当前位置: 首页 > news >正文

devops完整搭建教程(gitlab、jenkins、harbor、docker)

devops完整搭建教程(gitlab、jenkins、harbor、docker)

文章目录

  • devops完整搭建教程(gitlab、jenkins、harbor、docker)
    • 1.简介:
    • 2.工作流程:
    • 3.优缺点
    • 4.环境说明
    • 5.部署前准备工作
      • 5.1.所有主机永久关闭防火墙和selinux
      • 5.2.配置yum源
      • 5.3.配置主机名与IP地址解析
    • 6.部署gitlab主机
      • 6.1.安装gitlab
      • 6.2.配置gitlab
      • 6.3.破解gitlab管理员密码
      • 6.4.查看gitlab的web页面
    • 7.部署jenkins主机
      • 7.1.部署tomcat
      • 7.2.安装jenkins
      • 7.3.访问jenkins的web页面
      • 7.4.安装git、maven、docker
      • 7.5.安装docker
      • 7.6.配置Jenkins主机可以从harbor主机拉取镜像,以及免密登录
    • 8.部署harbor.com主机
      • 8.1.安装harbor前需先安装docker及docker-compose
      • 8.2.安装harbor.com
          • 进入harbor官网,拉取harbor二进制包
          • 执行install.sh文件
          • 将harbor设置为开机自启
    • 9.部署docker主机
      • 9.1.安装docker服务
      • 9.2.制作一个基础的tomcat镜像,并上传到私有镜像仓库
    • 10.项目代码完整发布流程
      • 10.1.将代码上传到gitlab主机
      • 10.2.2.在Jenkins创建流水线项目,并运行项目
    • 11.最终测试(在docker主机上测试)
    • 11.错误排查报告

1.简介:

DevOps(Development Operations)是一种软件开发方法论和工作流程,旨在促进软件开发团队和运维团队之间的协作与沟通,以实现更高效的软件交付和运营。

2.工作流程:

  1. 持续集成(Continuous Integration,CI):开发团队将代码频繁地集成到共享存储库中,确保代码的一致性和稳定性。
  2. 持续交付(Continuous Delivery,CD):自动化构建、测试和部署流程,以快速将代码交付到生产环境。
  3. 自动化测试(Automated Testing):使用自动化测试工具和技术,确保软件的质量和稳定性。
  4. 自动化部署(Automated Deployment):自动化部署工具的使用,以快速、准确地部署软件到目标环境。
  5. 监控与日志(Monitoring and Logging):实时监测和记录系统的运行状态和日志,帮助快速发现和解决问题。

3.优缺点

优点:

  1. 加快交付速度:通过自动化流程和协作,加快软件的交付速度和发布周期。
  2. 提高质量和稳定性:自动化测试和部署流程能够提高软件的质量和稳定性。
  3. 促进协作与沟通:DevOps强调开发团队和运维团队之间的协作与沟通,改善工作效率和团队合作。
  4. 减少错误和故障:自动化流程和实时监控能够减少人为错误和系统故障的发生。

缺点:

  1. 学习成本高:实施和运营DevOps需要一定的学习和实践成本,对团队和组织提出了技术和文化上的要求。
  2. 依赖自动化工具:DevOps依赖于各种自动化工具和技术,需要投入一定的资源和成本进行选型、集成和维护。
  3. 组织变革需求:DevOps要求开发团队和运维团队之间的协作与沟通,可能需要进行组织结构和文化上的变革。

总体而言,DevOps通过将开发和运维整合在一起,以协作和自动化的方式,提高软件交付效率和质量,同时促进团队协作和沟通。

4.环境说明

主机名IP地址充当角色所需安装的软件系统版本
gitlab192.168.195.133本地代码仓库gitlab-cecentos8
jenkins192.168.195.134编译代码、打包镜像,项目发布jenkins、docker、git、mavencentos8
harbor.com192.168.195.135本地容器镜像仓库(存储镜像)harbor、docker-compose、dockercentos8
docker192.168.195.136制作镜像、上传镜像,测试环境(项目发布在此主机)dockercentos8

想要了解gitlab、jenkins、harbor的详细安装步骤,请阅读下列相关内容:
版本控制 gitlab 安装部署流程及其常用管理操作
tomcat部署jenkins
Harbor私有仓库

5.部署前准备工作

5.1.所有主机永久关闭防火墙和selinux

