Sonar installation and code quality check instances and sonar code check instances
Note: sonar depends on the database.
Mysql Optimization
1. I am using the mysql database. I will first make simple Optimization Configuration for mysql.
[Root @ localhost bin] # cat/etc/my. cnf [mysqld] max_allowed_packet = 10 Mdatadir =/var/lib/mysqlsocket =/var/lib/mysql. sockuser = mysql # Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links = 0 # modify the default encoding to utf8default-character-set = utf8 # modify the default storage engine to InnoDBdefault-storage-engine = InnoDB # this parameter is mainly used to cache indexes of innodb tables, data, innodb_buffer_pool_size = 256 M # configure query_cache_size = 128 M # Start mysql cache query_cache_type = 1 [mysqld_safe] log-error =/var/log/mysqld. logpid-file =/var/run/mysqld. pid
2. Restart the mysql service.
[root@localhost bin]# service mysqld restartStopping mysqld: [ OK ]Starting mysqld: [ OK ]
Sonar installation and deployment
1. sonar deployment
[root@localhost local]# pwd/usr/local[root@localhost local]# unzip sonarqube-4.5.4.zip
Modify the sonar configuration file
[root@localhost conf]# pwd/usr/local/sonarqube-4.5.4/conf[root@localhost conf]# vim sonar.propertiessonar.jdbc.username=rootsonar.jdbc.password=123456sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformancesonar.web.javaOpts=-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryErrorsonar.web.host=0.0.0.0sonar.web.port=9000
Create sonar database Dependencies
create database sonar default character set utf8;
2. Use nginx response proxy
Upstream Configuration
upstream tomcat_tools.sonar.local { server 127.0.0.1:9000 weight=10 max_fails=2 fail_timeout=300s;}server { listen 80; server_name tools.sonar.local.com; root /usr/local/sonarqube-4.5.4/web/; access_log /usr/local/sonarqube-4.5.4/logs/tools.sonar.local.com_access.log main; error_log /usr/local/sonarqube-4.5.4/logs/tools.sonar.local.com_error.log warn; error_page 403 404 /40x.html; location / { index index.html index.htm; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_tools.sonar.local; expires 0d; }}
Restart nginx after adding or removing configurations.
[root@localhost domains]# service nginx restart
3. Modify the firewall to open port 9000
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j ACCEPT
4. Start sonar
[root@localhost linux-x86-64]# pwd/usr/local/sonarqube-4.5.4/bin/linux-x86-64[root@localhost linux-x86-64]# lslib sonar.sh wrapper[root@localhost linux-x86-64]# ./sonar.sh startStarting SonarQube...Started SonarQube.
5. Access tools.sonar.local.com
6. log on to sonar [Default Account admin/admin] to install the Chinese package
Settings/SYSTEM/Update Center/Available Plugins
Select the Chinese package and restart it after the Chinese package is finished.
Project code submission sonar Detection code Quality
1. Add the following content between <profiles> nodes in settings. xml of the maven local repository:
<profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <sonar.jdbc.url> jdbc:mysql://192.168.147.129:3306/sonar?useUnicode=true&characterEncoding=utf8 </sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>root</sonar.jdbc.username> <sonar.jdbc.password>123456</sonar.jdbc.password> <sonar.host.url>http://tools.sonar.local.com</sonar.host.url> </properties> </profile> </profiles>
Or add the above content directly in the total pom of the application project. The difference is that the former increases for all projects, and the latter only configures for a single project.
2. Create an mvn command
3. Run the command to view the sonar Control Panel project.
Click here to view the quality of the Code.
For more information, see [http://www.cnblogs.com/dennisit/p/4546245.html].