1.1
war包部署
环境准备
// 其他系统类似
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
系统初始化
// 关闭防火墙
systemctl stop firewalld
systemctl enable firewalld
// 禁用selinux
vi /etc/selinux/config
SELINUX=disabled
或者通过命令修改
sed -i 's/enforcing/disabled/' /etc/selinux/config
版本说明
| 系统版本 |
Jenkins版本 |
JDK版本 |
备注 |
| RHEL7.4 |
Jenkins 2.440.2 |
Jdk-17.0.10 |
替换当前版本|2024-04-09 |
yum源配置
挂载本地yum源
// 将对应版本ISO文件存放在服务器目录
rhel-server-7.4-x86_64-dvd.iso
// 创建挂载点
# mkdir -p /mnt/cdrom
// 临时挂载
# mount -o loop /root/rhel-server-7.4-x86_64-dvd.iso /mnt/cdrom
mount: /dev/loop0 写保护,将以只读方式挂载
# tee /etc/yum.repos.d/local.repo << 'EOF'
[local]
name=Local Repository
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
EOF
# yum clean all
# yum makecache
配置网络yum源
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
# yum clean all
# yum makecache
JDK17安装|适配Jenkins 2.440.2
// 将jdk17解压
# tar xvf jdk-17.0.10_linux-x64_bin.tar.gz -C /opt
// 在用户家目录文件末尾添加配置JDK环境变量,这里以root用户为例
# cat cat /root/.bash_profile
export JAVA_HOME=/opt/jdk-17.0.10
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
// 生成jre
# cd jdk-17.0.10/
# ls
bin conf include jmods legal lib LICENSE man README release
# bin/jlink --module-path jmods --add-modules java.desktop --output jre
# source /root/.bash_profile
# java -version
java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)
jenkins启停脚本
# cat /usr/local/bin/jenkins.sh
#!/bin/bash
### Jenkins启停脚本
export JENKINS_PATH=/opt/jenkins.war
export JENKINS_PORT=8088
export JENKINS_LOG=/var/log/jenkins.log
export JENKINS_HOME=/data/jenkins/data/
pid=0
if [ "$1" = "start" ];then
if [ $pid -gt 0 ];then
echo 'jenkins is running...'
else
# 启动jenkins.war
nohup java -jar -Xms4096m -Xmx4096m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m ${JENKINS_PATH} --httpPort=${JENKINS_PORT} &> ${JENKINS_LOG} &
fi
elif [ "$1" = "stop" ];then
exec ps -ef | grep jenkins | grep -v grep | awk '{print $2}'| xargs kill -9
echo 'jenkins is stop..'
else
echo "Please input like this:"jenkins.sh start" or "jenkins stop""
fi
容器部署
cat Dockerfile
FROM jenkins/jenkins:2.426.1-jdk17
USER root
RUN apt-get update && apt-get install -y lsb-release
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"
k8s部署
说明
// 官方提供的github配置文件
https://github.com/scriptcamp/kubernetes-jenkins
# pwd
/root/jenkins/kubernetes-jenkins-main
tree
.
├── deployment.yaml //04po副本创建文件
├── namespace.yaml //01创建命名空间
├── README.md //00说明文档
├── serviceAccount.yaml //02创建角色权限
├── service.yaml //05创建service服务
└── volume.yaml //03创建sc&pv&pvc
0 directories, 6 files
配置
// volume.yaml
spec:
storageClassName: local-storage
claimRef:
name: jenkins-pv-claim
namespace: devops-tools
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
local:
path: /mnt
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- master //依据实际node情况,修改此处的值
# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: devops-tools
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-server
template:
metadata:
labels:
app: jenkins-server
spec:
securityContext:
fsGroup: 1000
runAsUser: 0 //修改此处,并进入pod添加域名解析
serviceAccountName: jenkins-admin
containers:
- name: jenkins
image: jenkins/jenkins:lts-jdk17 //修改此处对应当前lts最新版本
resources:
limits:
memory: "3Gi"
cpu: "2000m"
requests:
memory: "500Mi"
cpu: "500m"
ports:
- name: httpport
containerPort: 8080
- name: jnlpport
containerPort: 50000
livenessProbe:
httpGet:
path: "/login"
port: 8080
initialDelaySeconds: 90
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: "/login"
port: 8080
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- name: jenkins-data
mountPath: /var/jenkins_home
volumes:
- name: jenkins-data
persistentVolumeClaim:
claimName: jenkins-pv-claim
安装命令
# kubectl apply -f namespace.yaml
# kubectl apply -f serviceAccount.yaml
# kubectl apply -f volume.yaml
# kubectl apply -f deployment.yaml
# kubectl apply -f service.yaml
初始化安装日志
# kubectl logs jenkins-5bdc5bf9c6-lbxcn --namespace=devops-tools
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-03-15 06:13:19.193+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @2743ms to org.eclipse.jetty.util.log.JavaUtilLo
g2024-03-15 06:13:19.594+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2024-03-15 06:13:22.731+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2024-03-15 06:13:23.003+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecf
a3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.13+82024-03-15 06:13:24.309+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.Jetty
JspServlet2024-03-15 06:13:24.508+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2024-03-15 06:13:24.509+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2024-03-15 06:13:24.512+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2024-03-15 06:13:26.728+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.
get("JENKINS_HOME")2024-03-15 06:13:27.601+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@216914{Jenkins v2.319.1,/,file:///var/jenkins_home/war/,AVAIL
ABLE}{/var/jenkins_home/war}2024-03-15 06:13:27.793+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@72cf2de5{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-03-15 06:13:27.794+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @11349ms
2024-03-15 06:13:27.796+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2024-03-15 06:13:29.002+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2024-03-15 06:13:29.112+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/var/jenkins_home/war/WEB-INF/lib/guice-4.0.jar) to method jav
a.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2024-03-15 06:13:35.108+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2024-03-15 06:13:35.118+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2024-03-15 06:13:35.287+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2024-03-15 06:13:40.936+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2024-03-15 06:13:40.988+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-03-15 06:13:40.989+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-03-15 06:13:40.990+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-03-15 06:13:41.015+0000 [id=42] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2024-03-15 06:13:41.103+0000 [id=42] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2024-03-15 06:13:42.304+0000 [id=42] INFO hudson.util.Retrier#start: The attempt #1 to do the action check updates server failed with an allowed exception
:java.net.UnknownHostException: updates.jenkins.io
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:299)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:373)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:203)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:189)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1592)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
at hudson.model.DownloadService.loadJSON(DownloadService.java:117)
at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:219)
at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:214)
at hudson.PluginManager.checkUpdatesServer(PluginManager.java:1874)
at hudson.util.Retrier.start(Retrier.java:62)
at hudson.PluginManager.doCheckUpdatesServer(PluginManager.java:1845)
at jenkins.DailyCheck.execute(DailyCheck.java:92)
at hudson.model.AsyncPeriodicWork.lambda$doRun$1(AsyncPeriodicWork.java:102)
at java.base/java.lang.Thread.run(Thread.java:829)
2024-03-15 06:13:42.305+0000 [id=42] INFO hudson.util.Retrier#start: Calling the listener of the allowed exception 'updates.jenkins.io' at the attempt #1
to do the action check updates server2024-03-15 06:13:42.389+0000 [id=42] INFO hudson.util.Retrier#start: Attempted the action check updates server for 1 time(s) with no success
2024-03-15 06:13:42.393+0000 [id=42] SEVERE hudson.PluginManager#doCheckUpdatesServer: Error checking update sites for 1 attempt(s). Last exception was: Unk
nownHostException: updates.jenkins.io2024-03-15 06:13:42.399+0000 [id=42] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 1,382 ms
2024-03-15 06:13:43.812+0000 [id=28] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
c734c6734b2b43abae05fbfec1959464
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2024-03-15 06:13:43.816+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-03-15 06:13:43.900+0000 [id=22] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running