centos7 安装部署sonarqube 8.9.1(postqresql数据库版)

sonar公司产品sonarqube以最大限度地提高质量并管理软件产品组合中的风险。为开发者软件开发人员最终负责代码质量。
代码质量是所谓的非功能性需求的一部分,因此是开发人员的直接责任。为有追求的程序员写出地道代码提供方向。

一、环境要求

1、centos7 x64
2、jdk11
3、postqresql10及以上版本
4、sonarqube 8.9.1
https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.1.44547.zip

二、服务安装

1、环境配置

内核配置
修改/etc/sysctl.conf
在文件末尾加入如下配置

vm.max_map_count=262144
fs.file-max=65536
sysctl  -p

vim /etc/security/limits.conf

*	soft	nofile	65536
*	hard	nofile	65536
*	soft	nproc	4096
*	hard	nproc	4096

基础环境yum

yum install -y vim lrzsz wget unzip epel-release
yum install -y java-11-openjdk java-11-openjdk-devel

vim /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.11.0.9-1.el7_9.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

2、安装postgresql

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
yum install postgresql10-contrib postgresql10-server -y
/usr/pgsql-10/bin/postgresql-10-setup initdb

配置文件

cp /var/lib/pgsql/10/data/pg_hba.conf{,.bak}

vim /var/lib/pgsql/10/data/pg_hba.conf
将 peer ident 改为 trust ,改了6行

local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

开机启动

systemctl start postgresql-10
systemctl enable postgresql-10.service

创建用户及数据库

su - postgres
psql
CREATE DATABASE sonar TEMPLATE template0 ENCODING 'utf8' ;
create user sonar;
alter user sonar with password 'sonar';
alter role sonar createdb;
alter role sonar superuser;
alter role sonar createrole;
alter database sonar owner to sonar;
\q
exit

3、安装sonarqube

adduser sonar
wget -c https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.1.44547.zip
unzip sonarqube-8.9.1.44547.zip 
mv sonarqube-8.9.1.44547 /usr/local/sonarqube
chown -R sonar:sonar /usr/local/sonarqube/

配置文件
vim /usr/local/sonarqube/conf/sonar.properties

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.jdbc.maxActive=60
sonar.jdbc.maxIdle=5
sonar.jdbc.minIdle=2
sonar.jdbc.maxWait=5000
sonar.jdbc.minEvictableIdleTimeMillis=600000
sonar.jdbc.timeBetweenEvictionRunsMillis=30000
sonar.jdbc.removeAbandoned=true
sonar.jdbc.removeAbandonedTimeout=60

vi /etc/profile

export SONAR_HOME=/usr/local/sonarqube
export SONAR_RUNNER_HOME=/usr/local/sonar-scanner
export PATH=$PATH:$SONAR_RUNNER_HOME/bin
export PATH=$PATH:$SONAR_HOME/bin

启动

su sonar
cd /usr/local/sonarqube/bin/linux-x86-64/
./sonar.sh start
Starting SonarQube...
Started SonarQube.

设置sonar系统systemd服务

vim /etc/systemd/system/sonar.service

[Unit]
 
Description=SonarQube Server
 
After=syslog.target network.target
 
[Service]
 
Type=forking
 
ExecStart=/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start
 
ExecStop= /usr/local/sonarqube/bin/linux-x86-64/sonar.sh stop
 
LimitNOFILE=65536
 
LimitNPROC=4096
 
User=sonar
 
Group=sonar
 
Restart=on-failure
 
[Install]
 
WantedBy=multi-user.target

自动启动

systemctl restart sonar.service

systemctl enable sonar.service

web访问
http://IP:9000
username:admin
password: admin

三、汉话
安装中文插件即可
centos7 安装部署sonarqube 8.9.1(postqresql数据库版)_第1张图片

注、

1、mysql版sonarqube

wget -c https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.5.0.56709.zip

mysql 5.7
grant all on *.* to "sonar"@"%" identified by "sonar";
create database sonar default character set utf8;

cd /usr/local/sonar/conf
vim sonar.properties
sonar.jdbc.username=sonar	#用户名
sonar.jdbc.password=sonar   #密码
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEnccding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.context=/sonar
sonar.web.port=9000
sonar.web.host=0.0.0.0

useradd sonar
chown -R sonar:sonar /usr/local/sonar
su sonar -c '/usr/local/sonar/bin/linux-x86-64/sonar.sh  start '
访问 http://ip:9000/sonar 	admin    admin
生成token  ->输入(otoyix) ->java->manen
mvn sonar:sonar \
-Dsonar.host.ur1-http://192.168.0.1:xxxx/sonar \
-Dsonar.login=838edadfcb2c6326b1c6e2118f4309f74d888458


2、docker-compose.yml

version: '2'
services:
  postgres:
    image: postgres
    restart: always
    container_name: postgres
    ports:
      - 5432:5432
    volumes:
      - /home/sonar/postgres/postgresql:/var/lib/postgresql
      - /home/sonar/postgres/data:/var/lib/postgresql/data
    environment:
      TZ: Asia/Shanghai
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
      POSTGRES_DB: sonar

  sonar:
    image: sonarqube
    container_name: sonar
    depends_on:
      - postgres
    volumes:
      - /home/sonar/sonarqube/extensions:/opt/sonarqube/extensions
      - /home/sonar/sonarqube/logs:/opt/sonarqube/logs
      - /home/sonar/sonarqube/data:/opt/sonarqube/data
      - /home/sonar/sonarqube/conf:/opt/sonarqube/conf
      - /home/sonar/sonarqube/lib/common:/opt/sonarqube/lib/common
      - /home/sonar/sonarqube/lib/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
    ports:
      - 9999:9000
    command:
      # 内存设置
      - -Dsonar.ce.javaOpts=-Xmx2048m
      - -Dsonar.web.javaOpts=-Xmx2048m
    environment:
      SONARQUBE_JDBC_USERNAME: sonar
      SONARQUBE_JDBC_PASSWORD: sonar
      SONARQUBE_JDBC_URL: jdbc:postgresql://postgres:5432/sonar

----------------------end

你可能感兴趣的:(linux常用基础技能及服务,Devops,#,sonarqube,sonar,centos,postqresql)