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