码迷,mamicode.com
首页 > 其他好文 > 详细

sonarqube && sonar-scanner

时间:2020-06-02 12:53:12      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:pen   figure   grep   change   collect   dai   splay   not   pts   

sonarqube && sonar-scanner

link
技术图片

sonarqube

download
archive
github-sonarqube
sonarqube-7.9.3-lts

sonarqube-lts-7.9 requirement

link

opt-env

  • openjdk-11
  • postgresql-10
  • centos-7.x 2c4g

openjdk-11

openjdk
download

01、mkdir home && unzip

[root@c-3-103 ~]# mkdir /opt/sonarqube  //项目运行目录
[root@c-3-103 ~]# tar zxf openjdk-11.0.2_linux-x64_bin.tar.gz  -C /opt/sonarqube/
[root@c-3-103 ~]# 
[root@c-3-103 ~]# cd /opt/sonarqube/
[root@c-3-103 sonarqube]# ll
total 0
drwxr-xr-x 8 root root 96 Jun  1 23:47 jdk-11.0.2
[root@c-3-103 sonarqube]# cd jdk-11.0.2/
[root@c-3-103 jdk-11.0.2]# pwd
/opt/sonarqube/jdk-11.0.2

02、add openjdk-env

cat <<-‘EOF‘ >>/etc/profile
#add openjdk-11
export JAVA_HOME=/opt/sonarqube/jdk-11.0.2
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
EOF

[root@c-3-103 jdk-11.0.2]# source /etc/profile
[root@c-3-103 jdk-11.0.2]# 
[root@c-3-103 jdk-11.0.2]# java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
[root@c-3-103 jdk-11.0.2]# 

postgresql-10

download
reference

01、requirement

[root@c-3-103 postgresql-10.10]# yum install -y gcc gcc-c++ make autoconf
[root@c-3-103 jdk-11.0.2]# yum install -y ncurses-devel readline-devel zlib-devel

02、adduser && pgdata && pg_env

[root@c-3-103 ~]# useradd postgres
[root@c-3-103 ~]# mkdir -p /opt/sonarqube/pgdata/{data,archive}
su - postgres   //配置环境变量
tee <<-‘EOF‘ >>.bash_profile
export PGHOME=/opt/sonarqube/pgdata
export PGDATA=$PGHOME/data
export PATH=$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=.:$PGHOME/lib
EOF
source .bash_profile

03、compile && init

[root@c-3-103 ~]# yum install -y lbzip2
[root@c-3-103 ~]# tar zxf postgresql-10.10.tar.bz2
[root@c-3-103 postgresql-10.10]# ./configure   -q --prefix=/opt/sonarqube/pgdata
[root@c-3-103 postgresql-10.10]# make -s -j4
[root@c-3-103 postgresql-10.10]# make -s install
[root@c-3-103 postgresql-10.10]# chown -R postgres: /opt/sonarqube/pgdata/
su - postgres
initdb --auth=trust --auth-host=md5 --auth-local=trust --pgdata=$PGDATA --encoding=‘UTF-8‘ --username=postgres --pwprompt
[postgres@c-3-103 data]$ pwd
/opt/sonarqube/pgdata/data
[postgres@c-3-103 data]$ 
tee <<-‘EOF‘ >> postgresql.auto.conf
listen_addresses = ‘*‘
port = 5432
wal_level = hot_standby
archive_mode = on
archive_command = ‘cp %p /opt/sonarqube/pgdata/archive/%f‘
#max_wal_senders = 10
logging_collector = on
EOF

[postgres@c-3-103 data]$ egrep -v ‘^#|^$‘ pg_hba.conf 
local   all             all                                     trust
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             0.0.0.0/0               md5

[postgres@c-3-103 ~]$ pg_ctl start  //start pg
waiting for server to start....2020-06-02 00:14:57.195 CST [20182] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-06-02 00:14:57.195 CST [20182] LOG:  listening on IPv6 address "::", port 5432
2020-06-02 00:14:57.196 CST [20182] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-06-02 00:14:57.211 CST [20182] LOG:  redirecting log output to logging collector process
2020-06-02 00:14:57.211 CST [20182] HINT:  Future log output will appear in directory "log".
 done
server started
[postgres@c-3-103 ~]$ 
[postgres@c-3-103 ~]$ ss -lnt
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      128                                    *:22                                                 *:*                  
LISTEN      0      128                                    *:5432                                               *:*                  
LISTEN      0      100                            127.0.0.1:25                                                 *:*                  
LISTEN      0      128                                   :::22                                                :::*                  
LISTEN      0      128                                   :::5432                                              :::*                  
LISTEN      0      100                                  ::1:25                                                :::*                  
[postgres@c-3-103 ~]$ psql
psql (10.10)
Type "help" for help.

postgres=# \q
[postgres@c-3-103 ~]$

04、init sonar db

su - postgres
psql

create database sonar;
create user sonar with superuser createdb createrole login password ‘123123‘;
alter database sonar owner to sonar;

sonarqube-lts-7.9

01、linux-sonar turn
link

tee <<-EOF  >>/etc/sysctl.conf
#add sonarqube
vm.max_map_count=262144
fs.file-max=102400
EOF

