码迷,mamicode.com
首页 > 其他好文 > 详细

Jenkins Server的安装部署方式

时间:2020-07-22 15:45:59      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:基础   include   clu   生成   pass   Kubernete   mirrors   其他   停止   

技术图片


 

第2章 Jenkins Server的安装部署方式

  • 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部署。部署后的基础配置。


1.1 安装依赖

Jenkins是基于Java开发的一种持续集成工具,可以在安装Java Runtime Environment的任何机器独立运行。部署前需要安装Java开发环境。要求是JDK8+,目前已经支持JDK11。关于JDK的安装可以通过yum或者源码包方式。

技术图片

 

rpm方式

rpm -ivh jdk-xxxxx.rpmyum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

源码包方式

tar zxf jdk-xxxx.tar.gz -www.zhuyngyule.cn C /usr/localvim /etc/profile
export JAVA_HOME=/usr/local/jdkxxxexport PATH=$PATH:$JAVA_HOME/bin
source /etc/profile

1.2 安装部署

1.2.1 使用Tomcat部署

如果使用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.gztar 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

1.2.2 CentOS环境部署

普遍在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 jenkinssystemctl enable jenkins

1.2.3 MacOS环境部署

在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==> CaveatsFor 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==> CaveatsNote: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login: brew services start jenkins-ltsOr, 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@11For 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-ltsNote: When using launchctl the port will be 8080.
To have launchd start jenkins-lts now and restart at login: brew services start jenkins-ltsOr, 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

1.2.4 基于Docker部署

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

1.2.5 基于Kubernetes部署

首先创建一个namespace jenkins ,然后通过kubectl create -f jenkins.yml部署。

这是一个完整的Deployment文件。

kind: DeploymentapiVersion: apps/v1metadata:  labels:    k8s-app: jenkins  name: jenkins  namespace: devopsspec:  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: v1kind: ServiceAccountmetadata:  labels:    k8s-app: jenkins  name: jenkins  namespace: devops---kind: ServiceapiVersion: v1metadata:  labels:    k8s-app: jenkins  name: jenkins  namespace: devopsspec:  type: NodePort  ports:    - name: web      port: 30080      targetPort: 30080      nodePort: 30080    - name: slave      port: 30081      targetPort: 30081      nodePort: 30081  selector:    k8s-app: jenkins---kind: RoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: jenkins namespace: devopsrules: - 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/v1beta1kind: RoleBindingmetadata: name: jenkins namespace: devopsroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: jenkinssubjects: - kind: ServiceAccount   name: jenkins   namespace: devops

jenkins端口可以自定义,这里使用的是30080端口和30081端口。持久化的目录采用的是hostpath方式,这种方式仅能适合本地测试。建议如果生产还是采用共享存储pvc来持久化。否则节点漂移到其他节点会出现数据丢失。

1.2.6 基于Windows部署

下载软件包通过向导安装即可。windows这里基本上很少用的了。

1.2.7 软件资源下载

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/


1.3 配置

解锁:当您第一次访问Jenkins的时候,系统会要求您使用自动生成的密码对其进行解锁。解锁秘钥可以通过$JENKINS_HOME/secrets/initialAdminPassword文件获取。还可以通过在启动日志中获取。

Jenkins Server的安装部署方式

标签:基础   include   clu   生成   pass   Kubernete   mirrors   其他   停止   

原文地址:https://www.cnblogs.com/woshixiaowang/p/13359864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!