centos下搭建
1. 關閉Selinux
vim /etc/selinux/config
SELINUX=enforcing //把enforcing改為disabled
重啟計算機生效配置
reboot
2. 添加鏡像地址(使用國內(nèi)源)
vim /etc/yum.repos.d/gitlab-ce.repo
粘貼如下內(nèi)容:
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
3. 安裝依賴
安裝和配置openssh
yum -y install curl policycoreutils-python openssh-server openssh-clients
4. 下載gitlab-ce,版本:10.8.7
查看gitlab都有哪些版本:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
下載版本:
curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm
5. 安裝gitlab-ce
rpm -i gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm
安裝完刪除安裝包:
rm -f gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm
6. 關閉防火墻
systemctl stop firewalld
systemctl disable firewalld
7. gitlab配置
vim /etc/gitlab/gitlab.rb
修改external_url
external_url 'http://47.75.147.153:8080
8. 對gitlab執(zhí)行配置迅腔,時間比較長
gitlab-ctl reconfigure
9. 啟動gitlab
gitlab-ctl start
10. 打開瀏覽器訪問gitlab
http://47.75.147.153
Ubuntu下搭建
1. 安裝配置依賴項
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates
2. 安裝發(fā)送郵件
sudo apt-get install -y postfix
3. 下載安裝腳本
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
4. 修改安裝腳本
sudo vim /etc/apt/sources.list.d/gitlab_gitlab-ce.list
把原來的兩行刪除或者注釋(#是行注釋),然后增加
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
deb-src https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
5. 再次執(zhí)行
sudo apt-get update
6. 執(zhí)行安裝腳本
sudo apt-get install gitlab-ce=12.10.11-ce.0
7. gitlab配置
sudo vim /etc/gitlab/gitlab.rb
修改external_url
external_url 'http://47.75.147.153:8080'
8. 開啟端口號防火墻
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
9. 對gitlab執(zhí)行配置靠娱,時間比較長
sudo gitlab-ctl reconfigure
10. 啟動gitlab
sudo gitlab-ctl start
11. 打開瀏覽器訪問gitlab
http://47.75.147.153
發(fā)送郵件配置(以阿里企業(yè)郵箱為例)
1. 設置postfix開機自啟沧烈,并啟動,postfix支持gitlab發(fā)信功能
systemctl enable postfix && systemctl start postfix
2. 編輯配置文件
sudo vim /etc/gitlab/gitlab.rb
配置郵箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qiye.aliyun.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "test@xxx.com" #發(fā)送方郵箱賬號
gitlab_rails['smtp_password'] = "xxxxxxx #發(fā)送方郵箱密碼
gitlab_rails['smtp_domain'] = "smtp.mxhichina.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'test@xxx.com'
user['git_user_email'] = "test@xxx.com"
user['git_user_name'] = "GitLab系統(tǒng)郵件"
3. 執(zhí)行重新配置命令
gitlab-ctl reconfigure
4. 重啟服務
gitlab-ctl restart
5. 測試發(fā)送郵件能否成功
進入gitlab控制臺:
gitlab-rails console
執(zhí)行這條命令給自己發(fā)送郵件:
Notify.test_email('user@xxx.com', 'Test123Title', 'Test123Body').deliver_now
定時備份
1. GITLAB備份參數(shù)設置
vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path']=true
gitlab_rails['backup_path']="/var/opt/gitlab/backups" #gitlab備份目錄
gitlab_rails['backup_archive_permissions']=0644 #生成的備份文件權限
gitlab_rails['backup_keep_time'] = 7776000 #備份保留天數(shù)像云,秒計算锌雀,這里是90天
2. 設置備份目錄權限
chmod -R 777 /var/opt/gitlab/backups
3. 執(zhí)行重新配置命令
gitlab-ctl reconfigure
4. 創(chuàng)建定時任務
crontab -e
輸入:每天晚上1點開始備份
0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
查看定時任務:
crontab -l
5. 重啟cron
centos:
sudo systemctl restart crond
ubuntu:
sudo service cron restart
數(shù)據(jù)恢復
1. 將備份的文件拷貝至:/var/opt/gitlab/backups
2. 執(zhí)行命令停止相關數(shù)據(jù)連接服務
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
3. 執(zhí)行恢復命令
gitlab-rake gitlab:backup:restore BACKUP=1565599695_2019_08_12_10.8.7
指令執(zhí)行過程中有兩次交互,都輸入yes即可迅诬。
4. 最后重啟gitlab
gitlab-ctl restart