在CentOS7上面搭建GitLab服务器
准备工作
1 设置固定ip地址
这一步尽量让客户那边的IT人员配置
注意:如果已经设置则略过这一步
步骤1:Vmware 14设置
点击下图所示额位置
Gateway(网关)—对应自己的电脑
下图所示的位置 就是上面需要的 Gateway(网关)
步骤2:命令行设置
[[email protected]~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls
[[email protected] network-scripts]# vi ifcfg-ens33
vi /etc/sysconfig/network-scripts/ifcfg-ens33
ESC
:wq #保存退出
步骤3:重启Linux的网络服务
然后重启Linux的网络服务,使修改生效
service network restart
2固定主机名
注意:如果已经设置则略过,如果通过其他方式修改的主机名也可以略过这一步
查看当前 IP地址:ifconfig
[[email protected] ~]# vim /etc/hosts
ESC
:wq #保存退出
3 开发防火墙端口
步骤1:重新加载防火墙
[[email protected] ~]# firewall-cmd –reload
步骤2:开放防火墙端口
(根据实际需要)
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=9706/tcp --permanent
[[email protected] ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[[email protected] ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
[[email protected] ~]# firewall-cmd --zone=public --add-port=22/tcp --permanent
[[email protected] ~]# firewall-cmd --zone=public --add-port=9706/tcp --permanent
步骤3:重启防火墙
[[email protected] ~]# firewall-cmd --reload
步骤4:查看已开放的端口
[[email protected] ~]# firewall-cmd --list-ports
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
一、 安装并配置必要的依赖关系
在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问。
1.安装ssh
sudo yum install -y curl policycoreutils-pythonopenssh-server
若出现以下图片的信息则表示成功
2.将SSH服务设置成开机自启动
安装命令:sudo systemctl enable sshd
3.启动SSH服务
安装命令:sudo systemctl start sshd
4。安装防火墙
(如果已经安装了防火墙并且已经在运行状态,则可直接进行第6步)
yum install firewalld systemd -y
若出现“完毕!”的字样,则表示安装成功
5.开启防火墙
安装命令:service firewalld start
6.添加http服务到firewalld
pemmanent表示永久生效,若不加--permanent系统下次启动后就会失效。
sudo firewall-cmd --permanent --add-service=http
7.重启防火墙
安装命令:sudo systemctl reload firewalld
8.安装Postfix以发送通知邮件
安装命令:sudo yum install postfix
9.将postfix服务设置成开机自启动
安装命令:sudo systemctl enable postfix
10.启动postfix
安装命令:sudo systemctl start postfix
在安装Postfix期间,可能会出现配置屏幕。选择“Internet Site”并按enter键。使用您的服务器的外部DNS以“mail name”并按enter。如果出现额外的屏幕,继续按enter键接受默认值。
11.wget 用于从外网上下载插件
检查系统中是否已经安装wget,使用命令若出现下图wget相关版本描述则说明系统中已经安装wget 若报系统找不到命令说明wget未安装
若wget未安装则进行安装,安装命令:yum -y install wget
12.安装vim编辑器
安装命令:yum install vim -y
二、添加GitLab镜像源并安装gitlab服务器
1.添加gitlab镜像
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
2.安装gitlab
安装gitlab 安装命令:rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
安装过程需要些时间,如果出现下图,则说明安装成功。
3.修改gitlab配置文件
指定服务器ip和自定义端口:
vim /etc/gitlab/gitlab.rb
注意:防火墙要开放相应的端口
进入编辑器后按“i”键进入编辑状态,ESC键退出编辑状态
退出并保存,命令输入“:wq”
ps:注意这里设置的端口不能被占用,默认是8080端口,如果8080已经使用,请自定义其它端口,并在防火墙设置开放相对应得端口
4.重置并启动GitLab
执行:
gitlab-ctl reconfigure
gitlab-ctl restart
提示 "ok: run:"表示启动成功
5.访问 GitLab页面
如果没有域名,直接输入服务器ip和指定端口进行访问
初始账户: root 密码:5iveL!fe
第一次登录修改密码
安装过程遇见的那些坑
一、在CentOS里面安装软件,提示软件已安装,但是rpm -q和-e都是提示包没有安装
查看与rpm包相关的文件和其他信息 rpm -qa | grep 包名
查询包是否被安装,命令:rpm -q 包名
删除软件包,命令:rpm -e 包名
三 GitLab 项目创建后地址由Localhost改为实际IP
进入终端修改以下文件即可。
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: localhost >> 这里改为主机的IP即可
port: 80
https: false
# Uncommment this line below if your ssh host is different from HTTP/HTTPS one
# (you'd obviously need to replace ssh.host_example.com with your own host).
# Otherwise, ssh host will be set to the `host:` value above
重启GitLab
gitlab-ctl restart
OK!!
出现的问题
问题1:yum lock
yum提示Another app is currently holding the yum lock; waiting for it to exit
使用yum安装计划任务功能,结果提示:
# yum -y install vixie-cron
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 25960.
Another app is currently holding the yum lock; waiting for it to exit...
可能是系统自动升级正在运行,yum在锁定状态中。
已经有一个yum进程在运行了,使用kill干掉它:
# kill -s 9 25960
# ps aux|grep yum
root 6744 0.0 0.0 103260 900 pts/1 S+ 14:59 0:00 grep yum
root 25960 0.0 0.0 0 0 ? Z Sep19 0:01 [yumBackend.py] <defunct>
很遗憾,kill对付不了它,那怎么办呢?
可以通过强制关掉yum进程:
#rm -f /var/run/yum.pid
然后就可以使用yum了。