jenkins+nexus+gitlab+docker+k8s配置项目

一、环境配置和准备工作

机器:
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/

jenkins安装

或者你直接选择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
Jenkins启动界面

点击继续
选择安装自定义插件


自定义插件

可能存在有些插件安装不了的情况,点击重试安装,再安装不了,可以不用管。因为有些插件暂时用不到。


安装插件

创建用户

配置第一个实例
实例

安装完成
Jenkins安装完成
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/


nexus
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


设置network

expand

勾选保存

2)配置Jenkins
登录Jenkins,创建一个项目,选择自由风格项目


创建项目

3)在gitlab上建立一个项目
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配置

将上述ssh密钥拷贝到gitlab项目中
4)配置Jenkins的git地址(需要服务器安装git)


git地址

5)配置Jenkins插件Gitlab Hook


webhook地址

设置secret token
token

6)将上述信息配置到gitlab中
webhook
设置webhook信息

测试webhook


webhook测试

出现200说明配置成功。同时Jenkins也会触发动作


Jenkins触发器

===============================================================================

设置maven+docker私有仓库地址为nexus

1)第一次登录nexus

登录nexus

2)根据提示找到初始密码,登录之后修改密码
update password

创建仓库

3)选择maven2(proxy)设置阿里云镜像仓库
image.png

设置地址和名称

阿里仓库地址:http://maven.aliyun.com/nexus/content/groups/public/
4)设置阿里镜像仓库生效
阿里镜像仓库

添加

5)设置docker仓库
docker-hosted

设置名称和端口号

上面的端口号是后面docker上传镜像用的比较重要,记住它
docker代理

docker设置代理,如上图。
创建docker-group,将上面的代理和hosted配置到group中。docker的地址可以从这个地址获取:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

配置hosted

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文件即可。


maven配置

在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对应

上传完成

查看nexus

===================================================

安装docker和k8s

参考文章:https://www.jianshu.com/p/63789d66e3a9

k8s集群

===================================================

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,290评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,399评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,021评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,034评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,412评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,651评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,902评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,605评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,339评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,586评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,076评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,400评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,060评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,851评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,685评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,595评论 2 270

推荐阅读更多精彩内容