Linux离线安装jenkins

环境:一台完全离线的linux服务器,部署jenkins

请自行安装jdk环境
下载地址
链接:https://pan.baidu.com/s/1iyG_rVVCdPBXo2E7RO_Jew
提取码:ct4y
参考链接https://www.cnblogs.com/xing1/p/15181289.html
参考地址https://blog.csdn.net/weixin_43184774/article/details/104428244
将jenkins.war包传到服务器
安装参考文档进行操作
jenkins.sh脚本

#!/bin/bash
VA_OPTIONS="-server -Xmx2048m -Xms1024m"
Jenkins=$2
this_dir="$( cd "$( dirname "$0"  )" && pwd )"
log_file="${this_dir}/catalina.out"
jar_file="${this_dir}/${Jenkins}"

if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$Jenkins" = "" ];
then
    echo -e "\033[0;31m 未输入应用名 \033[0m"
    exit 1
fi

function start()
{
    count=`ps -ef |grep java|grep $Jenkins|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$Jenkins is running..."
    else
        nohup java $JAVA_OPTIONS -jar  ${jar_file}  --httpPort=8088 > "${log_file}" 2>&1 &
		echo -e "Start $Jenkins success...Please see the detail log in /logs/catalina.out"
    fi
}

function stop()
{
    echo "Stop $Jenkins"
    boot_id=`ps -ef |grep java|grep $Jenkins|grep -v grep|awk '{print $2}'`
    count=`ps -ef |grep java|grep $Jenkins|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ef |grep java|grep $Jenkins|grep -v grep|wc -l`

        boot_id=`ps -ef |grep java|grep $Jenkins|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
    fi
}

function restart()
{
    stop
    sleep 2
    start
}

function status()
{
    count=`ps -ef |grep java|grep $Jenkins|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$Jenkins is running..."
    else
        echo "$Jenkins is not running..."
    fi
}

case $1 in
    start)
    start;;
    stop)
    stop;;
    restart)
    restart;;
    status)
    status;;
    *)

    echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {JenkinsJarName} \033[0m\033[0;31m Example: \033[0m\033[0;33m sh  $0  start jenkins.war \03[0m"
esac

可能遇到的问题

1.没有.sh的执行权限 ,进行授权

chmod 777 jenkins.sh

设置为开机自启动

配置开机启动服务,到 /lib/systemd/system 服务注册目录下创建 jenkins.service
touch jenkins.service
文件内容如下:
[Unit]
Description=Jenkins
After=network.target

[Service]
Type=forking
### jenkins.sh的路径
ExecStart=/home/soft/jenkins/jenkins.sh start jenkins.war
ExecReload=/home/soft/jenkins/jenkins.sh restart jenkins.war
ExecStop=/home/soft/jenkins/jenkins.sh stop jenkins.war
PrivateTmp=true

[Install]
WantedBy=multi-user.target

创建好服务后,执行一下命令刷新配置
systemctl daemon-reload

  启动脚本
systemctl start jenkins.service

查看启动脚本状态是否启用成功(失败的话,看错误日志进行修改)
systemctl status jenkins.service

设置开机启动
systemctl enable jenkins.service

查看设置开机启动的服务列表
systemctl list-units --type=service

可能遇到的问题 Jenkins做成服务遇到的问题
Linux离线安装jenkins_第1张图片
Jenkins.sh 脚本上方增加
#!/bin/bash

你可能感兴趣的:(项目部署,jenkins,linux,运维)