使用yum安装jenkins。centos7系统 java11环境
1,安装java11环境
[root@four-4 app]# pwd
/app
[root@four-4 app]# ls
jdk11.tar.gz
# 脚本安装
function Install_Java(){
cd $dir
tar -zxf $dir/jdk11.tar.gz -C /usr/local/
mv -f /usr/local/jdk-11.0.2 /usr/local/java11 >/dev/null 2>&1
echo "export JAVA_HOME=/usr/local/java11" >> ~/.bashrc
echo "export CLASSPATH=/usr/java/java11/lib" >> ~/.bashrc
echo "export PATH=\$JAVA_HOME/bin:\$PATH:\$HOME/bin" >> ~/.bashrc
source ~/.bashrc
}
dir="/app"
Install_Java
# 如果安装后还是无法执行which命令查看java路径,可以执行source ~/.bashrc
2,下载jenkins
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo --no-check-certificate
rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
[root@four-4 ~]# cat /etc/yum.repos.d/jenkins.repo
[jenkins]
name=Jenkins
baseurl=http://pkg.jenkins.io/redhat
gpgcheck=0 #修改为0不进行检测
yum install jenkins -y #安装
3修改jenkins中的java路径
vim /usr/lib/systemd/system/jenkins.service
# The Java executable. When left empty, JAVA_HOME and PATH are consulted.
Environment="JENKINS_JAVA_CMD=/usr/local/java11/bin/java" #取消这一行的注释,并且将java路径写入
systemctl daemon-reload
4重启并访问jenkins