sonar6.7.5的安装和配置以及与jenkins的集成

11280阅读 0评论2018-11-15 missing-cn
分类:系统运维

sonar6.7.5的安装和配置

摘要

代码分析软件sonar的安装配置及升级过程

1、安装

#选择长周期支持的版本6.7.5

wget -c  
 cp -r sonar/ sonar.4.0

service sonar stop 

原来4.0使用的mysql已经不建议使用了,本次使用postgresql。

[root@xgit opt]# cat /etc/centos-release
CentOS release 6.5 (Final)
[root@xgit opt]# yum install 
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.yun-idc.com
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.aliyun.com
Setting up Install Process
pgdg-redhat96-9.6-3.noarch.rpm                                                      | 4.7 kB     00:00
Examining /var/tmp/yum-root-961sdj/pgdg-redhat96-9.6-3.noarch.rpm: pgdg-redhat96-9.6-3.noarch
Marking /var/tmp/yum-root-961sdj/pgdg-redhat96-9.6-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat96.noarch 0:9.6-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                  Arch              Version           Repository                              Size
===========================================================================================================
Installing:
 pgdg-redhat96            noarch            9.6-3             /pgdg-redhat96-9.6-3.noarch            2.7 k

Transaction Summary
===========================================================================================================
Install       1 Package(s)

Total size: 2.7 k
Installed size: 2.7 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : pgdg-redhat96-9.6-3.noarch                                                              1/1
  Verifying  : pgdg-redhat96-9.6-3.noarch                                                              1/1

Installed:
  pgdg-redhat96.noarch 0:9.6-3

Complete!
#安装客户端和服务端
[root@xgit opt]# yum install postgresql96 yum install postgresql96-server
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.yun-idc.com
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.aliyun.com
pgdg96                                                                              | 4.1 kB     00:00
pgdg96/primary_db                                                                   | 207 kB     00:00
Setting up Install Process
^C[root@xgit opt]# yum install postgresql96 postgresql96-server -y
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.yun-idc.com
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.aliyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.10-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.10-1PGDG.rhel6 for package: postgresql96-9.6.10-1PGDG.rhel6.x86_64
---> Package postgresql96-server.x86_64 0:9.6.10-1PGDG.rhel6 will be installed
--> Running transaction check
---> Package postgresql96-libs.x86_64 0:9.6.10-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                        Arch              Version                          Repository         Size
===========================================================================================================
Installing:
 postgresql96                   x86_64            9.6.10-1PGDG.rhel6               pgdg96            1.4 M
 postgresql96-server            x86_64            9.6.10-1PGDG.rhel6               pgdg96            5.0 M
Installing for dependencies:
 postgresql96-libs              x86_64            9.6.10-1PGDG.rhel6               pgdg96            289 k

Transaction Summary
===========================================================================================================
Install       3 Package(s)

Total download size: 6.8 M
Installed size: 27 M
Downloading Packages:
(1/3): postgresql96-9.6.10-1PGDG.rhel6.x86_64.rpm                                   | 1.4 MB     00:33
(2/3): postgresql96-libs-9.6.10-1PGDG.rhel6.x86_64.rpm                              | 289 kB     00:02
(3/3): postgresql96-server-9.6.10-1PGDG.rhel6.x86_64.rpm                            | 5.0 MB     01:24
-----------------------------------------------------------------------------------------------------------
Total                                                                       57 kB/s | 6.8 MB     02:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : postgresql96-libs-9.6.10-1PGDG.rhel6.x86_64                                             1/3
  Installing : postgresql96-9.6.10-1PGDG.rhel6.x86_64                                                  2/3
  Installing : postgresql96-server-9.6.10-1PGDG.rhel6.x86_64                                           3/3
  Verifying  : postgresql96-libs-9.6.10-1PGDG.rhel6.x86_64                                             1/3
  Verifying  : postgresql96-server-9.6.10-1PGDG.rhel6.x86_64                                           2/3
  Verifying  : postgresql96-9.6.10-1PGDG.rhel6.x86_64                                                  3/3

Installed:
  postgresql96.x86_64 0:9.6.10-1PGDG.rhel6         postgresql96-server.x86_64 0:9.6.10-1PGDG.rhel6

Dependency Installed:
  postgresql96-libs.x86_64 0:9.6.10-1PGDG.rhel6

