Jenkins 、gitlab、实现CICD持续集成

Gitlab 安装
1 安装环境依赖

[root@yt6fnjphmaqeyeza ~]# yum install -y curl policycoreutils-python openssh-server postfix wget
Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                                                                                                                                                                                       | 3.6 kB  00:00:00
docker-ce-stable                                                                                                                                                                                                                           | 3.5 kB  00:00:00
epel                                                                                                                                                                                                                                       | 4.7 kB  00:00:00
extras                                                                                                                                                                                                                                     | 2.9 kB  00:00:00
kubernetes                                                                                                                                                                                                                                 | 1.4 kB  00:00:00
updates                                                                                                                                                                                                                                    | 2.9 kB  00:00:00
(1/3): docker-ce-stable/7/x86_64/primary_db                                                                                                                                                                                                | 118 kB  00:00:00
(2/3): epel/x86_64/updateinfo                                                                                                                                                                                                              | 1.0 MB  00:00:00
(3/3): epel/x86_64/primary_db                                                                                                                                                                                                              | 7.0 MB  00:00:00
Package curl-7.29.0-59.el7_9.1.x86_64 already installed and latest version
Package policycoreutils-python-2.5-34.el7.x86_64 already installed and latest version
Package 2:postfix-2.10.1-9.el7.x86_64 already installed and latest version
Package wget-1.14-18.el7_6.1.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:7.4p1-22.el7_9 will be updated
---> Package openssh-server.x86_64 0:7.4p1-23.el7_9 will be an update
--> Processing Dependency: openssh = 7.4p1-23.el7_9 for package: openssh-server-7.4p1-23.el7_9.x86_64
--> Running transaction check
---> Package openssh.x86_64 0:7.4p1-22.el7_9 will be updated
--> Processing Dependency: openssh = 7.4p1-22.el7_9 for package: openssh-clients-7.4p1-22.el7_9.x86_64
---> Package openssh.x86_64 0:7.4p1-23.el7_9 will be an update
--> Running transaction check
---> Package openssh-clients.x86_64 0:7.4p1-22.el7_9 will be updated
---> Package openssh-clients.x86_64 0:7.4p1-23.el7_9 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================================================================
 Package                                                            Arch                                                      Version                                                            Repository                                                  Size
==================================================================================================================================================================================================================================================================
Updating:
 openssh-server                                                     x86_64                                                    7.4p1-23.el7_9                                                     updates                                                    459 k
Updating for dependencies:
 openssh                                                            x86_64                                                    7.4p1-23.el7_9                                                     updates                                                    510 k
 openssh-clients                                                    x86_64                                                    7.4p1-23.el7_9                                                     updates                                                    655 k

Transaction Summary
==================================================================================================================================================================================================================================================================
Upgrade  1 Package (+2 Dependent packages)

Total download size: 1.6 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): openssh-7.4p1-23.el7_9.x86_64.rpm                                                                                                                                                                                                   | 510 kB  00:00:00
(2/3): openssh-clients-7.4p1-23.el7_9.x86_64.rpm                                                                                                                                                                                           | 655 kB  00:00:00
(3/3): openssh-server-7.4p1-23.el7_9.x86_64.rpm                                                                                                                                                                                            | 459 kB  00:00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                             3.1 MB/s | 1.6 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : openssh-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                                  1/6
  Updating   : openssh-clients-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                          2/6
  Updating   : openssh-server-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                           3/6
  Cleanup    : openssh-server-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                           4/6
  Cleanup    : openssh-clients-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                          5/6
  Cleanup    : openssh-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                                  6/6
  Verifying  : openssh-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                                  1/6
  Verifying  : openssh-clients-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                          2/6
  Verifying  : openssh-server-7.4p1-23.el7_9.x86_64                                                                                                                                                                                                           3/6
  Verifying  : openssh-server-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                           4/6
  Verifying  : openssh-clients-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                          5/6
  Verifying  : openssh-7.4p1-22.el7_9.x86_64                                                                                                                                                                                                                  6/6

Updated:
  openssh-server.x86_64 0:7.4p1-23.el7_9

Dependency Updated:
  openssh.x86_64 0:7.4p1-23.el7_9                                                                                             openssh-clients.x86_64 0:7.4p1-23.el7_9

Complete!

2 获取gitlab 包

[root@yt6fnjphmaqeyeza opt]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
--2023-11-28 11:22:05--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 427374190 (408M) [application/x-redhat-package-manager]
Saving to: ‘gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm’

100%[========================================================================================================================================================================================================================>] 427,374,190 32.8MB/s   in 11s

2023-11-28 11:22:16 (38.1 MB/s) - ‘gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm’ saved [427374190/427374190]

3、安装gitlab-通过本地的 rpm 包安装gitlab

