EDITORIAL words
SonarQube this service some familiar, some unfamiliar. For us the operation and maintenance personnel, we need to understand is, SonarQube is a code quality management platform, know how to install configuration, which is actually almost enough. We specialize in Jenkins mention this thing here, the reason is that Jenkins has such a plug-in that was also quite a lot of companies use. So we have to put forward to talk to him.
SonarQube installation
Currently such services are mostly already provides a way docker installation, if you are familiar with and use for your own docker, then you can use. I still run it using the more traditional method here.
download link:
My current download is the official website of the latest community version: 7.8
1. Due to the need to rely on running Sonar JDK, we can all join JDK environment variables:
echo 'export JAVA_HOME=/data/jdk8 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile # 生效 source /etc/profile
By this time java -version can see the JDK version information:
2. The sonar decompression:
cd /data/ unzip sonarqube-7.8.zip ln -s sonarqube-7.8 sonar mv sonarqube-7.8.zip /tmp/
At this point in the / data directory sonar catalog is our service catalog.
3. Because it is Java services, in fact all sonar is cross-platform, we are linux machines, so finding linux directory:
Note that, at this time we can not be started directly, because the user can not run es as root, so we need to modify the start of authority:
# Add user, edit directory permissions the useradd SONAR CD / Data / chown - R & lt sonar.sonar SONAR chown -R & lt sonar.sonar sonarqube-7.8 # handover user starts SU - SONAR CD / Data / SONAR / bin / Linux-x86-64 / . /sonar.sh Console
The results are as follows:
This is the start of the completion of the identification, we need to know is, Sonar runs by default 9000 port, we can access the page to see:
4. But as the production of access, such configuration is not enough, we need to increase the database connection configuration uses MySQL for example:
我们在另外一台机的 MySQL 数据库新建了一个名为 sonar 的数据库,并授权给用户 sonar,密码也是 sonar。
由于刚刚我们 console 调试模式启动的,所以 ctrl + C 就可以停止服务。
此时需要去修改 sonar 的配置文件:/data/sonar/conf/sonar.properties
如果你非常熟悉 Java 服务你就会觉得很简单,就是 Java 的 JDBC 配置,系统默认注释了,需要放开,我这里的配置如下:
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://192.168.10.204:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
我们也可以在该配置文件中配置其他,例如运行端口:sonar.web.port=9000
5. 再度启动 Sonar:
此时我们发现 sonar 启动会报错:
解决办法:
切换到 root 用户,修改配置:
# 配置 sysctl -w vm.max_map_count=262144 # 查看 sysctl -a | grep vm.max_map_count # 永久生效 echo 'vm.max_map_count=262144' >> /etc/sysctl.conf
切换会 sonar 用户,再度重启,由于此次重启会初始化一些数据到我们刚刚配置的数据库,所以第一次比较耗时。
你可以连接到数据库查看生成情况,但是我当前的版本存在 BUG,需要手动执行一个 SQL:
insert into schema_migrations values (2128);
否则 sonar 无法启动,在初始化数据的时候会报错。
执行完成后重启 sonar 访问修复:
之后如果卡在 Sonar 正在重启中的页面,可以去服务器执行:
./sonar.sh restart
结果:
默认初始账户:admin / admin
中文汉化:
安装完成后按照提示重启!