Skip to content

img

一、安装

1.0 硬件需求

Minimum hardware

  • 256MB RAM
  • 1GB of disk space
  • 1GB + RAM
  • 50GB + disk space
  • 下载地址

https://jenkins.io/download/

采用war方式安装

1.1 war方式

安装jdk

bash
#下载jdk
wget wget https://repo.huaweicloud.com/java/jdk/11+28/jdk-11_linux-x64_bin.tar.gz

#解压
mkdir -p /data/apps
tar -zxvf jdk-11_linux-x64_bin.tar.gz -C /data/apps/

#配置环境变量
vim /etc/profile.d/jdk.sh
export JAVA_HOME=/data/apps/jdk-11
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

#是配置生效
source /etc/profile.d/jdk.sh

[root@Rocky ~]# java --version
java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Servr VM 18.9 (build 11+28, mixed mode)
#下载jdk
wget wget https://repo.huaweicloud.com/java/jdk/11+28/jdk-11_linux-x64_bin.tar.gz

#解压
mkdir -p /data/apps
tar -zxvf jdk-11_linux-x64_bin.tar.gz -C /data/apps/

#配置环境变量
vim /etc/profile.d/jdk.sh
export JAVA_HOME=/data/apps/jdk-11
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

#是配置生效
source /etc/profile.d/jdk.sh

[root@Rocky ~]# java --version
java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Servr VM 18.9 (build 11+28, mixed mode)

java -Dpermissive-script-security.enabled=true -DJENKINS_HOME=/data/apps/jenkins -jar -Dfile.encoding=UTF-8 -Xms520m -Xmx1024m /data/apps/jenkins/jenkins.war --httpPort=9191

内存根据自己机器的配置设置

bash
#!/bin/bash   
#auth xiong han
# chkconfig: - 85 14

export JENKINS_HOME=/opt/jenkins
JENKINS_HOME_APP=jenkins.war
JENKINS_PORT="9191"
JENKINS_LOG_PATH=/var/log/jenkins

JENKINS_PID=$(jps |grep jenkins |awk '{print $1}')

COMMAND=$1  

JENKINS_OPT="-Xms1024m -Xmx3060m"

[ $# -ne 1 ] && { echo "Usage: $0 <restart | start | stop |status >"; exit 1; }   

case $COMMAND in   
start )  
	if [ -n "${JENKINS_PID}" ];then
		 echo "Jenkins process is already running."
	else
		echo "Start the Jenkins server."
		nohup java -jar "-Dfile.encoding=UTF-8" $JENKINS_OPT ${JENKINS_HOME}/${JENKINS_HOME_APP} --httpPort=${JENKINS_PORT} > ${JENKINS_LOG_PATH}/jenkins.log 2>&1 &  

		ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  
		if [ $? -eq 0 ]
		then   
			echo "Start completed!"  
		else  
			echo "Process has not been started!"  
			exit 1   
		fi   
	fi
;;  

stop )  
    echo "Stop the Jenkins server."
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep | awk '{print $2}' | xargs kill -9  

    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  

    if [ $? -eq 0 ]
    then   
        echo "Process has not been killed!"  
        exit 1   
    else  
        echo "Stop completed!"  
    fi   
;;  

status )  
    echo "Show the Jenkins server status."  
    echo "Process is: "  
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  
    echo "PID is: "  
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep | awk '{print $2}'  
;;  

* )  
    echo "Usage: $0 < start | stop | status>"   
    exit 1   
;;   
esac
#!/bin/bash   
#auth xiong han
# chkconfig: - 85 14

export JENKINS_HOME=/opt/jenkins
JENKINS_HOME_APP=jenkins.war
JENKINS_PORT="9191"
JENKINS_LOG_PATH=/var/log/jenkins

JENKINS_PID=$(jps |grep jenkins |awk '{print $1}')

COMMAND=$1  

JENKINS_OPT="-Xms1024m -Xmx3060m"

[ $# -ne 1 ] && { echo "Usage: $0 <restart | start | stop |status >"; exit 1; }   

case $COMMAND in   
start )  
	if [ -n "${JENKINS_PID}" ];then
		 echo "Jenkins process is already running."
	else
		echo "Start the Jenkins server."
		nohup java -jar "-Dfile.encoding=UTF-8" $JENKINS_OPT ${JENKINS_HOME}/${JENKINS_HOME_APP} --httpPort=${JENKINS_PORT} > ${JENKINS_LOG_PATH}/jenkins.log 2>&1 &  

		ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  
		if [ $? -eq 0 ]
		then   
			echo "Start completed!"  
		else  
			echo "Process has not been started!"  
			exit 1   
		fi   
	fi
;;  

stop )  
    echo "Stop the Jenkins server."
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep | awk '{print $2}' | xargs kill -9  

    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  

    if [ $? -eq 0 ]
    then   
        echo "Process has not been killed!"  
        exit 1   
    else  
        echo "Stop completed!"  
    fi   
;;  

status )  
    echo "Show the Jenkins server status."  
    echo "Process is: "  
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep  
    echo "PID is: "  
    ps -ef | grep "$JENKINS_HOME/$JENKINS_HOME_APP" | grep -v grep | awk '{print $2}'  
;;  

* )  
    echo "Usage: $0 < start | stop | status>"   
    exit 1   
;;   
esac

1.2 docker方式

官方文档

bash
docker run --name jenkins --restart=always --network=host -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai  -v /var/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime -d jenkins
docker run --name jenkins --restart=always --network=host -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai  -v /var/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime -d jenkins

1.3 图形步骤

输入密码

image-20240622173451171

输入密码,根据提示查看密码

选择插件安装

image-20240622173554417

image-20240622173648054

创建管理员账户

image-20240622173752849

配置实例地址

image-20240622173824184

这个后面可以手动修改

开始使用

image-20240622173859650

image-20240622174219642

image-20240622173939214