1.初始化Jenkins安装环境
系统版本:Red Hat Enterprise Linux 8.7
将脚本文件jenkins_install_env.sh 、 jenkins_install.sh和apache-maven-3.6.2-bin.tar.gz、jdk-8u251-linux-x64.tar.gz都上传到/usr/local/src目录下
执行jenkins_install_env.sh脚本初始化Jenkins安装环境
source jenkins_install_env.sh
脚本内容如下:
#!/bin/bash
if [ -z $1 ]
then echo '$1 is not exists or is empty'
exit
fi
echo "[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/rockylinux/8/BaseOS/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/rockylinux/8/AppStream/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/rockylinux/8/PowerTools/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[Extras]
name=Extras
baseurl=https://mirrors.aliyun.com/rockylinux/8/extras/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
" > /etc/yum.repos.d/online.repo
echo vers:$1
sed -i "s/8/$1/g" /etc/yum.repos.d/online.repo
dnf install -y vim
cd /usr/local/src/
tar -zxvf apache-maven-3.6.2-bin.tar.gz
tar -zxvf jdk-8u251-linux-x64.tar.gz
echo "export MAVEN_HOME=/usr/local/src/apache-maven-3.6.2" >> /etc/profile
echo "export JAVA_HOME=/usr/local/src/jdk1.8.0_251" >> /etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin:\$JAVA_HOME/bin" >> /etc/profile
source /etc/profile
systemctl stop firewalld && systemctl disable firewalld
执行完脚本,使用命令mvn -v查看初始化jdk和maven环境效果,如下表示成功!
编辑maven的settings.xml文件
vim apache-maven-3.6.2/conf/settings.xml
在mirrors标签内添加如下内容
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>nexus-163</id>
<mirrorOf>*</mirrorOf>
<name>Nexus 163</name>
<url>http://mirrors.163.com/maven/repository/maven-public/</url>
</mirror>
2. 安装jenkins
方法一
将下载好的jenkins的war包和apache-tomcat-8.0.45.tar.gz上传到/usr/local/src/目录下
执行jenkins_install.sh脚本安装jenkins(这种方法是下载Jenkins的war包运行在tomcat里面)
source jenkins_install.sh
脚本内容如下:
#!/bin/bash
cd /usr/local/src
tar -zxvf apache-tomcat-8.0.45.tar.gz
mv jenkins.war /usr/local/src/apache-tomcat-8.0.45/webapps/
cd apache-tomcat-8.0.45/bin
sh startup.sh && tail -f /usr/local/src/apache-tomcat-8.0.45/logs/catalina.out
访问地址:192.168.225.13:8080/jenkins
接下来选择安装推荐插件,这里需要耐心稍等一会儿
方法二
这种方式是通过yum安装源来安装jenkins的,Jenkins安装后是作为服务启动的
添加jenkins 资源库
dnf install -y wget
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo dnf install -y fontconfig java-11-openjdk
yum源安装看情况,有时候下载比较慢,和网速也有关系,所以一般能用方法一安装就行了,方法二太依赖yum源和网速
sudo dnf install -y jenkins-2.346.1
sudo systemctl daemon-reload
查看admin用户密码
cat /var/lib/jenkins/secrets/initialAdminPassword
如果上面下载速度太慢,可以在阿里云上下载(速度较快),下载地址:https://mirrors.aliyun.com/jenkins/redhat-stable/,下载后上传到/usr/local/src目录下
执行 rpm -ivh jenkins-2.346.1-1.1.noarch.rpm 命令安装
开机启动
systemctl enable jenkins
启动
systemctl start jenkins
查询运行状态
systemctl status jenkins
停止
systemctl stop jenkins
重启
systemctl restart jenkins
先查看下状态,再启动jenkins服务并且设置位开机启动,初次启动有点慢是正常的,耐心稍等片刻。。。差不多5-10分钟左右
再次查看服务已经起来了
现在访问:192.168.255.13:8080
后面就和war包安装的jenkin差不多了
这个地方有点不一样