Jenkins+Gitlab持续集成(第一部分)

一、环境

环境
在这里插入图片描述

二、步骤

第一部分
3.1 安装Gitlab程序:
3.2 配置并启动Gitlab程序:
3.3 通过web页面配置Gitlab程序:
3.4 通过web页面创建Gitlab项目:
3.5 通过git命令测试下载Gitlab中的项目代码及测试上传项目代码:
3.6 访问Gitlab的web页面验证上传的项目代码:
3.7 安装部署jdk环境:
3.8 安装部署apache-maven框架:
第二部分
3.9 安装部署jenkins程序(四种方式,在此使用第三种基于tomcat安装):
3.10 配置jenkins的web页面进行安装:
3.11 设置jenkins的环境变量与允许用户注册:
3.12 设置jenkins中的jdk的位置和maven的位置:
第三部分
3.13 创建Jenkins任务:
3.14 构建任务完成后,构建触发任务,查看Jenkins是够能够成功连接到Gitlab:
3.15 模拟测试发布网站代码文件到gitlab,然后构建到Jenkins:
3.16 安装测试服务器上的httpd服务并且在jinkens主机上配置秘钥对,实现能远程到httpd服务:
3.17 配置jenkins程序构建任务推送网页文件到httpd服务器上:
3.18 验证httpd服务器的文件推送情况,客户端访问测试:
3.19 注解:构建触发器的计划任务编写语法:
3.20 在开发人员主机上模拟修改代码,然后通过git提交到gitlab,测试jenkins自动构建任务:

三、操作(第一部分)

3.1 安装gatlab程序

> [root@jenkins ~]# yum -y install ntpdate [root@jenkins ~]# ntpdate
> ntp1.aliyun.com 26 Sep 17:00:53 ntpdate[30172]: adjust time server
> 120.25.115.20 offset -0.000031 sec [root@jenkins ~]# echo "/usr/sbin/ntpdate ntp1.aliyun.com" >>/etc/rc.local  [root@jenkins ~]#
> chmod +x /etc/rc.local [root@jenkins ~]# wget
> https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh
> [root@jenkins ~]# chmod +x script.rpm.sh  [root@jenkins ~]#
> ./script.rpm.sh The repository is setup! You can now install packages.
> [root@jenkins ~]# yum install -y gitlab-ce 离线安装: hostnamectl
> set-hostname jenkins.linuxfan.cn tar xf gitlab-rpm.tar.gz -C /opt 
> #上传软件包 ls /opt/gitlab-rpm/ cd /opt/gitlab-rpm/ rm -rf Changelog.rpm  createrepo -g /mnt/repodata/repomd.xml ./ cat <<END
>/etc/yum.repos.d/ctos7.repo  [gitlab] name=gitlab baseurl=file:///opt/gitlab-rpm/ enabled=1 gpgcheck=0 END yum -y install gitlab-ce cd

3.2 配置并启动gitlab程序

 [root@jenkins ~]# vi /etc/gitlab/gitlab.rb   13 external_url
> 'http://192.168.100.101' :wq [root@jenkins ~]# gitlab-ctl
> reconfigure				##加载配置文件,每次修改后都需要 Running handlers: Running handlers
> complete Chef Client finished, 435/620 resources updated in 02 minutes
> 29 seconds gitlab Reconfigured! [root@jenkins ~]# gitlab-ctl start ok:
> run: alertmanager: (pid 13861) 17s ok: run: gitaly: (pid 13787) 19s
> ok: run: gitlab-monitor: (pid 13807) 19s ok: run: gitlab-workhorse:
> (pid 13770) 20s ok: run: logrotate: (pid 13360) 99s ok: run: nginx:
> (pid 13345) 105s ok: run: node-exporter: (pid 13457) 82s ok: run:
> postgres-exporter: (pid 13885) 16s ok: run: postgresql: (pid 13055)
> 146s ok: run: prometheus: (pid 13842) 17s ok: run: redis: (pid 12980)
> 152s ok: run: redis-exporter: (pid 13618) 65s ok: run: sidekiq: (pid
> 13307) 114s ok: run: unicorn: (pid 13263) 120s [root@jenkins ~]#
> netstat -utpln 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:9100         
> 0.0.0.0:*               LISTEN      2628/node_exporter   tcp        0      0 127.0.0.1:9229          0.0.0.0:*               LISTEN     
> 3056/gitlab-workhor  tcp        0      0 127.0.0.1:9168         
> 0.0.0.0:*               LISTEN      3102/ruby            tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN     
> 2481/unicorn master  tcp        0      0 0.0.0.0:80             
> 0.0.0.0:*               LISTEN      2536/nginx: master   tcp        0      0 127.0.0.1:8082          0.0.0.0:*               LISTEN     
> 2502/sidekiq 5.1.3   tcp        0      0 127.0.0.1:9236         
> 0.0.0.0:*               LISTEN      3072/gitaly          tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      813/sshd
> tcp        0      0 127.0.0.1:25            0.0.0.0:*              
> LISTEN      968/master           tcp        0      0 0.0.0.0:8060     
> 0.0.0.0:*               LISTEN      2536/nginx: master   tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN     
> 2739/redis_exporter  tcp        0      0 127.0.0.1:9090         
> 0.0.0.0:*               LISTEN      3117/prometheus      tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN     
> 3156/postgres_expor  tcp        0      0 127.0.0.1:9093         
> 0.0.0.0:*               LISTEN      3129/alertmanager    tcp        0      0 0.0.0.0:9094            0.0.0.0:*               LISTEN     
> 3129/alertmanager    udp        0      0 0.0.0.0:9094           
> 0.0.0.0:*                           3129/alertmanager [root@jenkins ~]# chmod -R 755 /var/log/gitlab [root@jenkins ~]# yum -y install git
> [root@jenkins ~]# git config --global user.name "linuxfan"
> [root@jenkins ~]# git config --global user.email admin@linuxfan.cn
> [root@jenkins ~]# mkdir /opt/linuxfan [root@jenkins ~]# cd
> /opt/linuxfan  [root@jenkins linuxfan]# git init 初始化空的 Git 版本库于
> /opt/linuxfan/.git/ [root@jenkins linuxfan]# ssh-keygen  -t rsa -C
> admin@linuxfan.cn  [root@jenkins linuxfan]# cat /root/.ssh/id_rsa.pub 
> ssh-rsa
> AAAAB3NzaC1yc2EAAAADAQABAAABAQDauS+Tnzq4FFole83uuSOt9iURbq0blLlSBp1dzXbS3re26o5idURw+SLFCc5BUp0Pd78I+Awtxtm1Nz58KAinATgmv5ImTN6yMSF99QTSR0ut/c8mIjm4cMHphGUIZgIplnCC5IwkbIcvQiHhkDzzn6YK/63Rp9hc3HyaGmMneDmxAhZglOeuno6i7i2hyNerKrDHlCaNPYx11u4KQ1J1wi9KGl1JL+FifTwQEtvWFgQE8HtkrslJsFwhzVrTi7Bv5d5U/GpnKn/7Fln0qPKNoWdl4MR/iD6zdZ8a5yDW+QK9ciiViKO0EzD3slWHxrq/evjPuTg6GRLtdKzVQAQL
> admin@linuxfan.cn

