首页 Jenkins教程Jenkins安装部署

部署web服务器环境

Jenkins基础配置

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

Jenkins部署与基础配置

官方网站:https://jenkins.io/zh/

Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建、测试和部署软件。

Jenkins 支持各种运行方式,可通过系统包、Docker 或者通过一个独立的 Java 程序

配置java环境并部署jenkins

安装jenkins
java环境配置

jenkins基于JAVA实现,安装jenkins前需要先安装 JDK

#安装openjdk
[root@ubuntu1804 ~]#apt update
[root@ubuntu1804 ~]#apt -y install openjdk-8-jdk
[root@ubuntu1804 ~]#java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

#或者安装oracle的jdk
root@jenkins:/usr/local/src# tar xvf jdk-8u192-linux-x64.tar.gz
root@jenkins:/usr/local/src# ln -sv /usr/local/src/jdk1.8.0_192/ /usr/local/jdk
root@jenkins:/usr/local/src# ln -sv /usr/local/jdk/bin/java /usr/bin/ #java命令软连接
root@jenkins:/usr/local/src# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=JAVA_HOME/bin:JAVA_HOME/jre/bin:PATH
export CLASSPATH=.CLASSPATH:JAVA_HOME/lib:JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
root@jenkins:/usr/local/src# source /etc/profile
root@jenkins:/usr/local/src# java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
安装jenkins
[root@ubuntu1804 ~]#wget https://pkg.jenkins.io/debian-stable/binary/jenkins_2.204.4_all.deb
[root@ubuntu1804 ~]#apt install daemon
[root@ubuntu1804 ~]#dpkg -i jenkins_2.204.4_all.deb
[root@ubuntu1804 ~]#systemctl status jenkins
● jenkins.service - LSB: Start Jenkins at boot time
   Loaded: loaded (/etc/init.d/jenkins; generated)
   Active: active (exited) since Thu 2020-03-05 15:41:27 CST; 34s ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 0 (limit: 2293)
   CGroup: /system.slice/jenkins.service

Mar 05 15:41:25 ubuntu1804.magedu.org systemd[1]: Starting LSB: Start Jenkins at boot time...
Mar 05 15:41:25 ubuntu1804.magedu.org jenkins[11662]: Correct java version found
Mar 05 15:41:25 ubuntu1804.magedu.org jenkins[11662]:  * Starting Jenkins Automation Server jenkins
Mar 05 15:41:25 ubuntu1804.magedu.org su[11693]: Successful su for jenkins by root
Mar 05 15:41:25 ubuntu1804.magedu.org su[11693]: + ??? root:jenkins
Mar 05 15:41:26 ubuntu1804.magedu.org su[11693]: pam_unix(su:session): session opened for user jenkins by (uid
Mar 05 15:41:26 ubuntu1804.magedu.org su[11693]: pam_unix(su:session): session closed for user jenkins
Mar 05 15:41:27 ubuntu1804.magedu.org jenkins[11662]:    ...done.
Mar 05 15:41:27 ubuntu1804.magedu.org systemd[1]: Started LSB: Start Jenkins at boot time.

[root@ubuntu1804 ~]#ps aux|grep jenkins
jenkins   11694  0.0  0.3  76620  7532 ?        Ss   15:41   0:00 /lib/systemd/systemd --user
jenkins   11695  0.0  0.1 111980  2676 ?        S    15:41   0:00 (sd-pam)
jenkins   11708  0.0  0.0  20388   184 ?        S    15:41   0:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
jenkins   11709 28.2 11.4 2561460 231920 ?      Sl   15:41   0:31 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
root      12465  0.0  0.0  14428  1156 pts/0    S+   15:43   0:00 grep --color=auto jenkins

[root@ubuntu1804 ~]#ss -ntlp |grep java
LISTEN   0         50                        *:8080                   *:*        users:(("java",pid=11709,fd=164))

#查看日志
[root@jenkins-ubunutu1804 ~]#cat /var/log/jenkins/jenkins.log
修改jenkins 服务的用户

默认jenkins服务使用jenkins 帐号启动,将文件复制到生产服务器可能会遇到权限问题,因此修改为root用户

[root@jenkins-ubunutu1804 ~]#vim /etc/default/jenkins
JENKINS_USER=root
JENKINS_GROUP=root

[root@jenkins-ubunutu1804 ~]#systemctl restart jenkins
[root@jenkins-ubunutu1804 ~]#ps aux|grep jenkins
root     121354  0.0  0.0  20388   188 ?        S    18:22   0:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
root     121355  3.2 20.0 3090932 403664 ?      Sl   18:22   0:29 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
root     126740  0.0  0.0  14428  1040 pts/1    S+   18:37   0:00 grep --color=auto jenkins
启动Jenkins
通过jar包直接启动jenkins
# java \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=12345 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname="10.0.0.101 " \
-jar jenkins-2.138.3.war &
rpm包安装jenkins配置
[root@s1 ~]# grep -v "#" /etc/sysconfig/jenkins | grep -v "^$"
JENKINS_HOME="/var/lib/jenkins"
JENKINS_JAVA_CMD=""
JENKINS_USER="jenkins"
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=12345 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname="192.168.7.101" \"

JENKINS_PORT="8080"
JENKINS_LISTEN_ADDRESS=""
JENKINS_HTTPS_PORT=""
JENKINS_HTTPS_KEYSTORE=""
JENKINS_HTTPS_KEYSTORE_PASSWORD=""
JENKINS_HTTPS_LISTEN_ADDRESS=""
JENKINS_DEBUG_LEVEL="5"
JENKINS_ENABLE_ACCESS_LOG="no"
JENKINS_HANDLER_MAX="100"
JENKINS_HANDLER_IDLE="20"
JENKINS_ARGS=""

#可选启动参数:
JENKINS_JAVA_OPTIONS="-server -Xms1g -Xmx1g -Xss512k -Xmn1g
-XX:CMSInitiatingOccupancyFraction=65
-XX:+UseFastAccessorMethods
-XX:+AggressiveOpts -XX:+UseBiasedLocking
-XX:+DisableExplicitGC -XX:MaxTenuringThreshold=10
-XX:NewSize=2048M -XX:MaxNewSize=2048M -XX:NewRatio=2
-XX:PermSize=128m -XX:MaxPermSize=512m -XX:CMSFullGCsBeforeCompaction=5
-XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
-XX:+CMSParallelRemarkEnabled -Djava.awt.headless=true
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname="192.168.7.104" "
Jenkins 启动过程

Jenkins安装部署插图

访问jenkins 页面

用浏览器访问:http://10.0.0.101:8080/

Jenkins安装部署插图(1)

[root@ubuntu1804 ~]#cat /var/lib/jenkins/secrets/initialAdminPassword
7d19df2dd74b48a9a48e9534456d0c92

输入文件中的密码:

Jenkins安装部署插图(2)

本文链接:http://www.yunweipai.com/35719.html

部署web服务器环境

Jenkins基础配置

网友评论comments

发表评论

电子邮件地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部