厚积薄发 发表于 2020-3-30 22:47:05

Gitlab+jenkins持续集成+自动化部署(一)

本帖最后由 厚积薄发 于 2020-3-30 22:49 编辑

Gitlab介绍
  GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
  GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
环境准备
Centos7.4--------x2
Gitlab:192.168.1.121 内存不能小于2G
jenkins:192.168.1.215
关闭selinux并确定是出于关闭状态sed -i ‘s/SELINUX=enforcing/SELINUX=disabled’ /etc/selinux/config`或者是临时关闭selinuxsetenforce 0更新软件包+重启服务器
yum -y update && reboot
关闭防火墙
systemctl stop firewalld
一.安装gitlab Ip地址:192.168.1.121
安装依赖包
yum install curl policycoreutils openssh-server openssh-clients postfix -y
启动postfixsystemctl start postfixcurl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh |bash# cat /etc/yum.repos.d/gitlab-ce.reponame=gitlab-cebaseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7repo_gpgcheck=0gpgcheck=0enabled=1gpgkey=https://packages.gitlab.com/gpg.key# yum makecache# yum install -y gitlab-ce在安装一个git客户端
yum -y install git
配置并启动gitlab-ce
# gitlab-ctl reconfigure
##时间可能比较长,请你耐心等待即可!~~~
##关闭:gitlab-ctl stop
##启动:gitlab-ctl start
##重启:gitlab-ctl restart
可以使用gitlab-ctl管理查看gitlab 例如查看gitlab状态:
https://s4.51cto.com/images/blog/201807/11/ca127ac97744f4e1afc18a32cec7ef46.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
确保80端口没有被占用,被占用的话,建议修改gitlab端口或者使用docker容器搭建gitlab
访问192.168.1.121 会提示让设置一个密码,设置的密码自己记住就可以.至少8位数
https://s4.51cto.com/images/blog/201807/11/3302b263203385d9db11491e0a832661.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
进入登陆界面 输入用户名及密码 用户root 密码为刚才设置的密码
https://s4.51cto.com/images/blog/201807/11/d6591475d178095e9aa99a8ed42234a6.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
创建一个组
https://s4.51cto.com/images/blog/201807/11/6a3e547671c6bda2db7c0277ec402a66.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://s4.51cto.com/images/blog/201807/11/35f371bcbef579eef8eaec85553abe68.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
创建一个项目
https://s4.51cto.com/images/blog/201807/11/5e79f0defbe3cab0c106be30185ca662.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://s4.51cto.com/images/blog/201807/11/acc841fd5378f0f622c4abc2972938d0.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://s4.51cto.com/images/blog/201807/11/4aa81fe92141b3a929384cda1d884604.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
在创建好的项目里面,点击README顺便输入点文字
https://s4.51cto.com/images/blog/201807/11/d337801a57d4a5a4404f1c4ef8750c0b.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
为了保证安全取消用户能够自己注册 (在下面找到seve保存)
https://s4.51cto.com/images/blog/201807/11/f01e1708c37af7655b09ec52eb0ab124.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
现在登陆就能发现没有注册了
0创建ssh免秘钥登陆 模拟使用gitlab这台服务器当做客户端
ssh-keygen -t rsa -C “你的邮箱”回三次车,密码为空
https://s4.51cto.com/images/blog/201807/11/23eb8512f5a98a8fe937387a2e7faf21.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTwULTk7SphWY4QPoAh1rkCcLPqNHWGrHSb9xmxpI5KkjYsxlNzxQL1OCB89rDAfF3hbOBVlSqX4Bw5PpLKxupEh7JW1uOfQY652ygqI7OF6nf6L3JZ354uYa1uqd4u5y1sag+U9gXCLndq2NLAY0EFTlWy8jeU5unNWcq/WYjf17u4CdwHpV4UnDAFNUYPzzZ2TdSto7g7Nt3IerQ7qesS0jlOT28yx0ihPLpYuM1Xc5uu7+FfHSvk0VrpWXDRQPcIqijpXJvch6N1kMpc4Vo/8aDaL2ATy7bjfvqZqEaO+n7f7r3WgnKh9ilGwi0cB4F7wY/jbYrmf/wGkXRsU6B *****@163.com把公钥粘贴到gitlab用户当中
https://s4.51cto.com/images/blog/201807/11/db4ca9c6ebb76759a2f2c9024fb65082.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://s4.51cto.com/images/blog/201807/11/c60a0ba7a282034354442ac8aecb776e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
修改gitlab的拉取地址
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
https://s4.51cto.com/images/blog/201807/11/0b0077c8b4d75adeb9c83758c63a5345.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://s4.51cto.com/images/blog/201807/11/9a952ef073dd23b119eda22e250be7bf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
重启gitlab-ce
# gitlab-ctl restart
https://s4.51cto.com/images/blog/201807/11/9c3c996cfcf71f80cb47ad2f9ba0d7a1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
拉取gitlab test项目
https://s4.51cto.com/images/blog/201807/11/f58c4f375b89ebf23573f50c0b2617bc.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=# mkdir /test# cd /test# git clone git@192.168.1.121:root/test.gitCloning into 'test'...The authenticity of host '192.168.1.121 (192.168.1.121)' can't be established.ECDSA key fingerprint is SHA256:3+2ICEmVWmSRY5m13Ds9w8uQ/unCGZM0l/AZR52LbQc.ECDSA key fingerprint is MD5:9c:94:0e:45:ff:57:42:67:a7:94:aa:33:86:30:99:d1.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.1.121' (ECDSA) to the list of known hosts.remote: Counting objects: 3, done.remote: Total 3 (delta 0), reused 0 (delta 0)Receiving objects: 100% (3/3), done.创建一个index.html用来模拟开发写代码并提交# pwd/test/test# cat index.html <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body><h1>测试</h1> </body></html># git add *    ##提交所有更改信息(删除 增加文件)# git config --global user.email "******@163.com"   ##身份验证# git config --global user.name "root"             ##身份验证# git commit -m "add index.html"         ## add index.html 1 file changed, 10 insertions(+) create mode 100644 index.html# git push origin masterCounting objects: 4, done.Delta compression using up to 4 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 382 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To git@192.168.1.121:root/test.git   5b44e15..1cdcea5master -> masterhttps://blog.51cto.com/12832314/2140284验证查看gitlab上是否有提交的index.html
https://s4.51cto.com/images/blog/201807/11/f1ee2e136390f6cdd150658ab53ae545.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
页: [1]
查看完整版本: Gitlab+jenkins持续集成+自动化部署(一)