centos安装使用jenkins

环境

jdk1.8 安装
mvn 4.5.x 安装

下载jenkins

  1. 快速安装方式

wget https://pkg.jenkins.io/redhat-stable/jenkins-2.150.3-1.1.noarch.rpm

rpm -ivh jenkins-2.150.3-1.1.noarch.rpm

  1. 或者使用yum安装

yum install -y jenkins

设置jenkins端口

vi /etc/sysconfig/jenkins

更改

JENKINS_PORT="7788"

JENKINS_AJP_PORT="7007"

自动安装完成之后:

/usr/lib/jenkins/jenkins.war  #  WAR包 

/etc/sysconfig/jenkins # 配置文件

/var/lib/jenkins/ # 默认的JENKINS_HOME目录

/var/log/jenkins/jenkins.log # Jenkins日志文件

启动jenkins

systemctl start jenkins

可能出现错误

Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.

vi /etc/init.d/jenkins

更改jdk的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
/usr/local/jdk1.8/bin/java # 注意添加java的执行路径

再次启动

systemctl start jenkins

连接测试

curl 127.0.0.1:7788

查看密码

cat /var/lib/jenkins/secrets/initialAdminPassword

查看私钥 放入jenkins中

cat .ssh/id_rsa

查看公钥 放入第三方git上

cat .ssh/id_rsa.pub

生成私钥

ssh-keygen -t rsa

jenkins忘记密码两种解决方案

默认Jenkins的配置目录是/root/.jenkins/

一、admin 密码更改情况

  1. 进入\Jenkins\secrets目录,打开initialAdminPassword文件,复制密码;

  2. 访问Jenkins页面,输入管理员admin,及刚才的密码;

  3. 进入后可更改其他管理员密码;

    二、忘记密码,重置密码

  4. 删除Jenkins目录下config.xml文件中下面代码,并保存文件。


<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy">
<denyAnonymousReadAccess>true</denyAnonymousReadAccess>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>true</disableSignup>
<enableCaptcha>false</enableCaptcha>
</securityRealm>
  1. 重启Jenkins服务;

  2. 进入首页>“系统管理”>“Configure Global Security”;

  3. 勾选“启用安全”;

  4. 点选“Jenkins专有用户数据库”,并点击“保存”;

  5. 重新点击首页>“系统管理”,发现此时出现“管理用户”;

  6. 点击进入展示“用户列表”;

  7. 点击右侧进入修改密码页面,修改后即可重新登录

本文总阅读量