gitlab+jenkins自动化部署

    技术2022-07-10  144

    环境:centos 7 两台 192.168.100.128 安装gitlab 192.168.100.129 安装jenkins 关闭防火墙 Git包版本:gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

    gitlab+jenkins服务简述:

    GitLab是一个代码仓库,用来管理代码。Jenkins是一个自动化服务器,可以运行各种自动化构建、测试或部署任务。 所以这两者结合起来,就可以实现开发者提交代码到GitLab,Jenkins以一定频率自动运行测试、构建和部署的任务, 帮组开发团队更高效的集成和发布代码。

    部署安装Gitlab 1)安装gitlab

    #安装所需依赖 [root@localhost ~]# yum -y install epel-release curl openssh-server openssh-clients postfix cronie policycoreutils-python #安装gitlab软件包 [root@localhost ~]# rpm -ivh gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm #修改位本机的IP地址,便于访问 [root@localhost ~]# vim /etc/gitlab/gitlab.rb external_url 'http://192.168.100.128' #重新配置gitlab,就算不修改配置文件,也需要在安装后重新配置gitlab [root@localhost ~]# gitlab-ctl reconfigure #确定其80端口在监听 [root@localhost ~]# netstat -anpt | grep -w 80

    2)配置gitlab 3)生成密钥对,便于ssh登录

    [root@localhost ~]# ssh-keygen -t rsa -C "809024097@qq.com" #生成秘钥对 [root@localhost ~]# cat ~/.ssh/id_rsa.pub #查看公钥并复制 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDomj6jspC+pgAGHxRnAI/gEeEVYk3THpVU+wVyGRbiq/CeZTZLtCi9YEVvAgot8QK0lWgm/J7HiFFxwThbXNdmmJ8QfiFUsEE/bj+r0GNf63J+6ukR3ZkpEmTKa6V9sKaWQLNyjcJAcpyDnt9d8MjQ2484uCcP7Pd6oiOxp2IOqOK3R0ahxhMvMJ1qzj+MmNF7If2A6FiEkwVEX/vjqTov6RbQvAxsC0tv2dddCGHEZyZ88Ra5mvMDnCvR/M62LwrjMnhAVYQ+bxaQmnCV3UEbFfTL+DaJ+q2cmBxWakOFi8Ycgi8il8GLF3YvQrsfUzJ6pfg9eeCuCjUQwJxT2kOJ 809024097@qq.com

    接下来需在web页面进行操作。如图: 4)创建一个库 5)本地服务器进行测试

    #执行克隆操作,第一次根据提示输入yes即可! [root@localhost test01]# git clone git@192.168.100.128:root/test01.git #进入克隆的库,查看是否与web页面创建的库的内容一致 [root@localhost ~]# cd test01/ [root@localhost test01]# ls README.md #自报家门,进行简单的声明用户名及邮箱地址 [root@localhost test01]# git config --global user.name admin [root@localhost test01]# git config --global user.email admin@admin.com #创建文件进行测试 [root@localhost test01]# echo "hello world" > 123.txt [root@localhost test01]# git add 123.txt [root@localhost test01]# git commit -m "commit form local first" #将本地的测试文件推送到远端(gitlab) [root@localhost test01]# git push origin master

    6)gitlab验证 刷新页面之后,如图: gitlab的配置到此先告一段落,接下来安装Jenkins! 部署安装Jenkins 1)安装Jenkins和git

    #安装git [root@localhost ~]# yum -y install git #安装Jenkins软件包和Java包 [root@localhost ~]# rpm -ivh jdk-8u131-linux-x64_.rpm jenkins-2.222.1-1.1.noarch.rpm #启动jenkins [root@localhost ~]# systemctl start jenkins 查看jenkins的8080端口 [root@localhost ~]# ss -lnt | grep 8080 LISTEN 0 50 :::8080 :::*

    2)jenkins web页面配置 如图:

    #查看密码信息,并将其复制 [root@localhost ~]# cat /var/lib/jenkins/secrets/initialAdminPassword fea4b6ca898444a0a4ed5644a0cfba87

    Processed: 0.012, SQL: 9