一、环境配置和准备工作
机器:
192.168.0.102
192.168.0.112
192.168.0.109
内存建议3G
CPU建议2核
虚拟机建议关闭防火墙
安装jdk1.8
系统:CentOS8.3
二、安装jenkins,nexus,docker,k8s集群
设置镜像仓库地址:
rm -rfv /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
sudo wget -O /etc/yum.repos.d/jenkins.repo
1、安装Jenkins
安装地址:
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install jenkins
jenkins地址:https://www.jenkins.io/zh/download/
https://pkg.jenkins.io/redhat-stable/
或者你直接选择war包安装,直接通过java -jar命令启动。这里选择war包方式,因为rpm安装方式有时候网络会不太好,下载可能会出现问题。
启动Jenkins
touch log-jenkins.log
nohup java -jar jenkins.war --httpPort=8085 1>log-jenkins.log &
浏览器打开:http://192.168.0.102:8080
在以下路径可以看到Jenkins登录的初始密码
/root/.jenkins/secrets/initialAdminPassword
点击继续
选择安装自定义插件
可能存在有些插件安装不了的情况,点击重试安装,再安装不了,可以不用管。因为有些插件暂时用不到。
配置第一个实例
安装完成
2.安装Nexus
下载地址:
https://www.sonatype.com/products/repository-oss-download
备用下载地址:
链接:https://pan.baidu.com/s/1ZZz1gMIybU4dY52Dx5dNcQ
提取码:2v8e
解压tar包
tar -zxvf nexus-3.30.1-01-unix.tar.gz
mv nexus-3.30.1-01 nexus
进入nexus的bin目录
cd nexus/bin
配置nexus
vim /etc/profile
# 配置nexus
export NEXUS_HOME=/soft/nexus
export PATH=$NEXUS_HOME/bin:$PATH
source /etc/profile
编辑nexus.rc
run_as_user="root"
启动nexus
[root@localhost bin]# nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
nexus status
[root@localhost bin]# nexus status
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
nexus is running.
访问地址:http://192.168.0.102:8081/
3.安装gitlab
官网地址:
https://about.gitlab.com/install/
sudo dnf install -y curl policycoreutils openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd
# Check if opening the firewall is needed with: sudo systemctl status firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
sudo dnf -y install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
设置访问地址
sudo EXTERNAL_URL="http://192.168.0.102" dnf install -y gitlab-ee
这个过程会需要点时间,耐心等待
打开网址:
http://192.168.0.102/
4.102服务器上安装maven
下载地址:http://maven.apache.org/download.cgi
(我下载的是maven3.8)
解压
tar -zxvf apache-maven-3.8.1-bin.tar.gz
设置环境变量
vim /etc/profile
# 配置maven
export MVN_HOME=/soft/maven
export PATH=$MVN_HOME/bin:$PATH
让其生效
source /etc/profile
[root@localhost maven]# mvn -version
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /soft/maven
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /soft/jdk1.8/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.el8.x86_64", arch: "amd64", family: "unix"
5.安装完毕之后,下面通过gitlab的webhook,触发Jenkins,让Jenkins拉取最新gitlab代码,Jenkins将最新代码打包
1)配置gitlab
2)配置Jenkins
登录Jenkins,创建一个项目,选择自由风格项目
3)在gitlab上建立一个项目
4)配置ssh,并将ssh传到gitlab上
[root@localhost soft]# ssh-keygen -t rsa -c
Enter file in which the key is (/root/.ssh/id_rsa):
/root/.ssh/id_rsa: No such file or directory
[root@localhost soft]# 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:LO5SD79PpEQTG5+72Pa3DFuJjhJgK/WuCfDZ5zGfPSE root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| o |
| = . |
| + o |
| +o . . |
| . o.+S o |
| o.++oo=E... . |
| +oo=*.=.o.o |
| .o +=* *.=. |
| .+.o+= =oo. |
+----[SHA256]-----+
[root@localhost soft]# cd /root/.ssh/
[root@localhost .ssh]# ls
id_rsa id_rsa.pub
[root@localhost .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCqFfTDIvNtMQZQoU3TlYGskHbkYRRYykwyc00J3J+hEVJ/Hv4kjgHz8VegOT8uNHmR+MQ8AkfRIKTb9DzzLgbruiD5rdNmSRRhvoVtk7VNtn5qSu8wyX4Eyz97GR+Df0CLJB494JHs/VztHR32YSkoAY+ats5tSYfJQn6yrUhaBZKoSW4P+M5BI7V1z6UeJPkq67ZciOCW56QvHFD826FU1uXn9+YWpRutz7MnWpXhV7VTx19SsNfFlN93142GSvpMJvNVaM9x521tmev/OHs8uCEG1wgeFbrQal38OW87DJ0rak2CAqthZ8koKsrRe2VtGXdQA8VKC53v1Y8Gze+GYLGTlW1b/fUyLklCa98qj+AA0XJNUIfevP7e4tzm02vnlyx1T4ZQ82PMsg4JNvRo0yXvfBFL3y8Oqm89EbB9LgIQB0nPh13RFYPXZnuRKMG3eOF3FGPilMxQElOYT3I1jgKtxkcnOMNH0XNaagT4U8AquHVbhXMXTCgWFDxx2M8= root@localhost.localdomain
将上述ssh密钥拷贝到gitlab项目中
4)配置Jenkins的git地址(需要服务器安装git)
5)配置Jenkins插件Gitlab Hook
设置secret token
6)将上述信息配置到gitlab中
测试webhook
出现200说明配置成功。同时Jenkins也会触发动作
===============================================================================
设置maven+docker私有仓库地址为nexus
1)第一次登录nexus
2)根据提示找到初始密码,登录之后修改密码
3)选择maven2(proxy)设置阿里云镜像仓库
阿里仓库地址:http://maven.aliyun.com/nexus/content/groups/public/
4)设置阿里镜像仓库生效
5)设置docker仓库
上面的端口号是后面docker上传镜像用的比较重要,记住它
docker设置代理,如上图。
创建docker-group,将上面的代理和hosted配置到group中。docker的地址可以从这个地址获取:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
maven配置nexus
下面是我的maven中setting.xml的配置信息,仅供参考
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\depends\rep</localRepository>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>upload</id>
<username>admin</username>
<password>wsh123456</password>
</server>
<server>
<id>public</id>
<username>admin</username>
<password>wsh123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>public</id>
<mirrorOf>*</mirrorOf>
<name>Public Respositories</name>
<url>http://192.168.0.102:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>
idea,maven依赖上述setting.xml文件即可。
在pom文件中添加以下代码
<distributionManagement>
<repository>
<id>public</id>
<name>Nexus Release</name>
<url>http://192.168.0.102:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>upload</id>
<name>Nexus Snapshot</name>
<url>http://192.168.0.102:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
上面的url地址,对应nexus着snapshot和release地址,上面的id要与settings.xml中的id对应
===================================================
安装docker和k8s
参考文章:https://www.jianshu.com/p/63789d66e3a9
===================================================