shaoqin 发表于 2018-9-3 12:48:24

jenkins自动化发布python flask模拟流程

  一、前提步骤
  1、安装gitlab
  yum -y install policycoreutils openssh-server openssh-clients postfix
  wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-8.17.0-ce.0.el6.x86_64.rpm
  rpm -ivh gitlab-ce-8.17.0-ce.0.el6.x86_64.rpm
  vi/etc/gitlab/gitlab.rb
  修改为本机IPexternal_url 'http://10.120.52.22'
  gitlab-ctl reconfigure
  gitlab-ctl restart
  gitlab-ctlstatus 查询状态

  访问地址:http://10.120.52.22
  2、安装jenkins 持续集成
  wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.90/jenkins.war
  启动jenkins
  java -jarjenkins.war &
  访问地址:http://10.120.52.42:8080
  二、思路
  以Python flask web开发环境为背景, 通过git提交代码到gitlab后,再用jenkins远程到gitlab构建代码发布到测试服务器上
  三、gitlab配置
  1、登录gitlab上面,创建project:flask-demo
  2、在菜单栏上 SSH Keys 中,添加开发环境IP的ssh-key
  3、登录开发环境IP,克隆git地址
  # git clone git@10.120.52.22:UserCenter/flask-demo.git
  #cd flask-demo 创建测试文件web.py

  4、上传更新代码
  git status
  git add .
  git commit-m "new file web.py"
  git push originmaster
  四、jenkins 配置
  1、登录http://10.120.52.42:8080/ 控制台
  2、在系统管理-管理插件,安装SSH2 Easy Plugin 插件后重启
  3、创建project项目 flask demo ,添加gitlab地址,远程服务器IP等信息,如下截图



  4、系统管理-系统配置

  5、在project中构建代码,验证远程服务是否更新
  其他
  1、忘记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!
  2、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的时间点必须与原服务器备份后的文件名一致

页: [1]
查看完整版本: jenkins自动化发布python flask模拟流程