Centos7安装Sonar

2019年2月28日 作者 ruike

Centos7安装Sonar

一、环境要求

1、JDK >1.8.0

2、Mysql数据库

3、Centos7

4、具体参照官网

环境要求

安装步骤

下载地址

二、安装流程

1、下载解压授权

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

unzip sonarqube-7.5.zip -d /usr/local/sonarqube-7.5

useradd sonar    //新建个普通用户,后面以该普通用户身份起动sonarqube服务

chown -R  sonar.sonar  /usr/local/sonarqube-7.5

2.配置

vim conf/sonar.properties

:wq 保存退出

3.启动

# 启动,另外有console、start、status、stop
su sonar /usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh start
# 查看状态
su sonar /usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh status
# 查看日志
tail -f /usr/local/sonarqube-7.5/logs/sonar.log

4.登录

  • 浏览器输入服务器ip:9000,默认账号密码admin admin,自行修改

三、修改工作目录

修改配置文件:

# 修改如下
vim /usr/local/sonarqube-7.5/conf/sonar.properties

sonar.path.logs=...
sonar.path.data=...
sonar.path.temp=...

保存重启服务

su sonar /usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh restart

四、Nginx反向代理到80端口

# SonarQube 9000
server {
    listen       80;
    server_name  sonar.***.com;
    access_log   /usr/local/nginx/logs/sonar.log;

    location / {
        proxy_pass http://127.0.0.1:9000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

五、其它

1、汉化:

下载对应版本中文插件包
https://github.com/SonarQubeCommunity/sonar-l10n-zh

比如7.5版本的

https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.25/sonar-l10n-zh-plugin-1.25.jar

将中文插件包到sonar插件文件夹

/usr/local/sonarqube-7.5/extensions/plugins

重启服务

su sonar /usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh restart

2、加入系统服务:

vim /usr/lib/systemd/system/sonar.service

[Unit]
Description=SonarQube project
After=network.target

[Service]
Type=forking
User=sonar
Group=sonar

ExecStart=/usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh start
ExecReload=/usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh restart
ExecStop=/usr/local/sonarqube-7.5/bin/linux-x86-64/sonar.sh stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# 启动
systemctl start sonar
# 停止
systemctl stop sonar
# 状态
systemctl status sonar
# 开机自启
systemctl enable sonar