安装依赖
先修改这个
gitlab搭建提示inet_interfacesJob for postfix.service failed because the control process exited with erro
修改 /etc/postfix/main.cf的设置
inet_protocols = ipv4
inet_interfaces = all
sudo yum install curl openssh-server openssh-clients postfix cronie
sudo service postfix start
sudo chkconfig postfix on或者执行systemctl enable postfix.service
#这句是用来做防火墙的,避免用户通过ssh方式和http来访问。
sudo lokkit -s http -s ssh
sudo yum makecache
sudo yum install gitlab-ce
sudo yum install gitlab-ce-x.x.x #安装指定版本
sudo gitlab-ctl reconfigure #Configure and start GitLab
GitLab配置文件修改
修改项目配置文件
vim /etc/gitlab/gitlab.rb
external_url 'http://域名或ip:端口'
修改gitlab自带nginx配置文件
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
listen *:端口;
server_name ip或者域名;
set $http_host_with_default "域名或ip:8888";
配置生效
#使配置生效
gitlab-ctl reconfigure
sudo gitlab-ctl reconfigure #可能需要这样
#重新启动GitLab
gitlab-ctl restart
默认密码
是root用户的密码
备份与恢复
- Gitlab的备份目录路径设置
[root@code-server ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups" //gitlab备份目录
gitlab_rails['backup_archive_permissions'] = 0644 //生成的备份文件权限
gitlab_rails['backup_keep_time'] = 7776000 //备份保留天数为3个月(即90天,这里是7776000秒)
[root@code-server ~]# mkdir -p /data/gitlab/backups
[root@code-server ~]# chown -R git.git /data/gitlab/backups
[root@code-server ~]# chmod -R 777 /data/gitlab/backups
如上设置了gitlab备份目录路径为/data/gitlab/backups,最后使用下面命令重载gitlab配置文件,是上述修改生效!
root@code-server ~]# gitlab-ctl reconfigure
- GItlab备份操作(使用备份命令"gitlab-rake gitlab:backup:create")
手动备份gitlab
[root@code-server backups]# gitlab-rake gitlab:backup:create
然后查看下备份文件(文件权限是设定好的644)
[root@code-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar
编写备份脚本,结合crontab实施自动定时备份,比如每天0点、6点、12点、18点各备份一次
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# vim gitlab_backup.sh
#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1
注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出
[root@code-server backups]# crontab -l
0 0,6,12,18 * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1
- Gitlab恢复操作
GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:
1)停止相关数据连接服务
[root@code-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@code-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@code-server backups]# gitlab-ctl status
2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups)
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar
Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[root@code-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
最后再次启动Gitlab
[root@code-server backups]# gitlab-ctl start
[root@code-server backups]# gitlab-ctl status
恢复命令完成后,可以check检查一下恢复情况
[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=true
然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!
另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致