3.3 通过web页面配置Gitlab程序

在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述

3.4 通过web页面创建Gitlab项目

在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述在这里插入图片描述

3.5 通过git命令测试下载Gitlab中的项目代码及测试上传项目代码

[root@jenkins linuxfan]# git clone http://192.168.100.101/linuxfan/linuxfan.git
正克隆到 'linuxfan'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done. 
[root@jenkins linuxfan]# ls
linuxfan
[root@jenkins linuxfan]# ls linuxfan/
www.linuxfan.cn

[root@jenkins linuxfan]# rm -rf linuxfan/
或者[root@jenkins ~]# git clone git@192.168.100.101:linuxfan/linuxfan.git			##下载项目linuxfan
正克隆到 'linuxfan'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
[root@jenkins linuxfan]# cat linuxfan/www.linuxfan.cn 			##查看项目下载后的代码
www.linuxfan.cn

[root@jenkins linuxfan]# cd linuxfan/							##切换到项目目录中	
[root@jenkins linuxfan]# pwd
/opt/linuxfan/linuxfan
[root@jenkins linuxfan]# touch haha.txt						##创建测试代码文件
[root@jenkins linuxfan]# git add haha.txt
[root@jenkins linuxfan]# git commit -m "haha.txt"				##将测试代码文件提交到git版本库中
[master ee68b76] haha.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 haha.txt
[root@jenkins linuxfan]# git remote add origin git@192.168.100.101:linuxfan/linuxfan.git		##创建远程的gitlab版本库,名称为origin,在clone时会自动创建此版本库,可以使用git remote remove origin命令删除,在此指定的origin的方式必须与上述clone命令方式相同
[root@jenkins linuxfan]# git push								##将git版本库中的文件上传到gitlab 
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 268 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.100.101:linuxfan/linuxfan.git
   bc0010d..ee68b76  master -> master

3.6 访问Gitlab的web页面验证上传的项目代码

在这里插入图片描述在这里插入图片描述在这里插入图片描述

3.7 安装部署jdk环境

[root@jenkins ~]# tar zxvf jdk-8u171-linux-x64.tar.gz 
[root@jenkins ~]# mv jdk1.8.0_171 /usr/local/java/
[root@jenkins ~]# vi /etc/profile
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$MAVEN_HOME/bin:$JAVA_HOME/bin
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
:wq
[root@jenkins ~]# source /etc/profile
[root@jenkins ~]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

3.8 安装部署apache-maven框架

[root@jenkins ~]# wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
[root@jenkins ~]# tar zxvf apache-maven-3.5.4-bin.tar.gz
[root@jenkins ~]# mv apache-maven-3.5.4 /usr/local/maven
[root@jenkins ~]# ls /usr/local/maven
bin  boot  conf  lib  LICENSE  NOTICE  README.txt
[root@jenkins ~]# ln -s /usr/local/maven/bin/* /usr/bin/
[root@jenkins ~]# vi /etc/profile
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
:wq
[root@jenkins ~]# source /etc/profile
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值