标签:基础 include clu 生成 pass Kubernete mirrors 其他 停止
1.1 安装依赖
1.2 安装部署
1.2.1 使用Tomcat部署
1.2.2 CentOS环境部署
1.2.3 MacOS环境部署
1.2.4 基于Docker部署
1.2.5 基于Kubernetes部署
1.2.6 基于Windows部署
1.2.7 软件资源下载
1.3 配置
本章阐述Jenkins Server的安装部署方式。基于Tomcat、CentOS、MacOS、Docker、Kubernetes、Windows部署。部署后的基础配置。
Jenkins是基于Java开发的一种持续集成工具,可以在安装Java Runtime Environment的任何机器独立运行。部署前需要安装Java开发环境。要求是JDK8+,目前已经支持JDK11。关于JDK的安装可以通过yum或者源码包方式。
rpm方式
rpm -ivh jdk-xxxxx.rpm
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
源码包方式
tar zxf jdk-xxxx.tar.gz -www.zhuyngyule.cn C /usr/local
vim /etc/profile
export JAVA_HOME=/usr/local/jdkxxx
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
如果使用war包部署建议采用tomcat,当然Jenkins的war包可以直接通过java -jar jenkins.war
启动。我们可以部署一个tomcat服务然后将jenkins.war包放到tomcat的webapps目录下。最后通过浏览器http://tomcatserver/jenkins
访问。
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz
tar xf apache-tomcat-9.0.24.tar.gz -C /usr/local/
cp jenkins.war apache-tomcat-9.0.24/webapps/
# 启动
/usr/local/tomcat/bin/catalina.sh start
# 停止
/usr/local/tomcat/bin/shutdown.sh
普遍在centos系统部署Jenkins,可以下载jenkins的最新rpm包部署。
wget https://www.gaodeyulept.cn mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.235.2-1.1.noarch.rpm
rpm -ivh jenkins-2.235.2-1.www.javachenglei.com.noarch.rpm
systemctl start jenkins
systemctl enable jenkins
在Mac OS X机器上安装Jenkins CI服务器,可以手动下载pkg包安装或者通过brew自动安装。
手动下载pkg包安装,根据向导进一步安装。
使用brew部署
brew install jenkins-lts
######################################################################## 100.0%
==> Downloading http://mirrors.jenkins.io/war-stable/2.235.2/jenkins.war
==> Downloading from http://mirror.serverion.com/jenkins/war-stable/2.235.2/jenki
######################################################################## 100.0%
==> Installing dependencies for jenkins-lts: openjdk@11
==> Installing jenkins-lts dependency: openjdk@11
==> Pouring openjdk@11-11.0.7+10.high_sierra.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH run:
echo ‘export PATH="/usr/local/opt/openjdk@11/bin:$PATH"‘ >> /Users/zeyang/.bash_profile
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
==> Summary
?? /usr/local/Cellar/openjdk@11/11.0.7+10: 650 files, 295.7MB
==> Installing jenkins-lts
==> /usr/local/opt/openjdk@11/bin/jar xvf jenkins.war
==> Caveats
Note: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login:
brew services start jenkins-lts
Or, if you don‘t want/need a background service you can just run:
jenkins-lts
==> Summary
?? /usr/local/Cellar/jenkins-lts/2.235.2: 7 files, 66.4MB, built in 11 seconds
==> Caveats
==> openjdk@11
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH run:
echo ‘export PATH="/usr/local/opt/openjdk@11/bin:$PATH"‘ >> /Users/zeyang/.bash_profile
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
==> jenkins-lts
Note: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login:
brew services start jenkins-lts
Or, if you don‘t want/need a background service you can just run:
jenkins-lts
# Start.
brew services start jenkins-lts
# Stop.
brew services stop jenkins-lts
docker pull jenkins/jenkins:lts
docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
## 参数解释
-d 后台运行
-v 持久化jenkins数据目录
-p 端口绑定 server:8080 agent:50000
首先创建一个namespace jenkins
,然后通过kubectl create -f jenkins.yml
部署。
这是一个完整的Deployment文件。
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
k8s-app: jenkins
name: jenkins
namespace: devops
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: jenkins
template:
metadata:
labels:
k8s-app: jenkins
namespace: devops
name: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:2.211
imagePullPolicy: IfNotPresent
ports:
- containerPort: 30080
name: web
protocol: TCP
- containerPort: 30081
name: agent
protocol: TCP
resources:
limits:
cpu: 1000m
memory: 2Gi
requests:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /login
port: 30080
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
readinessProbe:
httpGet:
path: /login
port: 30080
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
volumeMounts:
- name: jenkins-home
mountPath: /var/lib/jenkins
env:
- name: JENKINS_HOME
value: /var/lib/jenkins
- name: JENKINS_OPTS
value: --httpPort=30080
- name: JENKINS_SLAVE_AGENT_PORT
value: "30081"
volumes:
- name: jenkins-home
hostPath:
path: /data/devops/jenkins
type: Directory
serviceAccountName: jenkins
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: jenkins
name: jenkins
namespace: devops
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: jenkins
name: jenkins
namespace: devops
spec:
type: NodePort
ports:
- name: web
port: 30080
targetPort: 30080
nodePort: 30080
- name: slave
port: 30081
targetPort: 30081
nodePort: 30081
selector:
k8s-app: jenkins
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: jenkins
namespace: devops
rules:
- apiGroups: [""]
resources: ["pods","configmaps","namespaces"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: jenkins
namespace: devops
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: jenkins
subjects:
- kind: ServiceAccount
name: jenkins
namespace: devops
jenkins端口可以自定义,这里使用的是30080端口和30081端口。持久化的目录采用的是hostpath方式,这种方式仅能适合本地测试。建议如果生产还是采用共享存储pvc来持久化。否则节点漂移到其他节点会出现数据丢失。
下载软件包通过向导安装即可。windows这里基本上很少用的了。
JDK下载链接:https://www.tengyao3zc.cn /java/technologies/javase/javase-jdk8-downloads.html
Mac pkg软件包下载:https://www.javachenglei.com .edu.cn/jenkins/osx-stable/
Jenkins war包下载链接:https://www.jintianxuesha.com .edu.cn/jenkins/war-stable/
Jenkins rpm包下载链接:https://www.wanfeigw.cn mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
Jenkins Docker hub:https://www.yuanyangyul.com hub.docker.com/r/jenkins/jenkins
k8s yaml:https://www.xincheng0001.cn github.com/zeyangli/devops-on-k8s/blob/master/devops/jenkins.yaml
windows 下载:https://www.letianhuanchao.cn mirrors.tuna.tsinghua.edu.cn/jenkins/windows-stable/
解锁:当您第一次访问Jenkins的时候,系统会要求您使用自动生成的密码对其进行解锁。解锁秘钥可以通过$JENKINS_HOME/secrets/initialAdminPassword文件获取。还可以通过在启动日志中获取。
标签:基础 include clu 生成 pass Kubernete mirrors 其他 停止
原文地址:https://www.cnblogs.com/woshixiaowang/p/13359864.html