CentOS7下的Django2集成部署三:Jenkins和GitLab安装

Jenkins

  • 安装 JDK和Jenkins
    [root@home-ct75211 ~]# cd /usr/local/src/
    [root@home-ct75211 src]# ll
    total 244436
    -rw-r--r--. 1 root root 176154027 Dec 14 08:46 jdk-8u191-linux-x64.rpm
    -rw-r--r--. 1 root root  74141787 Dec 14 08:40 jenkins-2.99-1.1.noarch.rpm
    [root@home-ct75211 src]# rpm -ivh jdk-8u191-linux-x64.rpm
    
    [root@home-ct75211 src]# java -version
    java version "1.8.0_191"
    Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
    [root@home-ct75211 src]# rpm -ivh jenkins-2.99-1.1.noarch.rpm
    
    
    [root@home-ct75211 src]# systemctl status jenkins
    ● jenkins.service - LSB: Jenkins Automation Server
       Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:systemd-sysv-generator(8)
    [root@home-ct75211 src]# systemctl start jenkins
    [root@home-ct75211 src]# systemctl enable jenkins
    jenkins.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig jenkins on
    [root@home-ct75211 src]# netstat -ntpl
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:21190          0.0.0.0:*               LISTEN      26831/uwsgi         
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26813/nginx: master 
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1081/sshd           
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1380/master         
    tcp6       0      0 :::3306                 :::*                    LISTEN      2425/mysqld         
    tcp6       0      0 :::8080                 :::*                    LISTEN      27284/java          
    tcp6       0      0 :::22                   :::*                    LISTEN      1081/sshd           
    tcp6       0      0 ::1:25                  :::*                    LISTEN      1380/master         
    
     netstat -ntpl
    netstat -ntpl

    jenkins 默认端口是8080,访问

    • 如果一直是这个页面,需要编辑一下Jenkins程序目录 /var/lib/jenkins/ 下的 hudson.model.UpdateCenter.xml 文件
      把
      http://updates.jenkins-ci.org/update-center.json
      改成
      http://mirror.xmission.com/jenkins/updates/update-center.json
      [root@home-ct75211 jenkins]# systemctl restart jenkins

      再次访问就可以了,按照提示输入默认密码就可以登录了

    • 先直接跳过(直接关闭提示页面)推荐插件安装的页面,进入系统先重置下密码
  •   创建一个item来测试下
  •   立即构建,然后查看下console output
    •   
  • 基本上Jenkins已经就绪了,之后会用gitlab的触发插件和pipeline的相关插件,请直接安装他们