sysctl -p

tee <<-EOF  >>/etc/security/limits.conf
#add sonarqube
sonar  -  nofile 102400
sonar  -  nproc  102400
EOF

02、add user && config

[root@c-3-103 ~]# useradd sonar
[root@c-3-103 ~]# yum install -y unzip
[root@c-3-103 ~]# unzip sonarqube-7.9.3.zip  -d /opt/sonarqube/
[root@c-3-103 ~]# chown -R sonar: /opt/sonarqube/sonarqube-7.9.3/

[root@c-3-103 conf]# pwd
/opt/sonarqube/sonarqube-7.9.3/conf

[root@c-3-103 conf]# egrep -v ‘^#|^$‘ sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=123123
sonar.jdbc.url=jdbc:postgresql://192.168.3.103/sonar
sonar.web.javaOpts=-Xmx1024m -Xms1024m -XX:+HeapDumpOnOutOfMemoryError
sonar.web.host=0.0.0.0
[root@c-3-103 conf]#

03、privileges && start

[root@c-3-103 conf]# su - sonar   //change sonar to running
[sonar@c-3-103 ~]$ /opt/sonarqube/sonarqube-7.9.3/bin/linux-x86-64/sonar.sh start |status |stop

[sonar@c-3-103 linux-x86-64]$ ./sonar.sh --help
Usage: ./sonar.sh { console | start | stop | force-stop | restart | status | dump }

[sonar@c-3-103 ~]$ tail -F /opt/sonarqube/sonarqube-7.9.3/logs/sonar.log 

[sonar@c-3-103 logs]$ pwd
/opt/sonarqube/sonarqube-7.9.3/logs
[sonar@c-3-103 logs]$ ll
total 212
-rw-r--r-- 1 sonar sonar  54757 Jun  2 11:28 access.log
-rw-r--r-- 1 sonar sonar   1136 Jun  2 11:26 ce.log
-rw-r--r-- 1 sonar sonar  11500 Jun  2 11:26 es.log
-rw-r--r-- 1 sonar sonar     88 Mar 24 08:24 README.txt
-rw-r--r-- 1 sonar sonar   4978 Jun  2 11:26 sonar.log
-rw-r--r-- 1 sonar sonar 128911 Jun  2 11:26 web.log
[sonar@c-3-103 logs]$ 

04、open sonarqube web

http://192.168.3.103:9000/
admin/admin    //default user

sonar-scanner

link
doc

01、download && unzip

[root@c-3-103 ~]# unzip sonar-scanner-cli-4.3.0.2102-linux.zip  -d /opt/sonarqube/
[root@c-3-103 ~]# chown -R sonar: /opt/sonarqube/sonar-scanner-4.3.0.2102-linux/

[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ ll bin/
total 8
-rwxr-xr-x 1 sonar sonar 1761 Feb 20 08:14 sonar-scanner
-rwxr-xr-x 1 sonar sonar  595 Feb 20 08:14 sonar-scanner-debug
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ ./bin/sonar-scanner -h
INFO: 
INFO: usage: sonar-scanner [options]
INFO: 
INFO: Options:
INFO:  -D,--define <arg>     Define property
INFO:  -h,--help             Display help information
INFO:  -v,--version          Display version information
INFO:  -X,--debug            Produce execution debug output
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ 
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ 
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ 
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ ./bin/sonar-scanner -v
INFO: Scanner configuration file: /opt/sonarqube/sonar-scanner-4.3.0.2102-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.3.0.2102
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 3.10.0-862.el7.x86_64 amd64
[sonar@c-3-103 sonar-scanner-4.3.0.2102-linux]$ 

02、add env && config

tee <<-‘EOF‘ >> ~/.bash_profile
#add sonaqube env
export SONAR_HOME=/opt/sonarqube/sonarqube-7.9.3
export SONAR_SCANNER_HOME=/opt/sonarqube/sonar-scanner-4.3.0.2102-linux
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-Xmx1024m"
EOF

source ~/.bash_profile
[sonar@c-3-103 conf]$ cat sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://192.168.3.103:9000

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

03、scanner codes

进入到待扫描代码根目录新建sonar-project.properties
#sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=my:project

# --- optional properties ---

# defaults to project key
#sonar.projectName=My project
# defaults to ‘not provided‘
#sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=.
 
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

#path to your project build output path
#sonar.java.binaries=target/classes

sonar-scaneer  //代码根目录执行

sonar.projectName是项目名字
sonar.sources=是源文件所在的目录

Sample Projects

To help you get started, simple project samples are available for most languages on github. They can be browsed or downloaded. You‘ll find them filed under sonarqube-scanner/src.

daily-opt

postgresql

su - postgres
pg_ctl start
ps -ef | grep postgres //查看pgsql进程
pg_ctl status //查看数据状态
pg_ctl stop -m fast //停止数据库

troubleshooting

对于多语言扫描请预先安装对应的编译语言组件 go/node/python ...

reference

link

sonarqube && sonar-scanner

标签:pen   figure   grep   change   collect   dai   splay   not   pts   

原文地址:https://www.cnblogs.com/xiaochina/p/13030515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!