以gitlab主机演示:
//永久关闭防火墙
[root@gitlab ~]# systemctl disable --now firewalld.service
//永久关闭selinux
[root@gitlab ~]# setenforce 0
[root@gitlab ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

5.2.配置yum源

所有主机配置对应系统的yum源

以gitlab主机演示:
[root@gitlab ~]# rm -rf /etc/yum.repos.d/*
[root@gitlab ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@gitlab ~]# yum clean all
[root@gitlab ~]# yum makecache

5.3.配置主机名与IP地址解析

将所有主机的IP地址及其主机名写入到/etc/hosts文件中

以gitlab主机演示:
[root@gitlab ~]# vim /etc/hosts
[root@gitlab ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.195.133 tomcat 
192.168.195.134 jenkins
192.168.195.135 harbor.com
192.168.195.136 docker

6.部署gitlab主机

6.1.安装gitlab

//安装git
[root@gitlab ~]# yum -y install git//安装依赖包
[root@gitlab ~]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python perl
安装步骤略 . . .//上述安装依赖包成功则不需要进行这一步,上述出现错误可查看排错报告
[root@gitlab ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...1:policycoreutils-python-2.5-34.el7################################# [100%]//启动postfix服务并设置开机自启
[root@gitlab ~]# systemctl enable --now postfix.service 
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@gitlab ~]# ss -antl      //查看25号端口是否开启
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 100                              127.0.0.1:25                              0.0.0.0:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*              
LISTEN            0                 100                                  [::1]:25 //下载gitlab的rpm包
[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
--2023-10-07 14:50:24--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-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: 1295805808 (1.2G) [application/x-redhat-package-manager]
Saving to: ‘gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm’gitlab-ce-16.4.1-ce.0.el7.x86_64. 100%[===========================================================>]   1.21G  20.3MB/s    in 81s     2023-10-07 14:51:45 (15.2 MB/s) - ‘gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm’ saved [1295805808/1295805808][root@gitlab ~]# ls
anaconda-ks.cfg  gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@gitlab ~]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...1:gitlab-ce-16.4.1-ce.0.el7        ################################# [100%]
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 reconfigureFor a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.mdHelp us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-4
//出现上述的狐狸标识则表示安装成功

6.2.配置gitlab

//修改配置文件
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
[root@gitlab ~]# grep '^external_url' /etc/gitlab/gitlab.rb
external_url 'http://192.168.195.133'    //将此处设为gitlab的服务器ip地址亦或域名
[root@gitlab ~]# grep '8080' /etc/gitlab/gitlab.rbgitlab_workhorse['auth_backend'] = "http://localhost:8080"  //将两处8080端口的行取消注释puma['port'] = 8080 //重载配置文件并重启gitlab
[root@gitlab ~]# gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 2767) 1s
ok: run: gitaly: (pid 2777) 0s
ok: run: gitlab-exporter: (pid 2793) 0s
ok: run: gitlab-kas: (pid 2806) 0s
ok: run: gitlab-workhorse: (pid 2816) 1s
ok: run: logrotate: (pid 2827) 0s
ok: run: nginx: (pid 2833) 0s
ok: run: node-exporter: (pid 2841) 1s
ok: run: postgres-exporter: (pid 2847) 0s
ok: run: postgresql: (pid 2857) 0s
ok: run: prometheus: (pid 2866) 0s
ok: run: puma: (pid 2882) 1s
ok: run: redis: (pid 2887) 0s
ok: run: redis-exporter: (pid 2895) 0s
ok: run: sidekiq: (pid 2908) 0s//查看当前的gitlab版本
[root@gitlab ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1//查看端口号
[root@gitlab ~]# ss -antl
State          Recv-Q         Send-Q                   Local Address:Port                   Peer Address:Port         
LISTEN         0              1024                         127.0.0.1:9093                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9100                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9229                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8080                        0.0.0.0:*            
LISTEN         0              128                          127.0.0.1:9168                        0.0.0.0:*            
LISTEN         0              511                            0.0.0.0:80                          0.0.0.0:*            
LISTEN         0              128                          127.0.0.1:8082                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9236                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8150                        0.0.0.0:*            
LISTEN         0              128                            0.0.0.0:22                          0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8151                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8153                        0.0.0.0:*            
LISTEN         0              100                          127.0.0.1:25                          0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8154                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:8155                        0.0.0.0:*            
LISTEN         0              128                          127.0.0.1:8092                        0.0.0.0:*            
LISTEN         0              511                            0.0.0.0:8060                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9121                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9090                        0.0.0.0:*            
LISTEN         0              1024                         127.0.0.1:9187                        0.0.0.0:*            
LISTEN         0              1024                                 *:9094                              *:*            
LISTEN         0              128                              [::1]:9168                           [::]:*            
LISTEN         0              128                               [::]:22                             [::]:*            
LISTEN         0              100                              [::1]:25                             [::]:*

6.3.破解gitlab管理员密码

方法一:
(仅适用于初次安装服务)
[root@note1 ~]# cd /etc/gitlab/
[root@note1 gitlab]# ls
gitlab.rb  gitlab-secrets.json  initial_root_password  trusted-certs
[root@note1 gitlab]# cat initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.Password: 0h2AiLpPTnvB921far8MtZYmL3blSz9bMms7E3xqnVs=   //此条长代码就是我们的临时密码# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.方法二
(没有受限范围,直接通过破解密码进行登录)
[root@gitlab ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]GitLab:       16.4.1 (e6801ed8d44) FOSSGitLab Shell: 14.28.0PostgreSQL:   13.11
------------------------------------------------------------[ booted in 21.58s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(id: 1).first    //id为1的是超级管理员
=> #<User id:1 @root>
irb(main):002:0> user.password = 'redhat123'       //密码必须至少8个字符
=> "redhat123" 
irb(main):003:0> user.password_confirmation = 'redhat123'  //再次输入密码
=> "redhat123"
irb(main):004:0> user.save!  //保存修改,若无问题将返回true
=> true
irb(main):005:0> exit   //退出

6.4.查看gitlab的web页面

在这里插入图片描述

部署gitlab完成

7.部署jenkins主机

7.1.部署tomcat

Jenkins是一个Java程序,所以要依赖tomcat

//安装java环境
[root@jenkins ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel wget vim//查看安装的版本,能够查看到版本则说明安装成功
[root@jenkins ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)//拉取tomcat软件包
[root@jenkins ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
--2023-10-10 13:41:29--  https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
Resolving archive.apache.org (archive.apache.org)... 65.108.204.189, 2a01:4f9:1a:a084::2
Connecting to archive.apache.org (archive.apache.org)|65.108.204.189|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11692853 (11M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.80.tar.gz’apache-tomcat-9.0.80.tar.gz   100%[===============================================>]  11.15M  25.2KB/s    in 5m 55s  2023-10-10 13:47:25 (32.1 KB/s) - ‘apache-tomcat-9.0.80.tar.gz’ saved [11692853/11692853][root@jenkins ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.80.tar.gz//解压至指定目录
[root@jenkins ~]# tar xf apache-tomcat-9.0.80.tar.gz -C /usr/local/
[root@jenkins ~]# ls /usr/local/
apache-tomcat-9.0.80  bin  etc  games  include  lib  lib64  libexec  sbin  share  src//设置tomcat软链接,方便后续如果更换tomcat版本后也能直接使用
[root@jenkins ~]# cd //usr/local/
[root@jenkins local]# ll
total 0
drwxr-xr-x  9 root root 220 Oct 10 13:49 apache-tomcat-9.0.80
drwxr-xr-x. 2 root root   6 Aug 12  2018 bin
drwxr-xr-x. 2 root root   6 Aug 12  2018 etc
drwxr-xr-x. 2 root root   6 Aug 12  2018 games
drwxr-xr-x. 2 root root   6 Aug 12  2018 include
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib64
drwxr-xr-x. 2 root root   6 Aug 12  2018 libexec
drwxr-xr-x. 2 root root   6 Aug 12  2018 sbin
drwxr-xr-x. 5 root root  49 Jul 20 11:24 share
drwxr-xr-x. 2 root root   6 Aug 12  2018 src
[root@jenkins local]# ln -s apache-tomcat-9.0.80 tomcat
[root@jenkins local]# ll
total 0
drwxr-xr-x  9 root root 220 Oct 10 13:49 apache-tomcat-9.0.80
drwxr-xr-x. 2 root root   6 Aug 12  2018 bin
drwxr-xr-x. 2 root root   6 Aug 12  2018 etc
drwxr-xr-x. 2 root root   6 Aug 12  2018 games
drwxr-xr-x. 2 root root   6 Aug 12  2018 include
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib64
drwxr-xr-x. 2 root root   6 Aug 12  2018 libexec
drwxr-xr-x. 2 root root   6 Aug 12  2018 sbin
drwxr-xr-x. 5 root root  49 Jul 20 11:24 share
drwxr-xr-x. 2 root root   6 Aug 12  2018 src
lrwxrwxrwx  1 root root  20 Oct 10 13:51 tomcat -> apache-tomcat-9.0.80
[root@jenkins local]# cd tomcat/
[root@jenkins tomcat]# pwd
//usr/local/tomcat
[root@jenkins tomcat]# ls
bin           conf             lib      logs    README.md      RUNNING.txt  webapps
BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
[root@jenkins tomcat]# ls bin/
bootstrap.jar       ciphers.sh                    daemon.sh     setclasspath.bat  startup.sh            version.bat
catalina.bat        commons-daemon.jar            digest.bat    setclasspath.sh   tomcat-juli.jar       version.sh
catalina.sh         commons-daemon-native.tar.gz  digest.sh     shutdown.bat      tomcat-native.tar.gz
catalina-tasks.xml  configtest.bat                makebase.bat  shutdown.sh       tool-wrapper.bat
ciphers.bat         configtest.sh                 makebase.sh   startup.bat       tool-wrapper.sh上述的bin目录中我们能够用到的catalina.sh、shutdown.sh、version.sh、startup.sh、configtest.sh
这几个执行文件,用途分别是:
catalina.sh 能够关闭和开启服务(常用)
shutdown.sh 只能关闭服务(不是关闭主机)
startup.sh 只能开启服务
version.sh 查看tomcat版本
configtest.sh 测试配置文件是否存在错误,检查配置文件//将tomcat的lib位置存放在/etc/ld.so.conf/d/下面,命名一个自身名字的文件,方便查找
[root@jenkins tomcat]# ls
bin           conf             lib      logs    README.md      RUNNING.txt  webapps
BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
[root@jenkins tomcat]# vim /etc/ld.so.conf.d/tomcat.conf
[root@jenkins tomcat]# cat /etc/ld.so.conf.d/tomcat.conf
/usr/local/tomcat/lib
[root@jenkins tomcat]# ldconfig -v
ldconfig: Can't stat /libx32: No such file or directory
ldconfig: Path `/usr/lib' given more than once
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
/usr/lib64//bind9-export:libisccfg-export.so.163 -> libisccfg-export.so.163.0.4libisc-export.so.1104 -> libisc-export.so.1104.0.0libirs-export.so.161 -> libirs-export.so.161.0.0libdns-export.so.1107 -> libdns-export.so.1107.1.0
/usr/local/tomcat/lib:
/lib:
/lib64://使用绝对路径执行/usr/local/tomcat/bin/下面的脚本,tomcat不能写进环境变量,放置后续更改tomcat版本后环境变量仍是之前的tomcat版本
[root@jenkins tomcat]# pwd
//usr/local/tomcat
[root@jenkins tomcat]# cd bin
[root@jenkins bin]# pwd
/usr/local/tomcat/bin
[root@jenkins bin]# ./catalina.sh start
Using CATALINA_BASE:   //usr/local/tomcat
Using CATALINA_HOME:   //usr/local/tomcat
Using CATALINA_TMPDIR: //usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       //usr/local/tomcat/bin/bootstrap.jar://usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@jenkins bin]# ss -antl
State          Recv-Q         Send-Q                      Local Address:Port                 Peer Address:Port        
LISTEN         0              128                               0.0.0.0:22                        0.0.0.0:*           
LISTEN         0              1                      [::ffff:127.0.0.1]:8005                            *:*           
LISTEN         0              100                                     *:8080                            *:*           
LISTEN         0              128                                  [::]:22                           [::]:*
[root@jenkins bin]# ps -ef | grep tomcat       //查看tomcat进程
root        1585       1  0 14:02 pts/0    00:00:06 /usr/bin/java -Djava.util.logging.config.file=//usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath //usr/local/tomcat/bin/bootstrap.jar://usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=//usr/local/tomcat -Dcatalina.home=//usr/local/tomcat -Djava.io.tmpdir=//usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root        1640    1455  0 14:22 pts/0    00:00:00 grep --color=auto tomcat服务启动成功

访问tomcat的web页面
在这里插入图片描述

7.2.安装jenkins

Jenkins官网https://www.jenkins.io/download/

///安装Jenkins所需要的Java-17-openjdk
[root@jenkins local]# cd jenkins/
[root@jenkins jenkins]# yum -y install java-17-openjdk java-17-openjdk-devel//由于安装tomcat时安装的Java1.8,但是Jenkins需要Java17,为了防止版本冲突,需要配置jdk的优先级,从而能够同时使用这两个版本
[root@jenkins jenkins]# alternatives --config java  //优先使用java-17-openjdkThere are 2 programs which provide 'java'.Selection    Command
-----------------------------------------------1           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre/bin/java)Enter to keep the current selection[+], or type selection number: 1  //优先选择java-17
[root@jenkins ~]# bash     //bash使其生效 //下载jenkins.war的包
[root@jenkins ~]# wget wget https://get.jenkins.io/war-stable/2.414.2/jenkins.war
[root@jenkins ~]# ls
anaconda-ks.cfg  apache-tomcat-9.0.80.tar.gz  jenkins.war////将Jenkins包复制到我们为其准备的其中一个tomcat的/usr/local/jenkins/webapps/目录中去,也就是我们前面复制的jenkins中去
[root@jenkins ~]# cp jenkins.war /usr/local/tomcat/webapps/
[root@jenkins ~]# cd /usr/local/tomcat/webapps/
[root@jenkins webapps]# ls
docs  examples  host-manager  jenkins.war  manager  ROOT//重启服务后,则会自动解压jenkins.war
[root@jenkins webapps]# ../bin/catalina.sh stop
Using CATALINA_BASE:   /usr/local/jenkins
Using CATALINA_HOME:   /usr/local/jenkins
Using CATALINA_TMPDIR: /usr/local/jenkins/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/jenkins/bin/bootstrap.jar:/usr/local/jenkins/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@jenkins webapps]# ../bin/catalina.sh start
Using CATALINA_BASE:   /usr/local/jenkins
Using CATALINA_HOME:   /usr/local/jenkins
Using CATALINA_TMPDIR: /usr/local/jenkins/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/jenkins/bin/bootstrap.jar:/usr/local/jenkins/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@jenkins webapps]# ss -antl
State          Recv-Q         Send-Q                      Local Address:Port                 Peer Address:Port        
LISTEN         0              128                               0.0.0.0:22                        0.0.0.0:*           
LISTEN         0              128                                  [::]:22                           [::]:*           
LISTEN         0              1                      [::ffff:127.0.0.1]:8005                            *:*           
LISTEN         0              100                                     *:8080                            *:*           
[root@jenkins webapps]# ls      //jenkins自动解压
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT

7.3.访问jenkins的web页面

查看临时密码,登录进去,后面会重新设置一个管理员密码的

[root@jenkins webapps]# cat /root/.jenkins/secrets/initialAdminPassword
16e8260f352948819f217725970af6d2

建议直接安装全部插件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

7.4.安装git、maven、docker

//安装git
[root@jenkins ~]# yum -y install git
//安装maven
[root@jenkins ~]# yum -y install maven
//验证
[root@jenkins ~]# mvn -v
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_312, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-193.el8.x86_64", arch: "amd64", family: "unix"

7.5.安装docker

[root@jenkins ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
[root@jenkins ~]# dnf repolist -v  //查看是否启用
[root@jenkins ~]# dnf list docker-ce --showduplicates | sort -r //查看可安装版本
[root@jenkins ~]# yum -y install docker-ce-24.0.6-1.el8 --allowerasing
[root@jenkins ~]# systemctl enable --now docker.service

7.6.配置Jenkins主机可以从harbor主机拉取镜像,以及免密登录

//配置可以拉取harbor的镜像
[root@jenkins ~]# vim /etc/docker/daemon.json 
[root@jenkins ~]# cat /etc/docker/daemon.json
{
"insecure-registries": ["harbor.com"]
}[root@jenkins ~]#//配置免密登录,先生成密钥对
[root@jenkins webapps]# 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:vzUKGKdNcdU+1HrNg9AG/16CvAafso9l/z/4GXZI+Yg root@jenkins
The key's randomart image is:
+---[RSA 3072]----+
|           .+. . |
|           o.oo .|
|        . . o+.o.|
|         o . o=o+|
|      . S . o ++o|
|       B . o =.=.|
|      o o o E ++o|
|         . @ +..+|
|          =.. o+=|
+----[SHA256]-----+
[root@jenkins webapps]# ssh-copy-id root@192.168.195.133
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.195.133 (192.168.195.133)' can't be established.
ECDSA key fingerprint is SHA256:KtCxYXSsV732izj+QL2uzJDCS2G/X1MOMV+uUkriDno.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.195.133's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'root@192.168.195.133'"
and check to make sure that only the key(s) you wanted were added.[root@jenkins webapps]# ssh-copy-id root@192.168.195.135
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.195.135 (192.168.195.135)' can't be established.
ECDSA key fingerprint is SHA256:rX8qo9h9J++q89dUg33ZnWDL7KT30i/It603EM37Mic.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.195.135's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'root@192.168.195.135'"
and check to make sure that only the key(s) you wanted were added.[root@jenkins webapps]# ssh-copy-id root@192.168.195.136
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.195.136 (192.168.195.136)' can't be established.
ECDSA key fingerprint is SHA256:+4lBR7hgzjFe6gOp4we1Rd6lJJiHWgVeIQIN308d1gU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.195.136's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'root@192.168.195.136'"
and check to make sure that only the key(s) you wanted were added.[root@jenkins webapps]#

8.部署harbor.com主机

8.1.安装harbor前需先安装docker及docker-compose

[root@harbor ~]# curl -SL https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:--  0:00:16 --:--:--     0
curl: (52) Empty reply from server
[root@harbor ~]# chmod +x /usr/local/bin/docker-compose   //添加执行权限
[root@harbor ~]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose //将其链接到/usr/bin/下面

能够使用docker-compose --help则表示成功
在这里插入图片描述

8.2.安装harbor.com

进入harbor官网,拉取harbor二进制包

[Harbor官方文档](Releases · goharbor/harbor (github.com))
在这里插入图片描述

下载完成后,将该压缩包传到harbor.com主机中
在这里插入图片描述

[root@harbor ~]# ls
anaconda-ks.cfg  harbor-offline-installer-v2.9.1.tgz//解压压缩包
[root@harbor harbor]# tar xf harbor.v2.9.1.tar.gz -C /usr/local/

复制出一份harbor.yml文件,编辑/usr/local/harbor/下的harbor.yml文件

执行install.sh文件
[root@harbor harbor]# ./install.sh [Step 0]: checking if docker is installed ...Note: docker version: 24.0.7[Step 1]: checking docker-compose is installed ...Note: Docker Compose version v2.21.0[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-jobservice:v2.9.1
Loaded image: goharbor/harbor-registryctl:v2.9.1
Loaded image: goharbor/harbor-core:v2.9.1
Loaded image: goharbor/harbor-log:v2.9.1
Loaded image: goharbor/harbor-db:v2.9.1
Loaded image: goharbor/harbor-exporter:v2.9.1
Loaded image: goharbor/redis-photon:v2.9.1
Loaded image: goharbor/nginx-photon:v2.9.1
Loaded image: goharbor/registry-photon:v2.9.1
Loaded image: goharbor/trivy-adapter-photon:v2.9.1
Loaded image: goharbor/prepare:v2.9.1
Loaded image: goharbor/harbor-portal:v2.9.1[Step 3]: preparing environment ...[Step 4]: preparing harbor configs ...
prepare base dir is set to /usr/local/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registry/root.crt
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dirNote: stopping existing Harbor instance ...
[+] Running 10/10✔ Container harbor-jobservice  Removed                                                                          0.3s ✔ Container nginx              Removed                                                                          0.3s ✔ Container registryctl        Removed                                                                          0.3s ✔ Container harbor-portal      Removed                                                                          0.2s ✔ Container harbor-core        Removed                                                                          0.2s ✔ Container redis              Removed                                                                          0.2s ✔ Container harbor-db          Removed                                                                          0.2s ✔ Container registry           Removed                                                                          0.2s ✔ Container harbor-log         Removed                                                                         10.1s ✔ Network harbor_harbor        Removed                                                                          0.1s [Step 5]: starting Harbor ...
[+] Running 10/10✔ Network harbor_harbor        Created                                                                          0.1s ✔ Container harbor-log         Started                                                                          0.0s ✔ Container harbor-portal      Started                                                                          0.0s ✔ Container harbor-db          Started                                                                          0.0s ✔ Container redis              Started                                                                          0.0s ✔ Container registryctl        Started                                                                          0.0s ✔ Container registry           Started                                                                          0.0s ✔ Container harbor-core        Started                                                                          0.0s ✔ Container nginx              Started                                                                          0.0s ✔ Container harbor-jobservice  Started                                                                          0.0s 
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]#//查看启动的容器
[root@harbor harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                   PORTS                                   NAMES
350ca8862054   goharbor/harbor-jobservice:v2.9.1    "/harbor/entrypoint.…"   5 minutes ago   Up 5 minutes (healthy)                                           harbor-jobservice
b72bc2f82a68   goharbor/nginx-photon:v2.9.1         "nginx -g 'daemon of…"   5 minutes ago   Up 5 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
44f7ef47465b   goharbor/harbor-core:v2.9.1          "/harbor/entrypoint.…"   5 minutes ago   Up 5 minutes (healthy)                                           harbor-core
1b21077159ba   goharbor/harbor-portal:v2.9.1        "nginx -g 'daemon of…"   5 minutes ago   Up 5 minutes (healthy)                                           harbor-portal
e806f3263cd6   goharbor/registry-photon:v2.9.1      "/home/harbor/entryp…"   5 minutes ago   Up 5 minutes (healthy)                                           registry
e88001619f8b   goharbor/harbor-db:v2.9.1            "/docker-entrypoint.…"   5 minutes ago   Up 5 minutes (healthy)                                           harbor-db
3b0dc2c89b77   goharbor/harbor-registryctl:v2.9.1   "/home/harbor/start.…"   5 minutes ago   Up 5 minutes (healthy)                                           registryctl
dd19f6c1fbfa   goharbor/redis-photon:v2.9.1         "redis-server /etc/r…"   5 minutes ago   Up 5 minutes (healthy)                                           redis
e6ebc7e08482   goharbor/harbor-log:v2.9.1           "/bin/sh -c /usr/loc…"   5 minutes ago   Up 5 minutes (healthy)   127.0.0.1:1514->10514/tcp               harbor-log//镜像存放位置,镜像都存放在我们指定的/data目录下面
[root@harbor harbor]# ls /data
ca_download  database  job_logs  redis  registry  secret

通过IP访问harbor的web界面
在这里插入图片描述
在这里插入图片描述

使用Harbor的注意事项:

  1. 在客户端上传镜像时一定要记得执行docker login进行用户认证,否则无法直接push
  2. 在客户端使用的时候如果不是用的https则必须要在客户端的/etc/docker/daemon.json配置文件中配置insecure-registries参数
  3. 数据存放路径应在配置文件中配置到一个容量比较充足的共享存储中
  4. Harbor是使用docker-compose命令来管理的,如果需要停止Harbor也应用docker-compose stop来停止,其他参数请–help
将harbor设置为开机自启
//由于想要关闭或开启harbor需要进入到有docker-compose.yml文件的目录下执行,所以我们将该命令放到虚拟机启动最后执行的一个文件中去,也就是/etc/rc.local文件中[root@harbor harbor]# vim /etc/rc.local 
[root@harbor harbor]# head -5 /etc/rc.local
#!/bin/bash
cd /usr/local/harbor/ && docker-compose start
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
[root@harbor harbor]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Mar 24  2020 /etc/rc.local -> rc.d/rc.local
[root@harbor harbor]# chmod +x /etc/rc.d/rc.local
[root@harbor harbor]# ll /etc/rc.d/rc.local 
-rwxr-xr-x. 1 root root 520 Nov  7 22:29 /etc/rc.d/rc.local//将cd /usr/local/harbor/ && docker-compose start写入到这个文件中后,他就会在开启这个虚拟机的时候执行进入/usr/local/harbor/目录中执行开启harbor的命令

9.部署docker主机

9.1.安装docker服务

[root@docker ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
[root@docker ~]# dnf repolist -v  //查看是否启用
[root@docker ~]# dnf list docker-ce --showduplicates | sort -r //查看可安装版本
[root@docker ~]# yum -y install docker-ce-24.0.6-1.el8 --allowerasing
[root@docker ~]# systemctl enable --now docker.service

9.2.制作一个基础的tomcat镜像,并上传到私有镜像仓库

//制作tomcat镜像,并上传到harbor.com主机
[root@docker ~]# mkdir tomcat
[root@docker ~]# ls
anaconda-ks.cfg  ansible  tomcat
[root@docker ~]# cd tomcat/
[root@docker tomcat]# vim dockerfile 
[root@docker tomcat]# cat dockerfile 
FROM centos:8RUN rm -rf /etc/yum.repos.d/* && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
yum clean all && \
yum makecache && \
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel && \
yum -y install wget && \
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz && \
tar -xf apache-tomcat-9.0.80.tar.gz && \
mv apache-tomcat-9.0.80 /usr/local/tomcat && \
/usr/local/tomcat/bin/startup.shCMD ["/usr/local/tomcat/bin/catalina.sh","run"][root@docker tomcat]# docker images
REPOSITORY                  TAG       IMAGE ID       CREATED       SIZE
harbor.com/library/tomcat   v1.0      e49ab8188d29   7 hours ago   539MB//配置连接harbor.com私有镜像仓库
[root@docker ~]# vim /etc/docker/daemon.json
[root@docker ~]# cat /etc/docker/daemon.json
{
"insecure-registries": ["harbor.server"]
}
[root@docker ~]# systemctl daemon-reload
[root@docker ~]# systemctl restart docker.service//上传镜像到私有仓库harbor.com主机
[root@docker ~]# docker login harbor.com   //登录到私有镜像仓库
Username: admin
Password:                    //此处密文密码为Harbor.com
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded   //登录成功
[root@docker ~]#//上传到私有镜像仓库
[root@docker ~]# docker push harbor.server/library/tomcat:v1.0

在这里插入图片描述

10.项目代码完整发布流程

10.1.将代码上传到gitlab主机

首先需要在gitlab代码仓库新建一个空项目
在这里插入图片描述
在这里插入图片描述

//从公共代码仓库拉取需要的代码
[root@gitlab ~]# git clone 'https://gitee.com/forgotten/tomcat-java-demo.git'
//上传代码到本地代码仓库的操作
[root@gitlab ~]# git config --global user.name "root"
[root@gitlab ~]# git config --global user.email "2046807065@qq.com"
[root@gitlab ~]# git clone http://192.168.195.133/root/redhat
[root@gitlab ~]# mv tomcat-java-demo/* redhat/
mv: overwrite 'wanf/README.md'? y
[root@gitlab ~]# cd redhat/
[root@gitlab wanf]# ls
db deploy.yaml Dockerfile jenkinsfile LICENSE pom.xml README.md src
[root@gitlab redhat]#
[root@gitlab redhat]# git add *
[root@gitlab redhat]# git commit -m "test"
[root@gitlab redhat]# git push --set-upstream origin
Username for 'http://192.168.195.133': root
Password for 'http://root@192.168.195.133':          //此处为自己破解密码时设置的密码
Enumerating objects: 849, done.
Counting objects: 100% (849/849), done.
Compressing objects: 100% (754/754), done.
Writing objects: 100% (847/847), 649.86 KiB | 7.30 MiB/s, done.
Total 847 (delta 228), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (228/228), done.
To http://192.168.179.13/root/wanf.git
3d32c31..58d6311 main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

10.2.2.在Jenkins创建流水线项目,并运行项目

jenkins流水线代码如下:

pipeline {agent anystages {stage("pull code"){steps {sh """git clone http://192.168.195.133/root/redhat && mv /root/.jenkins/workspace/devops/redhat /root/redhat"""}}stage("pull images"){steps {sh """docker pull harbor.com/library/tomcat:v1.0"""}}stage("make .war pkgs"){steps {sh """cd /root/redhat && mvn clean package -Dmaven.test.skip=true && mv /root/redhat/target/ly-simple-tomcat-0.0.1-SNAPSHOT.war /root/test.war"""}}stage("vim dockerfile"){steps {sh """echo "FROM harbor.com/library/tomcat:v1.0" >> /root/dockerfile && echo "RUN rm -rf /usr/local/tomcat/webapps/ROOT" >> /root/dockerfile && echo "COPY ./test.war /usr/local/tomcat/webapps/ROOT.war" >> /root/dockerfile && echo 'CMD ["/usr/local/tomcat/bin/catalina.sh","run"]' >> /root/dockerfile"""}}stage("make new images"){steps {sh """cd /root && docker build -t harbor.com/library/tomcat:v0.2 ."""}}stage("push images"){steps {sh """docker login harbor.com -u admin -p Harbor12345 && docker push harbor.com/library/tomcat:v0.2"""}}stage("webs pull and run"){steps {sh """ssh docker "docker pull harbor.com/library/tomcat:v0.2" && ssh docker "docker run -d --name test -p 80:8080 -it harbor.com/library/tomcat:v0.2""""}}}
}  

在这里插入图片描述

在这里插入图片描述

11.最终测试(在docker主机上测试)

[root@docker tomcat]# docker ps
CONTAINER ID   IMAGE                            COMMAND                  CREATED       STATUS       PORTS                                   NAMES
085340cd4f6e   harbor.com/library/tomcat:v0.2   "/usr/local/tomcat/b…"   5 hours ago   Up 5 hours   0.0.0.0:80->8080/tcp, :::80->8080/tcp   test

在浏览器上访问docker主机IP地址
在这里插入图片描述

成功部署

11.错误排查报告

问题一

//出现一下问题,表示我们的源中没有policycoreutils-python这个软件包
[root@gitlab yum.repos.d]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:46 ago on Sat 07 Oct 2023 02:11:07 PM CST.
Package curl-7.61.1-12.el8.x86_64 is already installed.
Package openssh-server-8.0p1-4.el8_1.x86_64 is already installed.
Package openssh-clients-8.0p1-4.el8_1.x86_64 is already installed.
Package cronie-1.5.2-4.el8.x86_64 is already installed.
No match for argument: policycoreutils-python
Error: Unable to find a match: policycoreutils-python

解决方法:
在https://pkgs.org/这个网站中下载这个包

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
上传过去后使用rpm的方式安装即可:

[root@gitlab yum.repos.d]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...1:policycoreutils-python-2.5-34.el7################################# [100%]

问题二

//若出现下列错误,则表示文件/usr/share/man/ru/man8/semodule_package.8.gz从安装policycoretils -python-2.5-34.el7。X86_64与包policycoretils -2.9-9.el8. X86_64中的文件冲突[root@gitlab yum.repos.d]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]file /usr/bin/semodule_package from install of policycoreutils-python-2.5-34.el7.x86_64 conflicts with file from package policycoreutils-2.9-9.el8.x86_64file /usr/share/man/ru/man8/semodule_package.8.gz from install of policycoreutils-python-2.5-34.el7.x86_64 conflicts with file from package policycoreutils-2.9-9.el8.x86_64//解决方法
[root@gitlab yum.repos.d]# rpm -e policycoreutils-2.9-9.el8.x86_64

相关文章:

devops完整搭建教程(gitlab、jenkins、harbor、docker)

devops完整搭建教程&#xff08;gitlab、jenkins、harbor、docker&#xff09; 文章目录 devops完整搭建教程&#xff08;gitlab、jenkins、harbor、docker&#xff09;1.简介&#xff1a;2.工作流程&#xff1a;3.优缺点4.环境说明5.部署前准备工作5.1.所有主机永久关闭防火墙…...

页面上时间显示为数字 后端返回给前端 response java系统

有时候&#xff0c;在一个系统里&#xff0c;会看到&#xff0c;有的页面时间显示正常&#xff0c;有的页面时间显示成数字。像这样&#xff1a; "createTime": 1698706491000 这是因为出参没有做转换&#xff0c;直接将java.util.Date类型的数据返回给前端了。 返…...

idea怎么配置tomcat

要在IntelliJ IDEA中配置Tomcat&#xff0c;请按照以下步骤操作&#xff1a; 打开IntelliJ IDEA&#xff0c;点击File -> Settings&#xff08;或者使用快捷键CtrlAltS&#xff09;。 在设置窗口左侧导航栏中&#xff0c;选择Build, Execution, Deployment -> Applicati…...

GoLong的学习之路(二十三)进阶,语法之并发(go最重要的特点)(锁,sync包,原子操作)

这章是我并发系列中最后的一章。这章主要讲的是锁。但是也会讲上一章channl遗留下的一些没有讲到的内容。select关键字的用法&#xff0c;以及错误的一些channl用法。废话不多说。。。 文章目录 select多路复用通道错误示例并发安全和锁问题描述互斥锁读写互斥锁 syncsync.Wait…...

asp.net core 生命周期

在ASP.NET Core中&#xff0c;有三个重要的生命周期阶段&#xff1a; 请求生命周期&#xff08;Request Lifecycle&#xff09;&#xff1a;请求生命周期从接收到客户端的HTTP请求开始&#xff0c;到响应结果发送给客户端结束。在请求生命周期中&#xff0c;ASP.NET Core会创建…...

Leetcode刷题详解—— 目标和

1. 题目链接&#xff1a;494. 目标和 2. 题目描述&#xff1a; 给你一个非负整数数组 nums 和一个整数 target 。 向数组中的每个整数前添加 或 - &#xff0c;然后串联起所有整数&#xff0c;可以构造一个 表达式 &#xff1a; 例如&#xff0c;nums [2, 1] &#xff0c;可…...

学习c#的第六天

目录 C# 判断 if 语句 嵌套 if 语句 switch 语句 嵌套 switch 语句 ? : 运算符 C# 循环 循环类型 while 循环 for/foreach 循环 do...while 循环 嵌套循环 循环控制语句 break 语句 continue 语句 无限循环 C# 判断 if 语句 在C#中&#xff0c;if语句用于根…...

第七章 :Spring Boot web开发常用注解(二)

第七章 :Spring Boot web开发常用注解(二) 前言 本章节知识重点:作者结合自身开发经验,以及觉察到的一个现象:Springboot注解全面理解和掌握的并不多,对注解进行了全面总结,共分两个章节,可以作为web开发工程师注解参考手册,SpringBoot常用注解大全,一目了然!。本…...

IOC - Google Guice

Google Guice是一个轻量级的依赖注入框架&#xff0c;专注于依赖注入和IoC&#xff0c;适用于中小型应用。 Spring Framework是一个全面的企业级框架&#xff0c;提供了广泛的功能&#xff0c;适用于大型企业应用。 是吧&#xff01;IOC 容器不止Spring,还有Google Guice,来体…...

国际阿里云:Linux实例负载高问题排查和异常处理!!!

问题描述 在您使用ECS实例过程中&#xff0c;可能会遇到实例系统负载较高的情况&#xff0c;负载过高&#xff0c;可能会引发一系列异常问题&#xff0c;简单说您如下&#xff1a; CPU使用率或负载过高&#xff1a;一般来说&#xff0c;当CPU使用率≥80%时&#xff0c;定义为C…...

【数据结构】二叉树的遍历递归算法详解

二叉树的遍历 &#x1f4ab;二叉树的结点结构定义&#x1f4ab;创建一个二叉树结点&#x1f4ab;在主函数中手动创建一颗二叉树&#x1f4ab;二叉树的前序遍历&#x1f4ab;调用栈递归——实现前序遍历&#x1f4ab;递归实现中序和后序遍历 &#x1f4ab;二叉树的结点结构定义 …...

百度王颖:百度文库以AI创作能力突破语言边界,促进思想碰撞和文化融通

1月9日&#xff0c;2023年世界互联网大会乌镇峰会“网络传播与文明交流互鉴论坛”召开。百度副总裁、互娱和垂类平台负责人王颖出席并发表“以技术搭建跨文化交流桥梁”主题演讲。她表示&#xff0c;在大模型的加持下&#xff0c;百度各个产品都在重构&#xff0c;通过技术助力…...

人工智能基础_机器学习023_理解套索回归_认识L1正则---人工智能工作笔记0063

然后上一节我们说了L1,L2正则是为了提高,模型的泛化能力, 提高泛化能力,实际上就是把模型的公式的w,权重值,变小对吧. 然后我们这里首先看第一个L1正则,是怎么做到把w权重变小的 可以看到最上面是线性回归的损失函数,然后 L1可以看到,这个正则,就是在损失函数的基础上给损失…...

Learning an Animatable Detailed 3D Face Model from In-The-Wild Images论文笔记

Learning an Animatable Detailed 3D Face Model from In-The-Wild Images论文笔记 论文目标:提出一个端到端的框架,可以从非受控的图片中学习高质量、可动画的3D人脸模型。论文方法:论文结果:论文意义: 论文目标:提出一个端到端的框架,可以从非受控的图片中学习高质量、可动画…...

Lenovo联想小新Air-14笔记本2021款AMD锐龙ALC版(82LM)原装出厂Win10镜像和Windows11预装OEM系统

下载链接&#xff1a;https://pan.baidu.com/s/1akLkXM2HIg3eO76jqM-LVA?pwdxvo6 提取码&#xff1a;xvo6 系统自带所有驱动、出厂主题壁纸、系统属性专属LOGO标志、Office办公软件、联想电脑管家等预装程序 所需要工具&#xff1a;16G或以上的U盘 文件格式&#xff1a;…...

在程序中链接静态库

现在我们把上面src目录中的add.cpp、div.cpp、mult.cpp、sub.cpp编译成一个静态库文件libcalc.a。 add_library(库名称 STATIC 源文件1 [源文件2] ...) link_libraries(<static lib> [<static lib>...]) 参数1&#xff1a;指定出要链接的静态库的名字 可以是全…...

TortoiseSVN 状态图标不显示的两种解决办法

文章目录 TortoiseSVN 方式解决注册表方式解决 TortoiseSVN 方式解决 在桌面或者资源管理器中鼠标右键打开 TortoiseSVN 设置选择 Icon Overlays (图标覆盖)Status cache&#xff08;状态缓存&#xff09; 选择 ‘Shell’ 选择 Icon Overlays&#xff08;图标覆盖&#xff09;…...

NSSCTF-Crypto入门题 练习记录贴 ‘‘一‘‘

文章目录 前言001[鹤城杯 2021]easy_crypto002[强网拟态 2021]拟态签到题003[SWPUCTF 2021 新生赛]crypto8004[SWPUCTF 2021 新生赛]crypto7005[SWPUCTF 2021 新生赛]crypto6006[SWPUCTF 2021 新生赛]ez_caesar007[SWPUCTF 2021 新生赛]crypto10008[鹤城杯 2021]A_CRYPTO009[SW…...

Day03:注意事项、this关键字、构造器、JavaBean、String、ArrayList

OOP的注意事项 类名要跟class文件名一致&#xff08;一个class可以有多个类&#xff0c;但只有一个public&#xff0c;且与文件名一致&#xff09;&#xff0c;命名介意大驼峰&#xff1b;如果某个对象没有变量指向他&#xff0c;就成垃圾对象了&#xff08;空指针&#xff09…...

【从0到1设计一个网关】性能优化---缓存

文章目录 为什么要用缓存?Caffeine Cache使用Caffeine效果演示为什么要用缓存? 首先先了解一下为什么在网关中我们需要用到缓存。 我们可以从如下几点来入手这个问题: 处理大规模流量: 网关是系统的入口,需要处理大规模的请求流量。高性能的网关能够快速而有效地处理大量…...

CTF show Web 红包题第六弹

提示 1.不是SQL注入 2.需要找关键源码 思路 进入页面发现是一个登录框&#xff0c;很难让人不联想到SQL注入&#xff0c;但提示都说了不是SQL注入&#xff0c;所以就不往这方面想了 ​ 先查看一下网页源码&#xff0c;发现一段JavaScript代码&#xff0c;有一个关键类ctfs…...

IGP(Interior Gateway Protocol,内部网关协议)

IGP&#xff08;Interior Gateway Protocol&#xff0c;内部网关协议&#xff09; 是一种用于在一个自治系统&#xff08;AS&#xff09;内部传递路由信息的路由协议&#xff0c;主要用于在一个组织或机构的内部网络中决定数据包的最佳路径。与用于自治系统之间通信的 EGP&…...

Go 语言接口详解

Go 语言接口详解 核心概念 接口定义 在 Go 语言中&#xff0c;接口是一种抽象类型&#xff0c;它定义了一组方法的集合&#xff1a; // 定义接口 type Shape interface {Area() float64Perimeter() float64 } 接口实现 Go 接口的实现是隐式的&#xff1a; // 矩形结构体…...

条件运算符

C中的三目运算符&#xff08;也称条件运算符&#xff0c;英文&#xff1a;ternary operator&#xff09;是一种简洁的条件选择语句&#xff0c;语法如下&#xff1a; 条件表达式 ? 表达式1 : 表达式2• 如果“条件表达式”为true&#xff0c;则整个表达式的结果为“表达式1”…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

爬虫基础学习day2

# 爬虫设计领域 工商&#xff1a;企查查、天眼查短视频&#xff1a;抖音、快手、西瓜 ---> 飞瓜电商&#xff1a;京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空&#xff1a;抓取所有航空公司价格 ---> 去哪儿自媒体&#xff1a;采集自媒体数据进…...

.Net Framework 4/C# 关键字(非常用,持续更新...)

一、is 关键字 is 关键字用于检查对象是否于给定类型兼容,如果兼容将返回 true,如果不兼容则返回 false,在进行类型转换前,可以先使用 is 关键字判断对象是否与指定类型兼容,如果兼容才进行转换,这样的转换是安全的。 例如有:首先创建一个字符串对象,然后将字符串对象隐…...

Device Mapper 机制

Device Mapper 机制详解 Device Mapper&#xff08;简称 DM&#xff09;是 Linux 内核中的一套通用块设备映射框架&#xff0c;为 LVM、加密磁盘、RAID 等提供底层支持。本文将详细介绍 Device Mapper 的原理、实现、内核配置、常用工具、操作测试流程&#xff0c;并配以详细的…...

基于Java Swing的电子通讯录设计与实现:附系统托盘功能代码详解

JAVASQL电子通讯录带系统托盘 一、系统概述 本电子通讯录系统采用Java Swing开发桌面应用&#xff0c;结合SQLite数据库实现联系人管理功能&#xff0c;并集成系统托盘功能提升用户体验。系统支持联系人的增删改查、分组管理、搜索过滤等功能&#xff0c;同时可以最小化到系统…...

9-Oracle 23 ai Vector Search 特性 知识准备

很多小伙伴是不是参加了 免费认证课程&#xff08;限时至2025/5/15&#xff09; Oracle AI Vector Search 1Z0-184-25考试&#xff0c;都顺利拿到certified了没。 各行各业的AI 大模型的到来&#xff0c;传统的数据库中的SQL还能不能打&#xff0c;结构化和非结构的话数据如何和…...