Sonar installation and code quality check instances and sonar code check instances

Source: Internet
Author: User

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
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

Create sonar database Dependencies

create database sonar default character set utf8;

2. Use nginx response proxy

Upstream Configuration

upstream tomcat_tools.sonar.local {        server  weight=10 max_fails=2 fail_timeout=300s;}server {        listen                   80;        server_name    ;        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  wrapper[root@localhost linux-x86-64]# ./ startStarting SonarQube...Started SonarQube.

5. Access

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://;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>              <></>          </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 [].

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.