Complete!
[root@xgit opt]# service postgresql-9.6 initdb
Initializing database:                                     [  OK  ]
[root@xgit opt]# chkconfig postgresql-9.6 on
[root@xgit opt]# service postgresql-9.6 start
[root@xgit opt]# service postgresql-9.6 start
Starting postgresql-9.6 service:                           [  OK  ]
[root@xgit opt]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@xgit opt]#

其实就是解压 unzip sonarqube-6.7.5.zip

-bash-4.1$ psql
psql (8.4.20, server 9.6.10)
WARNING: psql version 8.4, server version 9.6.
         Some psql features might not work.
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
(3 rows)
[root@xgit opt]# sysctl vm.max_map_count
vm.max_map_count = 65530
[root@xgit opt]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
#修改/etc/sysctl.conf 增加 vm.max_map_count = 262144
[root@xgit opt]# sysctl fs.file-max
fs.file-max = 1619009
[root@xgit opt]# ulimit -u
127306
[root@xgit opt]# ulimit -u
127306 
## sonar为运行sonar服务的系统账号

sonar            hard    nofile          65536
sonar            soft    nproc           4096  # 线程

sonar            hard    nproc           4096  # 进程 

2、sonar服务的配置

## 连接postgresql的用户
sonar.jdbc.username=sonar
## 同上用户的密码
sonar.jdbc.password=yourpassword
## jdbc 连接,sonar为数据库名
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
## sonar 服务器ip或者域名
sonar.web.host=192.168.x.x
# The default value is root context (empty value).
#sonar.web.context=
# TCP port for incoming HTTP connections. Default value is 9000.
#sonar.web.port=9000

#因是centos6关闭seccomp filter功能
sonar.search.javaAdditionalOpts=-Dbootstrap.system_call_filter=false 
postgres=# create user sonarqube with password 'your_password' ;
CREATE ROLE 
[root@xgit opt]# su - postgres
-bash-4.1$ psql
psql (8.4.20, server 9.6.10)

postgres=# create database sonar owner sonar;
CREATE DATABASE
postgres=# grant all privileges on database sonar to sonar;
GRANT 
vi /var/lib/pgsql/9.6/data/pg_hba.conf
##添加下面一行数据

host    sonar           sonar           127.0.0.1/32            md5

3、启动sonar

su - sonar

cd /opt/sonarqube-6.7.5
bin/linux-x86-64/sonar.sh start

logs/sonar.log内出现下面提示,应为正常启动

2018.11.14 20:16:17 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2018.11.14 20:16:30 INFO  app[][o.s.a.SchedulerImpl] Process[es] is up
2018.11.14 20:16:46 INFO  app[][o.s.a.SchedulerImpl] Process[web] is up

2018.11.14 20:16:53 INFO  app[][o.s.a.SchedulerImpl] Process[ce] is up
2018.11.14 20:16:53 INFO  app[][o.s.a.SchedulerImpl] SonarQube is up
#!/bin/sh
### BEGIN INIT INFO
# Provides:          sonar
# Required-Start:    $local_fs $remote_fs $network $time $named
# Required-Stop:     $local_fs $remote_fs $network $time $named
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Sonar
# Description:       Open platform to manage code quality
### END INIT INFO

NAME=sonar
SCRIPTNAME=/etc/init.d/$NAME

if [ `id -u` -ne 0 ]; then
  echo "The $NAME init script can only be run as root"
  exit 1
fi

MACHINE_TYPE=`getconf LONG_BIT`
if [ "${MACHINE_TYPE}" = "64" ]; then
  JSW=/opt/sonar/bin/linux-x86-64/sonar.sh
else
  JSW=/opt/sonar/bin/linux-x86-32/sonar.sh
fi

do_start()
{
  su sonar -c "$JSW start"
}

do_stop()
{
  su sonar -c "$JSW stop"
}

do_status()
{
  su sonar -c "$JSW status"
}

do_restart()
{
  su sonar -c "$JSW restart"
}

case "$1" in
  start)
    do_start
    ;;
  stop)
    do_stop
    ;;
  status)
    do_status
    ;;
  restart|force-reload)
    do_restart
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

exit 0

service sonar start/stop/restart

4、查看分析结果

浏览器访问

在jenkinss上配置sonar

致谢参考

官方SonarQube-6.7文档

参考1

参考2

 

上一篇:jenkins slave console 乱码的解决
下一篇:jenkins从1.651升级到2.151的过程