1.下载Jenkins war包
或者
wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
2.启动war包
命令启动:
# java –jar Jenkins.war --httpPort=9000
httpPort表示配置指定Jenkins端口,由于Jenkins默认端口是8080,通常8080端口可能会有占用情况,所以换成自己定义的端口9000
脚本启动:
创建jenkins.sh脚本文件,并复制以下脚本
#!/bin/bash
JAVA_OPTIONS="-server -Xmx256m -Xms256m"
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=9000 > "${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 esmart-test.jar \033[0m"
esac
对jenkins.sh文件增加执行权限
# chmod u+x jenkins.sh
启动Jenkins
# ./jenkins.sh start jenkins.war
停止Jenkins
# ./jenkins.sh stop jenkins.war
重启Jenkins
# ./jenkins.sh restart jenkins.war
查看Jenkins状态
# ./jenkins.sh status jenkins.war
原文来自于:https://blog.csdn.net/chenweijiSun/article/details/104536813