本章闡述Jenkins Server的安裝部署方式。基於Tomcat、CentOS、MacOS、Docker、Kubernetes、Windows部署。 部署後的基礎配置。html
Jenkins是基於Java開發的一種持續集成工具,能夠在安裝Java Runtime Environment的任何機器獨立運行。部署前須要安裝Java開發環境。要求是JDK8+,目前已經支持JDK11。關於JDK的安裝能夠經過yum或者源碼包方式。java
rpm方式node
rpm -ivh jdk-xxxxx.rpm yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
源碼包方式linux
tar zxf jdk-xxxx.tar.gz -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
訪問。git
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包部署。github
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.235.2-1.1.noarch.rpm rpm -ivh jenkins-2.235.2-1.1.noarch.rpm systemctl start jenkins systemctl enable jenkins
在Mac OS X機器上安裝Jenkins CI服務器,能夠手動下載pkg包安裝或者經過brew自動安裝。web
手動下載pkg包安裝,根據嚮導進一步安裝。docker
使用brew部署apache
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" # 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
部署。json
這是一個完整的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.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
Mac pkg軟件包下載:https://mirrors.tuna.tsinghua.edu.cn/jenkins/osx-stable/
Jenkins war包下載連接:https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/
Jenkins rpm包下載連接:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
Jenkins Docker hub:https://hub.docker.com/r/jenkins/jenkins
k8s yaml:https://github.com/zeyangli/devops-on-k8s/blob/master/devops/jenkins.yaml
windows 下載:https://mirrors.tuna.tsinghua.edu.cn/jenkins/windows-stable/
解鎖:當您第一次訪問Jenkins的時候,系統會要求您使用自動生成的密碼對其進行解鎖。解鎖祕鑰能夠經過$JENKINS_HOME/secrets/initialAdminPassword文件獲取。還能夠經過在啓動日誌中獲取。
安裝插件:分別是安裝默認的插件和自定義選擇要安裝的插件,推薦仍是使用默認的插件安裝。
建立用戶:在這裏建立一個管理員帳號,到此jenkins的初始化配置已完成。
配置更新站點:因爲使用官方的站點速度相對很慢,這裏採用清華大學的jenkins更新站點。
這塊常常出現問題:當改完後其實仍是很慢,由於清華源代理的json文件的內容中仍是指向的外網地址。推薦幾種方法:
方法1: 使用jenkins中文社區的插件源。安裝中文社區插件(插件搜索關鍵字chinese),而後點擊頁面最下方超連接。最後會有提示使用插件源。
方法2: 配置代理域名轉發
location /download { proxy_pass http://mirrors.tuna.tsinghua.edu.cn/jenkins/; }
方法3:進入 jenkins 工做目錄,目錄下面有一個 updates 的目錄,下面有一個 default.json 文件,咱們執行下面的命令替換插件地址:替換完成後,須要重啓 Jenkins。
$ sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
咱們通常應用最多的應該是在linux或者docker中使用。 在linux環境中jenkins默認的配置文件在/etc/sysconfig/jenkins中,默認的啓動用戶爲jenkins,默認端口爲8080。 後期都是能夠基於配置文件進行修改的。
到此咱們就完成了,Jenkins server節點的安裝部署和基本的配置了。後期咱們來分享關於agent節點的部署。