jenkins-环境部署

1、安装前提

1.1、硬件配置需求

Minimum hardware requirements:
   256 MB of RAM
   1 GB of drive space (although 10 GB is a recommended minimum if running 
Jenkins as a Docker container)
Recommended hardware configuration for a small team:
   4 GB+ of RAM
   50 GB+ of drive space

1.2、软件配置需求

You will need to pre-install a supported version of Java:
   2.164 (2019-02) and newer: Java 8 or Java 11
   2.54 (2017-04) and newer: Java 8
   1.612 (2015-05) and newer: Java 7

1.3、同步系统时间

# 设置时区
timedatectl set-timezone Asia/Shanghai

# 同步系统时间
apt install -y ntpdate cron
systemctl start cron
systemctl enable cron

cat << 'CAT_END' > /var/spool/cron/crontabs/root 
#ntp Server update
*/5 * * * * /usr/sbin/ntpdate ntp5.aliyun.com  2>&1 > /dev/null
#ntp end
CAT_END

ntpdate ntp5.aliyun.com

1.4、准备主机

ubuntu 内存:4G CPU:1核 

2、java环境部署 

2.1、创建目录、准备jdk安装包

mkdir /data/{softs,server} -p
cd /data/softs
curl -O https://download.java.net/openjdk/jdk11.0.0.1/ri/openjdk-11.0.0.1_linux-x64_bin.tar.gz

2.2、安装java

cd /data/softs
tar xf openjdk-11.0.0.1_linux-x64_bin.tar.gz -C /data/server/
ln -s /data/server/jdk-11.0.0.1 /usr/local/java

cat << 'CAT_END' >> /etc/profile
export JAVA_HOME=/usr/local/java
export LS_JAVA_HOME=/usr/share/logstash/jdk
export PATH=$JAVA_HOME/bin:$PATH
CAT_END
source /etc/profile
java -version

3、Jenkins安装

需要安装依赖包:apt install -y fontconfig

3.1、安装方式

3.1.1、仓库安装

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

参考官方安装方法:https://www.jenkins.io/doc/book/installing/linux/

3.1.2、 Docker安装

docker pull docker:dind 
docker network create jenkins
docker run --name jenkins-docker --rm --detach --privileged --network jenkins \
 --network-alias docker --env DOCKER_TLS_CERTDIR=/certs \
 --volume jenkins-docker-certs:/certs/client --volume jenkinsdata:/var/jenkins_home \
 --publish 2376:2376 docker:dind --storage-driver overlay2

参考官方安装方法:https://www.jenkins.io/doc/book/installing/docker/

3.1.3、war安装【这里使用此方法】

cd /data/softs 
wget https://get.jenkins.io/war/2.375/jenkins.war

3.2、避免报错提前处理

3.2.1、javax.net.ssl.SSLException: No PSK available. Unable to resume.处理

java  -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -jar jenkins.war

# 启动的时候增加如下参数:-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2

3.2.2、No such plugin: cloudbees-folder

# 解决方法:
下载插件:https://updates.jenkins-ci.org/download/plugins/cloudbees-folder/

# 注意要与jenkins版本一致,否则会报错

# 替换:
打开war,将下载的插件放入:jenkins.war\WEB-INF\detached-plugins

3.3、systemd的配置

3.3.1、jenkins.service脚本

# 准备软件启动文件
mkdir /data/server/jenkins && cp /data/softs/jenkins.war /data/server/jenkins/

# 服务脚本
cat << 'CAD_END' > /lib/systemd/system/jenkins.service
[Unit]
Description= jenkins server project
[Service]
User=root
ExecStart=/usr/local/java/bin/java -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -Djsse.enableSNIExtension=true -jar /data/server/jenkins/jenkins.war &
ExecStop=/bin/kill -TERM ${MAINPID}
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
CAD_END

3.3.2、启动服务

systemctl daemon-reload
systemctl start jenkins
systemctl enable jenkins

3.3.3、检查端口

# ss -tunlp | grep java
tcp   LISTEN 0      50                 *:8080            *:*    users:(("java",pid=9783,fd=8))

3.3.4、启动日志查看

# journalctl -exu jenkins

3.4、访问jenkins web

3.4.1、访问主页

# 查看密码
# cat /root/.jenkins/secrets/initialAdminPassword
7873421cec8644d9b98ff5a8f6456745

3.4.2、安装插件【安装推荐插件】

3.4.4、设置管理员帐号密码

3.4.5、配置jenkins访问地址

3.4.6、配置完成

3.4.7、访问主页面

 

posted @ 2023-06-14 12:23  小粉优化大师  阅读(188)  评论(0编辑  收藏  举报