jenkins 的安装

环境
java:1.7 1.8
jenkins:jenkins.noarch.0.2.155-1.1

前言
这次是两年后再次安装jenkins,安装到新机子上,新版本的jenkins需要java8的支持。
安装的用户是jenkins,且配置好了sudo权限。

也就是 先创建好jenkins用户

步骤
下载安装


1,sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
2,sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
3,sudo yum install jenkins


配置文件


启动命令的代码:
/etc/init.d/jenkins

如果通过配置文件修改了用户,那么必须修改/var/log/jenkins,/var/lib/jenkins和/var/cache/jenkins文件的所有者

如果要查看日志信息,在/var/log/jenkins/jenkins.log

启动时的配置信息:/etc/sysconfig/jenkins

 

修改(或者说添加)jdk路径


执行命令:sudo vim /etc/init.d/jenkins

# 我添加了/home/jenkins/jdk1.8.0_191/bin/java
candidates="
/home/jenkins/jdk1.8.0_191/bin/java
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
"
for candidate in $candidates
...

# jenkins老一点的版本修改的方式 也就是直接写在 in 后面
for candidate in /home/jenkins/jdk1.8.0_191/bin/java /usr/java/jdk1.7.0_51/bin/java /etc/alternatives/java /usr/lib/jvm/java-1.6.0/bin/java /usr/lib/jvm/jre-1.6.0/bin/java /usr/lib/jvm/java-1.5.0/bin/java /usr/lib/jvm/jre-1.5.0/bin/java /usr/bin/java
do
  [ -x "$JENKINS_JAVA_CMD" ] && break
  JENKINS_JAVA_CMD="$candidate"
done

我上面使用的是jdk1.8来启动的。

 

修改默认文件的路径


之所以要修改,是因为有时默认安装路径的文件夹分配的存储空间很小(比如我公司);

执行命令:sudo vim /etc/init.d/jenkins

 

修改jenkins.war的位置


# Check for missing binaries (stale symlinks should not happen)
# 默认的
#JENKINS_WAR="/usr/lib/jenkins/jenkins.war"
# 我修改后的
JENKINS_WAR="/home/jenkins/lib/jenkins.war"



修改日志文件和缓存war的位置


# 这里我自己声明了下面两个变量
JENKINS_LOG="/home/jenkins/log/jenkins.log"
JENKINS_CACHE_WAR="/home/jenkins/cache/war"

# 它们原本默认的位置:/var/log/jenkins/jenkins.log和/var/cache/jenkins/war

JAVA_CMD="$JENKINS_JAVA_CMD $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR"
PARAMS="--logfile=$JENKINS_LOG --webroot=$JENKINS_CACHE_WAR --daemon"

# 其中如果,home/jenkins目录中是没有`log`这个路径的
# 需求我们手动先创建好,否则启动时会报错,还要注意权限问题



修改jenkins的工作空间目录


执行命令:sudo vim /etc/sysconfig/jenkins – 这是打开jenkins的配置文件。

[jenkins@localhost ~]$ sudo vim /etc/sysconfig/jenkins 
[sudo] jenkins 的密码:
## Path:        Development/Jenkins
## Description: Jenkins Automation Server
## Type:        string
## Default:     "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
# 默认配置
#JENKINS_HOME="/var/lib/jenkins"
# 我修改后的路径
JENKINS_HOME="/home/jenkins/dataspace"

... ...


防火墙配置


执行如下命令:

sudo firewall-cmd --permanent --new-service=jenkins
sudo firewall-cmd --permanent --service=jenkins --set-short="Jenkins Service Ports"
sudo firewall-cmd --permanent --service=jenkins --set-description="Jenkins service firewalld port exceptions"
sudo firewall-cmd --permanent --service=jenkins --add-port=8080/tcp
sudo firewall-cmd --permanent --add-service=jenkins
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload

查看配置结果:

sudo firewall-cmd --list-all
1
如下:

[jenkins@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: ssh dhcpv6-client jenkins http
  ports: 8010/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


看到 services中有jenkins就对了。

 

启动jenkins


命令:

sudo service jenkins start/stop/restart
1


浏览器访问
我的是http://192.168.0.204:8080/
地址根据自己的情况,进行修改;

 

第一次登录密码


1、我的是:/home/jenkins/dataspace/secrets/initialAdminPassword
2、页面上会有提示的;

 

自选插件安装方式
在原有默认的基础上还有添加:

插件名:

① Role-based Authorization Strategy
② GitLab
③Publish Over SSH
④SSH
⑤SSH Agent
⑥Email Extension
⑦Git Parameter

⑧Dashboard View – 这个是我打算尝试的,非必须
⑨NodeJS 因为node.js挺火的,所以加进来。
(建议别装,一直卡在这个地方,都半个小时了)。

选择好了后,点击install进行安装。
(jenkins主要就是靠插件来干活的)

 

免密登录


执行命令:ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 22222 webuser@106.75.52.44'

[jenkins@localhost ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 22222 webuser@106.75.52.44'

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/jenkins/.ssh/id_rsa.pub"
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
        -f: force mode -- copy keys without trying to check if they are already installed
        -n: dry run    -- no keys are actually copied
        -h|-?: print this help

这道命令我明明没有写错:ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 22222 webuser@106.75.52.44'

却总提示上面的信息,反正就是不成功。(浪费了一个小时)

之后, 我放弃了,换了个方式:

① 先把 部署jenkins服务器上的.ssh中的id_rsa.pub,手动拷贝到远程服务器上(远程服务器的拷贝路径也是在.ssh文件中)

正规的做法应该是使用scp命令,但是我还得去密码,所以就手动弄了。

②再执行命令:cat id_rsa.pub >> authorized_keys

就可以啦!

目的就是为了:将jenkins所在服务器的公钥复制到远程服务器的authorized_keys文件夹中。

使用ssh-copy-id成功后会显示如下(中间会提示要你输入密码):

[jenkins@localhost ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22222 webloper@103.59.45.56
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/jenkins/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
webloper@103.59.45.56's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '22222' 'developer@123.59.44.56'"
and check to make sure that only the key(s) you wanted were added.


验证是否成功


 ssh webuser@106.75.52.44 -p 22222
# exit 退出远程登录


凭据

 

Publish over SSH
这个是远程服务器的配置

路径:系统配置 —> Publish over SSH

邮件配置
参考:jenkins配置邮件及增强版邮件通知

https://blog.csdn.net/u013066244/article/details/78665075
原文:https://blog.csdn.net/u013066244/article/details/84965409 

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试