0.Gitlab安装
1.安装和配置必要的依赖关系
在CentOS7,下面的命令将在系统防火墙打开HTTP和SSH访问。
yum install curl openssh-server postfix
systemctl enable sshd postfix
systemctl start sshd postfix
firewall-cmd --permanent --add-service=http
systemctl reload firewalld
https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
版本:Gitlab Community Edition
注意: gitlab-ce 镜像仅支持 x86-64 架构
Debian/Ubuntu 用户
首先信任 GitLab 的 GPG 公钥:
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
再选择你的 Debian/Ubuntu 版本,文本框中内容写进 /etc/apt/sources.list.d/gitlab-ce.list
deb http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian stretch main
安装 gitlab-ce:
sudo apt-get update
sudo apt-get install gitlab-ce
RHEL/CentOS 用户
新建 /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
再执行
sudo yum makecache
sudo yum install gitlab-ce -y
安装后后,修改
/etc/gitlab/gitlab.rb 文件中external_url为你的域名,然后执行配置
gitlab-ctl reconfigure
启动脚本
cat /etc/systemd/system/gitlab.service
[Unit] Description=gitlab [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/gitlab-ctl start ExecStop=/bin/gitlab-ctl stop [Install] WantedBy=multi-user.target |
cat /usr/lib/systemd/system/gitlab-runsvdir.service
[Unit] Description=GitLab Runit supervision process After=basic.target [Service] ExecStart=/opt/gitlab/embedded/bin/runsvdir-start Restart=always [Install] WantedBy=basic.target |
3.配置并启动
gitlab-ctl reconfigure
gitlab-ctl status
gitlab-ctl stop
gitlab-ctl start
4.浏览到主机名和登录Browse to the hostname and login
Username: root
Password: 5iveL!fe
5.更多操作系统的安装方式,点击下方链接即可
CentOS6
CentOS7
Ubuntu14
Ubuntu12
1.Gitlab备份
使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份:
gitlab-rake gitlab:backup:create
使用以上命令会在/var/opt/gitlab/backups
目录下创建一个名称类似为1481598919_gitlab_backup.tar
的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1481598919是备份创建的日期 /etc/gitlab/gitlab.rb
配置文件须备份 /var/opt/gitlab/nginx/conf
nginx配置文件 /etc/postfix/main.cfpostfix
邮件配置备份
1.1Gitlab备份目录
可以通过/etc/gitlab/gitlab.rb
配置文件来修改默认存放备份文件的目录
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
/var/opt/gitlab/backups
修改为你想存放备份的目录即可, 修改完成之后使用gitlab-ctl reconfigure
命令重载配置文件即可.
1.2Gitlab自动备份
实现每天凌晨2点进行一次自动备份:通过crontab使用备份命令实现
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
2.Gitlab恢复
Gitlab的从备份恢复也非常简单:
# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 从1481598919编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1481598919
# 启动Gitlab
sudo gitlab-ctl start
3.gitlab迁移
要求:新服务器的gitlab版本与旧的服务器相同。
迁移如同备份与恢复的步骤一样, 只需要将老服务器/var/opt/gitlab/backups
目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups
即可(如果你没修改过默认备份目录的话).
但是需要注意的是新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的7.60版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为7.60在进行备份.
/etc/gitlab/gitlab.rb
gitlab配置文件须迁移,迁移后需要调整数据存放目录 /var/opt/gitlab/nginx/conf
nginx配置文件目录须迁移
[root@linux-node1 ~]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@linux-node1 ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@linux-node1 ~]# chmod 777 /var/opt/gitlab/backups/1481598919_gitlab_backup.tar # 或 chown git:git /var/opt/gitlab/backups/1481598919_gitlab_backup.tar
[root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1481598919
4.gitlab升级
1.关闭gitlab服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx
2.备份gitlab
gitlab-rake gitlab:backup:create
3.下载gitlab的RPM包并进行升级
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum update gitlab-ce
或者直接安装高版本
yum install gitlab-ce-8.12.13-ce.0.el7.x86_64
或者上官网下载最新版本 gitlab对应软件包 [gitlab官网](https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-8.12.13-ce.0.el7.x86_64.rpm)
使用 rpm -Uvh gitlab-ce-8.12.13-ce.0.el7.x86_64
报错.
Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'
解决方法:
sudo chmod 2770 /var/opt/gitlab/git-data/repositories
4.启动并查看gitlab版本信息
gitlab-ctl reconfigure
gitlab-ctl restart
# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 8.7.3
5.gitlab更改默认Nginx
更换gitlab自带Nginx,使用自行编译Nginx来管理gitlab服务。
编辑gitlab配置文件禁用自带Nignx服务器
vi /etc/gitlab/gitlab.rb
...
#设置nginx为false,关闭自带Nginx
nginx['enable'] = false
...
检查默认nginx配置文件,并迁移至新Nginx服务
/var/opt/gitlab/nginx/conf/nginx.conf #nginx配置文件,包含gitlab-http.conf文件
/var/opt/gitlab/nginx/conf/gitlab-http.conf #gitlab核心nginx配置文件
重启 nginx、gitlab服务
$ sudo gitlab-ctl reconfigure
$ sudo service nginx restart
访问报502。原因是nginx用户无法访问gitlab用户的socket文件。 重启gitlab需要重新授权
chmod -R o+x /var/opt/gitlab/gitlab-rails