注意:安装SonarQube 7.7 版本,需要安装JDK 1.8 和 MySQL 5.7
一、下载
SonarQube:https://www.sonarqube.org/downloads/
SonarQube汉化包:https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-1.27
二、设置安装环境
2.1官网要求:
2.2具体设置:
2.2.1 修改/etc/security/limits.conf文件
可以通过【ulimit -n】命令和【ulimit -u】查看大小。如果满足要求可以不用设置!
[root@centosServer ~]# vi /etc/security/limits.conf
sonarqube soft nproc 4096
sonarqube hard nproc 16384
sonarqube soft nofile 65536
sonarqube hard nofile 65536
2.2.2 修改/etc/sysctl.conf文件
可以通过【sysctl -a|grep vm.max_map_count】命令和【sysctl -a|grep fs.file-max】命令查看内核大小。
如果满足要求可以不用设置!
[root@centosServer ~]# vi /etc/sysctl.conf
vm.max_map_count = 262144
fs.file-max = 65536
# 输入命令:sysctl -p,使/etc/sysctl.conf配置文件立即生效。
[root@centosServer ~]# sysctl -p
三、开启远程访问
# 开放9000端口
firewall-cmd --zone=public --add-port=9000/tcp --permanent
# 重启
firewall-cmd --reload
# 查看防火墙是否放行9000端口
firewall-cmd --zone=public --list-ports
四、安装JDK 1.8
https://blog.csdn.net/m0_37048012/article/details/103747015
五、安装MySQL 5.7
https://blog.csdn.net/m0_37048012/article/details/107839983
六、安装SonarQube 7.7
6.1 创建系统用户
[root@centosServer ~]# useradd sonarqube
[root@centosServer ~]# passwd sonarqube
#设置2次同样的密码
6.2 上传安装包和汉化包
[root@centosServer ~]# cd /home/sonarqube/
6.3 解压安装包
如果unzip报错,请先执行安装【yum -y install unzip】命令。
[root@centosServer sonarqube]# unzip sonarqube-7.7.zip
6.4 移动汉化包,即可完成汉化
[root@centosServer sonarqube]# mv sonar-l10n-zh-plugin-1.27.jar /home/sonarqube/sonarqube-7.7/extensions/plugins/
6.5 修改sonar.properties核心配置文件
[root@centosServer sonarqube]# vi /home/sonarqube/sonarqube-7.7/conf/sonar.properties
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.jdbc.url=jdbc:mysql://192.168.200.139:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -server
sonar.web.host=192.168.200.139
sonar.web.context=/sonarqube
sonar.web.port=9000
# Elasticsearch
sonar.path.data=/var/sonarqube/data
sonar.path.temp=/var/sonarqube/temp
6.6 修改wrapper.conf核心配置文件
[root@centosServer sonarqube]# vi /home/sonarqube/sonarqube-7.7/conf/wrapper.conf
wrapper.java.command=/usr/java/jdk1.8.0_162/bin/java
6.7 切换sonarqube用户启动程序
# 授权
[root@centosServer ~]# chown -R sonarqube:sonarqube /home/sonarqube/
# 切换用户
[root@centosServer ~]# su - sonarqube
[sonarqube@centosServer ~]$ cd /home/sonarqube/sonarqube-7.7/bin/linux-x86-64/
# 启动程序
[sonarqube@centosServer linux-x86-64]$ ./sonar.sh start
6.8 通过sonar.log日志查看是否启动成功,如下图代表成功
[sonarqube@SonarServer ~]$ tail -1000f /home/sonarqube/sonarqube-7.7/logs/sonar.log
访问:http://you_ip:9000/sonarqube
账号:admin
密码:admin
七、开机启动
7.1 编写配置文件
[root@centosServer ~]# vi /etc/systemd/system/sonarqube.service
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=simple
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/bin/nohup /usr/java/jdk1.8.0_162/bin/java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /home/sonarqube/sonarqube-7.7/lib/sonar-application-7.7.jar
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=8192
TimeoutStartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
7.2 设置开机启动
# 开机启动
systemctl enable sonarqube.service
# 重启
reboot
八、常见命令
systemctl start sonarqube.service //启动
systemctl stop sonarqube.service //关闭
systemctl restart sonarqube.service //重启
systemctl status sonarqube.service //查看状态
九、参考网址
Centos 7 内核优化:
https://www.cnblogs.com/lixaingyang/p/12108309.html
https://blog.csdn.net/anqixiang/article/details/104922680