参考文章:https://blog.youkuaiyun.com/luomuhe/article/details/72832873
1. 系统环境:阿里云centos:内存2G
a) 版本号:CentOS Linux release 7.4.1708 (Core)
b) 链接工具:Xshell6
2. 运行Xshell创建会话,使用用户名密码登陆
3. 执行一系列命名:
a) yum install curl policycoreutils openssh-server openssh-clients 安装SSH
b) service sshd restart 启动SSH
c) yum install postfix 安装postfix 邮件模块
d) service postfix restart 启动postfix
如果启动报错:Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.t
解决:注释、/etc/hosts文件这一行
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
4. 新建文件:touch /etc/yum.repos.d/gitlab-ce.repo
复制一下内容:vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
上面的操作是使用镜像提高下载安装的速度
5. 执行:yum makecache
6. 执行:yum install gitlab-ce
7. 至此,gitlab 安装完毕!但不要急着去启动,我们现更改一些配置
a) 修改配置文件/etc/gitlab/gitlab.rb中的下面两项
external_url ‘http://你的外网IP:port'
unicorn[‘port’]=9090
b) gitlab-ctl reconfigure 更改配置文件后,重新加载使改动配置生效,并启动gitlab
c) 修改nginx监听端口:
sudo vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
如果报错:创建、/etc/chef/client.rb文件,查看本机名hostname -f
chef_server_url "..."
client_fork true
log_location "/var/log/chef/client.log"
validation_client_name "...-validator"
verify_api_cert true # you might not want this one unless you have a valid cert
node_name "my_node_name" # Add this line
一些常用命令:
需要关闭防火墙:开启80端口
[root@iZbp14cvwowqu27clxb6pxZ ~]# gitlab-ctl status
[root@iZbp14cvwowqu27clxb6pxZ ~]# gitlab-ctl tail --查看所有日志
[root@iZbp14cvwowqu27clxb6pxZ ~]# gitlab-ctl tail nginx/gitlab_access.log --查看nginx访问日志
[root@iZbp14cvwowqu27clxb6pxZ ~]# gitlab-ctl tail unicorn --跟踪unicorn的状态
一些目录结构:
主配置文件:/etc/gitlab/gitlab.rb // 可以自定义一些邮件服务等
日志地址:/var/log/gitlab/ // 对应各服务的打印日志
服务地址:/var/opt/gitlab/ // 对应各服务的主目录
仓库地址:/var/opt/gitlab/git-data // 记录项目仓库等提交信息
重置配置:gitlab-ctl reconfigure // 不要乱用,会重置为最原始的配置的
重启服务:gitlab-ctl stop/start/restart/uninstall // 停止、启动、重启、卸载
默认安装:postgres、nginx、redis、unicorn …
netstat -ntlp 查看所有端口
curl localhost 可以测试
# 查看已经开启的端口
firewall-cmd --list-ports
2 添加80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和访问类型) --permanent(永久生效)
3.重启防火墙
firewall-cmd --reload
4.停止防火墙
systemctl stop firewalld.service
5.禁止防火墙开机启动
systemctl disable firewalld.service
6.删除
firewall-cmd --zone=public --remove-port=80/tcp
主要的坑:
1. 配置文件:unicorn端口设置(建议unicorn端口不要使用8080,可能会被占用,gatlib的端口也不要使用80,修改自定义的端口,同时修改nginx监听 端口)
2. 内存要求2G,小于1G的要使用分区(最好是4G,否则卡,经常500)
3. 开启防火墙(开放自己的端口)
4. 添加node_name (创建/etc/chef/client.rb文件)
5. 记得登陆阿里云开启安全组,开放端口(如果localhost可以访问但是外网无法访问时,记得添加安全组)
查看日志:gitlab-ctl tail
添加邮件系统:
可以选择163 或者qq,或者阿里云邮箱 中转,但是在配置过程中发现25端口无法发送,所以使用qq邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxx@qq.com"
gitlab_rails['smtp_password'] = "xxx" 不是登陆密码,而是开启smtp的授权密码
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true 要开启
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "xxx@qq.com" 建议邮箱地址同意
user["git_user_email"] = "xxx@qq.com"
测试是否成功:
进入控制台 : gitlab-rails console
发送测试邮件:Notify.test_email('xxxxx@qq.com', 'Message Subject test', 'Message Body test').deliver_now
gitlab迁移:
1. 旧服务器备份:
gitlab-rake gitlab:backup:create (备份文件位于:/var/opt/gitlab/backups)
2. 查看gitlab版本:
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
3. 下载相同版本的gitlab安装包:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
4. 拷贝备份文件和安装包到新服务器:
scp /var/opt/gitlab/backups/1561597102_2019_06_27_12.0.1_gitlab_backup.tar root@xxx.xxx.xxx.xxx:/var/opt/gitlab/backups/
5. 新服务器升级:
yum -y update
安装依赖:yum install policycoreutils-python ;
安装邮件服务:
安装:sudo yum install postfix
设置 开机启动:sudo systemctl enable postfix
启动:sudo systemctl start postfix
6. 新服务器安装gitlab:
rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
7. 新服务器配置访问IP和端口:
vi /etc/gitlab/gitlab.rb
修改:external_url 'http://外网IP:端口' (防火墙和安全组都要开)
生成配置:gitlab-ctl reconfigure
重启:gitlab-ctl restart
8. 新服务器从备份文件恢复数据:
修改备份文件权限: chmod 777 1561597102_2019_06_27_12.0.1_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
注意:备份文件编号为1561597102_2019_06_27_12.0.1 即不包含‘_gitlab_backup.tar’后缀