1、前提步驟java
一、安裝gitlab git
yum -y install policycoreutils openssh-server openssh-clients postfixweb
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-8.17.0-ce.0.el6.x86_64.rpm flask
rpm -ivh gitlab-ce-8.17.0-ce.0.el6.x86_64.rpm服務器
vi /etc/gitlab/gitlab.rbssh
修改成本機IP external_url 'http://10.120.52.22' ide
gitlab-ctl reconfiguregitlab
gitlab-ctl restart post
gitlab-ctl status 查詢狀態 測試
訪問地址:http://10.120.52.22
二、安裝jenkins 持續集成
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.90/jenkins.war
啓動jenkins
java -jar jenkins.war &
2、思路
以Python flask web開發環境爲背景, 經過git提交代碼到gitlab後,再用jenkins遠程到gitlab構建代碼發佈到測試服務器上
3、gitlab配置
一、登陸gitlab上面,建立project:flask-demo
二、在菜單欄上 SSH Keys 中,添加開發環境IP的ssh-key
三、登陸開發環境IP,克隆git地址
# git clone git@10.120.52.22:UserCenter/flask-demo.git
# cd flask-demo 建立測試文件web.py
四、上傳更新代碼
git status
git add .
git commit -m "new file web.py"
git push origin master
4、jenkins 配置
一、登陸http://10.120.52.42:8080/ 控制檯
二、在系統管理-管理插件,安裝SSH2 Easy Plugin 插件後重啓
三、建立project項目 flask demo ,添加gitlab地址,遠程服務器IP等信息,以下截圖
四、系統管理-系統配置
五、在project中構建代碼,驗證遠程服務是否更新
其餘
一、忘記gitlab 帳號密碼處理方法:
gitlab-rails console production
Loading production environment (Rails 4.1.1)
irb(main):001:0> user = User.where(id:1).first
irb(main):002:0> user.password='66668888'
irb(main):003:0> user.save!
二、gitlab數據遷移
查看gitlab版本的命令:
gitlab-rake gitlab:env:info
2. 備份原a服務器上的的數據
gitlab-rake gitlab:backup:create RAILS_ENV=production
PS: 備份後的文件通常是位於/var/opt/gitlab/backups下, 自動生成文件名文件名如1481529483_gitlab_backup.tar
3. 將步驟2生成的tar文件拷貝到b服務器上相應的backups目錄下
能夠利用scp進行直接拷貝.
scp username@src_ip:/var/opt/gitlab/backups/1481529483_gitlab_backup.tar /var/opt/gitlab/backups
PS: username爲原服務器的用戶名,src_ip原服務器IP地址
4. 在b服務器恢復數據
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1481529483
PS:BACKUP的時間點必須與原服務器備份後的文件名一致