Jenkins介绍
Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:
1、持续的软件版本发布/测试项目。
2、监控外部调用执行的工作。
3、参考文档:https://www.cnblogs.com/h--d/p/5673085.html & https://www.cnblogs.com/reblue520/category/1030718.html
安装jdk
[root@cm-vpn2 src]# tar -zxvf jdk-8u131-linux-x64.tar.gz
[root@cm-vpn2 src]# mv jdk1.8.0_131 /usr/local/jdk1.8
配置环境变量
[root@root-01 src]# vim /etc/profile
把这段配置写到最后面:
JAVA_HOME=/usr/local/jdk1.8/
JAVA_BIN=/usr/local/jdk1.8/bin
JRE_HOME=/usr/local/jdk1.8/jre
PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin
CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
#保存立即生效
[root@root-01 src]# source /etc/profile
安装jenkins
[root@www src]# rpm -ivh jenkins-2.73.3-1.1.noarch.rpm
warning: jenkins-2.73.3-1.1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID d50582e6: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:jenkins-2.73.3-1.1 ################################# [100%]
配置jenkins
[root@www src]# vim /etc/sysconfig/jenkins
#默认是8080修改为8088
JENKINS_PORT="8088"
JENKINS_HTTPS_PORT="8089"
启动jenkins
说明:启动jenkins报错
[root@www payment]# service jenkins start
Starting jenkins (via systemctl): Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
[FAILED]
[root@www payment]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2018-05-22 19:13:31 CST; 12s ago
Docs: man:systemd-sysv-generator(8)
Process: 5651 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)
May 22 19:13:30 www.surprizeboxx.test systemd[1]: Starting LSB: Jenkins Automation Server...
May 22 19:13:30 www.surprizeboxx.test runuser[5652]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
May 22 19:13:30 www.surprizeboxx.test jenkins[5651]: Starting Jenkins bash: /usr/bin/java: No such file or directory
May 22 19:13:30 www.surprizeboxx.test runuser[5652]: pam_unix(runuser:session): session closed for user jenkins
May 22 19:13:31 www.surprizeboxx.test jenkins[5651]: [FAILED]
May 22 19:13:31 www.surprizeboxx.test systemd[1]: jenkins.service: control process exited, code=exited status=1
May 22 19:13:31 www.surprizeboxx.test systemd[1]: Failed to start LSB: Jenkins Automation Server.
May 22 19:13:31 www.surprizeboxx.test systemd[1]: Unit jenkins.service entered failed state.
May 22 19:13:31 www.surprizeboxx.test systemd[1]: jenkins.service failed.
#解决把java环境变量加入
[root@www payment]# vim /etc/rc.d/init.d/jenkins
candidates="
************
************
/usr/local/jdk1.8/bin/java
"
#再启动就ok
[root@www payment]# service jenkins start
Starting jenkins (via systemctl): Warning: jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[ OK ]
#监听的端口8088 8089
[root@www src]# netstat -nvlpt |grep java
tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 29656/java
tcp6 0 0 :::8088 :::* LISTEN 5721/java
tcp6 0 0 :::8089 :::* LISTEN 5721/java
在网页上访问http://192.168.1.250:8088/
说明:第一次访问会提示输入密码,红色字体就是存放密码的路径
进入选择插件安装界面,选择第一个(Install suggested plugins)
说明:要点击一下
插件安装完成之后,需要创建第一个用户
创建用户之后,就可以使用jenkins了
SonarQube介绍:
SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误
安装SonarQube
说明:将下载的sonarqube-6.5.zip解压后移动到/usr/local目录下
[root@cm-vpn2 src]# wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.5.zip
[root@cm-vpn2 src]# unzip sonarqube-6.5.zip
[root@cm-vpn2 src]# mv sonarqube-6.5 /usr/local/sonarqube
安装Sonar-Runner
说明:将下载的sonar-runner-dist-2.4.zip解压后移动到/usr/local目录下
[root@cm-vpn2 src]# unzip sonar-runner-dist-2.4.zip
[root@cm-vpn2 src]# mv sonar-runner-2.4 /usr/local/sonar-runner
配置环境变量
[root@cm-vpn2 src]# vim /etc/profile
*****************
*****************
SONAR_HOME=/usr/local/sonarqube
export SONAR_HOME
SONAR_RUNNER_HOME=/usr/local/sonar-runner
export SONAR_RUNNER_HOME
#保存退出并使配置生效
[root@cm-vpn2 src]# source !$
source /etc/profile
配置数据库
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.11 sec)
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
Query OK, 0 rows affected (0.14 sec)
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.07 sec)
配置SonarQube Runner
[root@www ~]# vim /usr/local/sonar-runner/conf/sonar-runner.properties
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Global database settings
sonar.jdbc.username=sonar //数据库连接账号
sonar.jdbc.password=sonar //数据库连接密码
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
sonar.login=admin //sonarQube平台登录账号
sonar.password=admin //sonarQube平台登录密码
SonarQube 启动
[root@www ~]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.
[root@www ~]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh stop
Stopping SonarQube...
SonarQube was not running.
[root@www ~]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart
Stopping SonarQube...
SonarQube was not running.
Starting SonarQube...
Started SonarQube.
#监听端口 9000
[root@www ~]# netstat -nvlpt |grep java
tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 30945/java
tcp6 0 0 :::8088 :::* LISTEN 5721/java
tcp6 0 0 127.0.0.1:43993 :::* LISTEN 31099/java
tcp6 0 0 :::8089 :::* LISTEN 5721/java
tcp6 0 0 127.0.0.1:9092 :::* LISTEN 31032/java
tcp6 0 0 :::9000 :::* LISTEN 31032/java
tcp6 0 0 127.0.0.1:9001 :::* LISTEN 30970/java
在网页上访问http://192.168.1.250:9000/
点击login
说明:user:admin passwd:admin
至此SonarQube/SonarRunner/Jenkins已安装好
来源:oschina
链接:https://my.oschina.net/u/3662885/blog/1821392