#执行报错 fastestmirror不能使用,fastestmirror是yum的一个加速插件处理办法就是禁用这个插件 
解决如下:
[root@yt6fnjphmaqeyeza gitlab]# yum localinstall gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
Loaded plugins: fastestmirror
No such command: locainstall. Please use /usr/bin/yum --help
[root@yt6fnjphmaqeyeza gitlab]# vi /etc/yum/pluginconf.d/fastestmirror.conf
把enabled=1改为0
vi /etc/yum.conf
把plugins=1改为0

3.1 继续执行

[root@yt6fnjphmaqeyeza gitlab]# yum localinstall gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
Examining gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm: gitlab-ce-10.5.7-ce.0.el7.x86_64
Marking gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:10.5.7-ce.0.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================================================================
 Package                                                 Arch                                                 Version                                                       Repository                                                                       Size
==================================================================================================================================================================================================================================================================
Installing:
 gitlab-ce                                               x86_64                                               10.5.7-ce.0.el7                                               /gitlab-ce-10.5.7-ce.0.el7.x86_64                                               1.2 G

Transaction Summary
==================================================================================================================================================================================================================================================================
Install  1 Package

Total size: 1.2 G
Installed size: 1.2 G
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gitlab-ce-10.5.7-ce.0.el7.x86_64                                                                                                                                                                                                               1/1
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

  Verifying  : gitlab-ce-10.5.7-ce.0.el7.x86_64                                                                                                                                                                                                               1/1

Installed:
  gitlab-ce.x86_64 0:10.5.7-ce.0.el7
  
Complete!

4、修改gitlab 的配置

[root@yt6fnjphmaqeyeza ~]#  grep -Ev '^#' /etc/gitlab/gitlab.rb |grep -Ev '^$'
external_url 'http://203.34.153.182'
 gitlab_rails['gitlab_email_enabled'] = true
 gitlab_rails['gitlab_email_from'] = '1321529864@qq.com'
 gitlab_rails['gitlab_email_display_name'] = 'jiangshiguang'
 gitlab_rails['smtp_enable'] = true
 gitlab_rails['smtp_address'] = "smtp.qq.com"
 gitlab_rails['smtp_port'] = 587
 gitlab_rails['smtp_user_name'] = "1321529864@qq.com"
 gitlab_rails['smtp_password'] = "pprugrufscxwhbgj"
 gitlab_rails['smtp_domain'] = "smtp.qq.com"
 gitlab_rails['smtp_authentication'] = "login"
 gitlab_rails['smtp_enable_starttls_auto'] = true
 gitlab_rails['smtp_tls'] = true

5、测试gitlab命令行是否正确

