最近重新安装了下操作系统和虚拟机,需要在Linux centos7安装Jenkins,记录下安装过程。
Linux版本:CentOS7 64位
Jenkins:jenkins-2.227-1.1.noarch.rpm
JDK版本:jdk-8u161-linux-x64.tar.gz
具体安装步骤:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
版本:jdk-8u161-linux-x64.tar.gz
2.1、创建Folder:mkdir devTools
2.2、解压缩JDK:
tar -zxvf jdk-8u161-linux-x64.tar.gz -C /home/helen/devTools
-->解压缩文件在:jdk1.8.0_161文件夹中
3.1、(在当前非root用户下的.bashrc里配置)
vim /home/elsa/.bashrc
在.bashrc文件末尾追加如下
export JAVA_HOME=/home/helen/devTools/jdk1.8.0_161
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
备注:修改完需要保存,点击Esc,:wq保存退出; :q不保存退出
3.2、执行命令使配置生效
source /home/helen/.bashrc
javac
java -version
------------------------------
[helen@linuxprobe devTools]$ java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
jenkins官网下载地址:Redhat Jenkins Packages
可以用以下方法安装:
To use this repository, run the following command:
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 yum install -y jenkins
>>wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
如果是非root用户,需要加上sudo
[helen@linuxprobe ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo [sudo] password for helen: --2020-03-25 10:57:38-- https://pkg.jenkins.io/redhat/jenkins.repo Resolving pkg.jenkins.io (pkg.jenkins.io)... 52.202.51.185 Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 71 Saving to: ‘/etc/yum.repos.d/jenkins.repo’ 100%[=================================================================>] 71 --.-K/s in 0s 2020-03-25 10:57:43 (8.87 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [71/71] |
[helen@linuxprobe ~]$ cat /etc/yum.repos.d/jenkins.repo [jenkins] name=Jenkins baseurl=http://pkg.jenkins.io/redhat gpgcheck=1 |
解释下参数含义:
[cd_repo] #仓库名称
name #仓库描述
baseurl #仓库位置的URL(这是本地的仓库)
gpgcheck #是否检查证书
enabled #是否启用此仓库
如果是非root用户,需要加上sudo
[helen@linuxprobe ~]$ sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key |
(一般情况下,这样就安装成功了)
Error downloading packages:
jenkins-2.227-1.1.noarch: [Errno 256] No more mirrors to try.
--->发现安装失败。可以从Redhat Jenkins Packages 下载下来安装了。
然后linux使用命令:rz “选择文件”,上传到linux centos7上面
[helen@linuxprobe Jenkins]$ su root Password: [root@linuxprobe Jenkins]# rpm -ivh jenkins-2.227-1.1.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:jenkins-2.227-1.1 ################################# [100%] |
配置文件("端口","JENKINS_HOME"等都可以在这里配置) /etc/sysconfig/jenkins 默认的JENKINS_HOME目录 /var/lib/jenkins/ Jenkins日志文件 /var/log/jenkins/jenkins.log WAR包 /usr/lib/jenkins/jenkins.war |
默认端口8080(如端口已其他占用,需修改端口)
[root@linuxprobe Jenkins]# vim /etc/sysconfig/jenkins
找到 JENKINS_PORT="8080" 修改端口号,按Esc,点击i,修改端口号后:wq保存。
5.1启动:
[root@linuxprobe Jenkins]# systemctl start jenkins
5.2 查看jenkins执行日志:
[root@linuxprobe Jenkins]# tail -n 300 -f /var/log/jenkins/jenkins.log
5.3 启动成功,可以访问:http://localhost:8088
[root@linuxprobe jenkins]# firewall-cmd --zone=public --add-port=8088/tcp --permanent
success
[root@linuxprobe jenkins]# firewall-cmd --reload
Success
非本机访问:
cat /var/lib/jenkins/secrets/initialAdminPassword
[root@linuxprobe helen]# cat /var/lib/jenkins/secrets/initialAdminPassword 6771df5cc53a42b78cb2ca0ec7cd6431 |
/var/lib/jenkins/secrets/initialAdminPassword
启动服务 |
service jenkins start 或者:systemctl start jenkins |
重启服务 |
service jenkins restart 或者:systemctl restart jenkins |
停止服务 |
service jenkins stop 或者:systemctl stop jenkins |
# 查看状态 |
systemctl status jenkins.service |
Web页面关闭Jenkies |
http://localhost:8088/exit |
Web页面重启Jenkies |
http://localhost:8088/restart |
参考:https://www.jb51.net/article/171226.htm