GitLab

  • 准备工作
    • 上述环境,已经准备好了,就剩这个Gitlab了,做个快照先
    • 做快照的时间先做下ssh-keygen
      [root@home-ct75211 ~]# ssh-keygen -t rsa
      Generating public/private rsa key pair.
      Enter file in which to save the key (/root/.ssh/id_rsa): 
      Created directory '/root/.ssh'.
      Enter passphrase (empty for no passphrase): 
      Enter same passphrase again: 
      Your identification has been saved in /root/.ssh/id_rsa.
      Your public key has been saved in /root/.ssh/id_rsa.pub.
      The key fingerprint is:
      SHA256:RsLwx3rxsdKlpgoubJFHRKgdKcAD47Wvqlho0iX1wRI root@home-ct75211
      The key's randomart image is:
      +---[RSA 2048]----+
      |B  =E            |
      |o+= o* .         |
      | =.+o * = . .    |
      |. ..oo * + =     |
      |  .o..o S *      |
      | oooo  o +       |
      |ooo+.   .        |
      |+.=. . .         |
      |+o .. .          |
      +----[SHA256]-----+
      [root@home-ct75211 ~]# cat ~/.ssh/id_rsa.pub
      ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDd1qSaKrRPKIltcibTJNne+06ZVLXQKJfht6WAUPui7vhQVHKBbmW33hq2J9anKQSHwFZe12QM6tcl49MrLrOzn4z7rxa95jE/Zf5TE7ADwKqGn6kfv8+11ifzkKYwbV3iqYwxAWDKoPAaFiKkkAqadpevWgdoyi+z4GGKfn3Ph8dHJfLZNP1LO6ogC4eVvUUbsLQKnt5QnaGDbqHuqgVkLfmyGUiMBc2ZVnkqGgMiKPYibMQsLYHGIrN5fZUKBqA+S4RFKNJZxBvtMvzU1Sz3q11A8tudcJH8JBf1dHcEavO1hnDTaSP3ibVHzIblOKkA9j4ZbouKlAVjOOW6izSz root@home-ct75211
      ssh-keygen -t rsa

       

    • 把git也安装下 yum -y install git 
    • 安装依赖
      yum install -y curl policycoreutils-python openssh-server
      [root@home-ct75211 ~]# systemctl enable sshd
      [root@home-ct75211 ~]# systemctl start sshd
  • 安装和配置
    • 这里用的版本是 gitlab-ce-10.2.2 
      [root@home-ct75211 ~]# cd /usr/local/src/
      [root@home-ct75211 src]# rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
      It looks like GitLab has not been configured yet; skipping the upgrade script.
      
             *.                  *.
            ***                 ***
           *****               *****
          .******             *******
          ********            ********
         ,,,,,,,,,***********,,,,,,,,,
        ,,,,,,,,,,,*********,,,,,,,,,,,
        .,,,,,,,,,,,*******,,,,,,,,,,,,
            ,,,,,,,,,*****,,,,,,,,,.
               ,,,,,,,****,,,,,,
                  .,,,***,,,,
                      ,*,.
        
      
      
           _______ __  __          __
          / ____(_) /_/ /   ____ _/ /_
         / / __/ / __/ /   / __ \`/ __ \
        / /_/ / / /_/ /___/ /_/ / /_/ /
        \____/_/\__/_____/\__,_/_.___/
        
      
      Thank you for installing GitLab!
      GitLab was unable to detect a valid hostname for your instance.
      Please configure a URL for your GitLab instance by setting `external_url`
      configuration in /etc/gitlab/gitlab.rb file.
      Then, you can start your GitLab instance by running the following command:
        sudo gitlab-ctl reconfigure
      
      For a comprehensive list of configuration options please see the Omnibus GitLab readme
      https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
      安装成功后

       

    • 配置 /etc/gitlab/gitlab.rb ,主要是端口号(默认是80端口)和备份的设置

      •  external_url 'http://gitlab.example.com' 修改成 external_url 'http://192.168.23.211' 

      •   # nginx['listen_port'] = nil 去掉#,修改成  nginx['listen_port'] = 21180 ,80端口给了nginx,后面会用这个端口访问gitlab

      •  # unicorn['port'] = 8080  去掉#,修改成 unicorn['port'] = 21188 。这个端口已给了Jenkins,后面会用21188
      • 文件末尾追加

        gitlab_rails['backup_path'] = '/data/backup/gitlab'
        gitlab_rails['backup_keep_time'] = 604800

         /data/backup/gitlab 这个路径会自动创建

      •  gitlab-ctl reconfigure 重新配置下,一般会自动重启服务的

  • 启动
    • 访问 http://192.168.23.211:21180 ,并设置root账户的初始密码
    • 习惯上会关闭前台注册
    • 设置外观
    • 外观预览
    • 添加组和用户
    • 先从已有的项目来创建一个简单的repo
    • 添加本地ssh-key到gitlab
    • 克隆git到本地
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python
      $ git clone  git@192.168.23.211:py3web/ok-admin.git
      Cloning into 'ok-admin'...
      The authenticity of host '192.168.23.211 (192.168.23.211)' can't be established.
      ECDSA key fingerprint is SHA256:3DePdkqpeNDs052JoC+Qfo8/xAnPAbqP1jid8kQ9dx8.
      Are you sure you want to continue connecting (yes/no)? yes
      Warning: Permanently added '192.168.23.211' (ECDSA) to the list of known hosts.
      remote: Counting objects: 578, done.
      remote: Compressing objects: 100% (284/284), done.
      remote: Total 578 (delta 258), reused 578 (delta 258)
      Receiving objects: 100% (578/578), 2.13 MiB | 15.48 MiB/s, done.
      Resolving deltas: 100% (258/258), done.
      
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python
      $ cd ok-admin/
      
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python/ok-admin (master)
      $ vim index.html
      
      $ git add .
      
      $ git commit -m "modified index.html"
      
      *** Please tell me who you are.
      
      Run
      
        git config --global user.email "you@example.com"
        git config --global user.name "Your Name"
      
      to set your account's default identity.
      Omit --global to set the identity only in this repository.
      
      fatal: unable to auto-detect email address (got 'admin@DESKTOP-BC8FMN2.(none)')
      
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python/ok-admin (master)
      $ git config --global user.email "zhujingxiu1987@gmail.com"
      $ git config --global user.name "zhujingxiu"
      
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python/ok-admin (master)
      $ git commit -m "modified index.html"
      [master b731093] modified index.html
       1 file changed, 3 insertions(+), 3 deletions(-)
      
      admin@DESKTOP-BC8FMN2 MINGW64 /e/python/ok-admin (master)
      $ git push -u origin master
      Counting objects: 3, done.
      Delta compression using up to 6 threads.
      Compressing objects: 100% (3/3), done.
      Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done.
      Total 3 (delta 2), reused 0 (delta 0)
      To 192.168.23.211:py3web/ok-admin.git
         7516c75..b731093  master -> master
      Branch 'master' set up to track remote branch 'master' from 'origin'.

      这样gitlab也就绪了

posted @ 2018-12-16 10:47  zhujingxiu  阅读(525)  评论(0编辑  收藏  举报