5.1 需要先执行gitlab的配置重新读取
[root@yt6fnjphmaqeyeza ~]# gitlab-ctl reconfigure
5.2 测试gitlab命令行是否正确
[root@yt6fnjphmaqeyeza ~]# gitlab-rails console
5.3 #测试邮件发送
Notify.test_email('1321529864@qq.com','hello,'hell jiangshiguang').deliver_now

6、 gitlab 的相关命令

##改了gitlab 的配置文件需执行
[root@yt6fnjphmaqeyeza ~]# gitlab-ctl reconfigure
# 启动 | 暂停
gitlab-ctl start | restart | status |stop
#初始化后,gitlab 组件就全部启动了;netstat -tunlp
[root@yt6fnjphmaqeyeza ~]# gitlab-ctl status

7、gitlab 运行的组件如下:
GitLab 由主要由以下服务构成,他们共同承担了 Gitlab 的运作需要
Nginx:静态 web 服务器
gitlab-shell:用于处理 Git 命令和修改 authorized keys 列表
gitlab-workhorse:轻量级的反向代理服务器。
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekig:用于在后台执行队列任务(异步执行)
unicorn:An HTTP server for Rack applications,GitLab Rails 应用是托管在这个

8、首次访问gitlab
访问对应机器的IP地址即可
localhost:端口

9、首次运行gitlab,需要输入2次密码

10、首次访问gitlab完成

#相关组件访问命令
gitlab-ctl start
gitlab-ctI stop
gitlab-ctl stop postgresql
gitlab-ctl restart
gitlab-ctl status
gitlab-ctl reconfigure
gitlab-ctl tail
gitlab-ctl tail redis

gitlab 汉化配置

1.获取汉化代码包
汉化地址 https://gitlab.com/xhang/gitlab,可以进行下载

2.检查汉化包,一定要保证,汉化包的版本,和你gitlab的版本是一致
下载地址 https://gitlab.com/xhang/gitlab/-/tree/v10.2.2-zh
[root@gite1 gitlab learn]# ls
gitlab-ce-10.2.2-ce…e17.x86 64.rpm gitlab-v10.2.2-zh.zip

3.关闭gitlab服务
gitlab-ctl stop

4.解压缩汉化包,拷贝其中内容
[root@git01 gitlab learn]# \cp -rf gitlab-v10.2.2-zh/*
/opt/gitlab/embedded/service/gitlab-rails/
cp: cannot overwrite non-directory /opt/gitlab/embedded/service/gitlabrails/log’ with directory gitlab-v10.2.2-zh/log’cp: cannot overwrite non-directory “/opt/gitlab/embedded/service/gitlabrails/tmp’ with directory gitlab-v19.2.2-zh/tmp

5.再次启动
gitlab-ctl start
检查gitlab的运行日志,检测所有组件的日志,看运行结果
gitlab-ctl tail

gitlab ssh-key 配置

在Linux 机器上 生成密钥对

[root@git01 gitlab learn]# ssh-key  ras

jenkins 安装

1、准备安装所需要的软件环境依赖包:
jdk、jenkins 、Jenkins所需要的插件

下载 jdk、jenkins  所需要的rpm 包
#下载 jdk
[root@jobpsihhlxfisgm2 package]# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u181-linux-x64.rpm
--2023-11-28 16:54:32--  http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u181-linux-x64.rpm
#下载jenkins
[root@jobpsihhlxfisgm2 package]# wget https://pkg.jenkins.io/redhat-stable/jenkins-2.99-1.1.noarch.rpm --no-check-certificate

2、安装jdk

[root@jobpsihhlxfisgm2 package]# rpm -ivh jdk-8u181-linux-x64.rpm
warning: jdk-8u181-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk1.8-2000:1.8.0_181-fcs        ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...


验证 是否安装成功
[root@jobpsihhlxfisgm2 package]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

3.安装Jenkins

[root@jobpsihhlxfisgm2 package]# rpm -ivh jenkins-2.99-1.1.noarch.rpm
warning: jenkins-2.99-1.1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID d50582e6: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jenkins-2.99-1.1                 ################################# [100%]

   验证是否成功
[root@jobpsihhlxfisgm2 package]# java -jar /usr/lib/jenkins/jenkins.war --version
2.99

4、启动jenkins

# 启动 jenkins
[root@jobpsihhlxfisgm2 package]# systemctl start jenkins
# 查看jenkins 状态
[root@jobpsihhlxfisgm2 package]# systemctl status jenkins

5、检查jenkins端口 、防火墙

# 端口
[root@jobpsihhlxfisgm2 package]# netstat -tunlp | grep 8080
# SELinux的命令
[root@jobpsihhlxfisgm2 package]# getenforce
# 防火墙
[root@jobpsihhlxfisgm2 package]# iptables -L

6、检查jenkins 配置文件

[root@jobpsihhlxfisgm2 package]# rpm -ql jenkins
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins 
/usr/lib/jenkins        
/usr/lib/jenkins/jenkins.war
/usr/sbin/rcjenkins
/var/cache/jenkins
/var/lib/jenkins
/var/log/jenkins

jenkins加载插件很多,非常吃内存,且所有操作都是io操作,需要系统IO速度较快,需要机器配置较号
 /etc/sysconfig/jenkins  jenkins配置文件
/var/lib/jenkins  jenkins核心目录:
/usr/lib/jenkins/jenkins.war 存放jenkins WAR包
/etc/sysconfig/jenkins  配置文件
/var/lib/jenkins/  默认的JENKINS HOME目录
/var/log/jenkins/jenkins.log  Jenkins日志文件
/var/lib/jenkins/secrets/initialAdminPassword  存放初始密码
/var/lib/jenkins/plugins  插件目录

7、访问jenkins 初始页面

7.1 访问 jenkins 
ip:port/
报错------------------

7.2 获取admin 初始密码
[root@jobpsihhlxfisgm2 secrets]# cat /var/lib/jenkins/secrets/initialAdminPassword
92bd358fa97a4a2c9b34c3ce6b4770a0

7.3 等待出现安装插件的页面 直接关掉 后面选择导入插件的方式

8、修改密码
必须去修改密码 不然下次无法登录

9、Jenkins 安装插件

修改jenkins的插件下载源
在页面上导入jenkins插件
在服务器上,进行插件迁移

9.1修改jenkins的插件下载源/9.2在页面上导入jenkins插件
在这里插入图片描述

9.3 服务器上进行 jenkins 插件导入

找到提前下载的插件包解压然后移动到Jenkins对应的插件目录
[root@jobpsihhlxfisgm2 package]# tar -zxcf jenkins-plugins.tar.gz
[root@jobpsihhlxfisgm2 plugins]# mv ./* /var/lib/jenkins/plugins/
[root@jobpsihhlxfisgm2 plugins]# systemctl restart jenkins

jenkins 可以进行正常创建任务了…

jenkins 服务器还得和应用服务器进行免密登录

[root@jobpsihhlxfisgm2 plugins]# ssh-copy-id root@[主机ip] 

jenkins 主要配置文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值