1. 程式人生 > >centos7下sonar5.6 + mysql5.7搭建程式碼質量管理平臺

centos7下sonar5.6 + mysql5.7搭建程式碼質量管理平臺

最近自己搭建sonar管理平臺花了三個晚上的時間,走了不少彎路,搭建MySQL時,用yum 安裝mysql 發現缺包,最後下載二進位制檔案安裝的。開始安裝的時mysql8。安裝好了之後,下載最新版的sonar6.6,修改配置,啟動。發現總報錯,錯誤日誌找不出具體錯誤原因。網上找了一大圈,還是沒解決問題。最後下載5.7版的。啟動後報錯,發現是不識別groups 這張表。應該是MySQL8的原因。然後下載了5.7的版本。這才弄好。
總結一點,不要什麼都用最新的。出問題了,難折騰。

mysql安裝

  • 安裝libaio
    shell> yum search libaio # search for info
    shell> yum install libaio # install library
  • 安裝mysql
    shell> groupadd mysql
    shell> useradd -r -g mysql -s /bin/false mysql
    shell> cd /usr/local
    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
    shell> ln -s full-path-to-mysql-VERSION-OS mysql
    shell> cd mysql
    shell> mkdir mysql-files
    shell> chown mysql:mysql mysql-files
    shell> chmod 750 mysql-files
    shell> bin/mysqld –initialize –user=mysql
    shell> bin/mysql_ssl_rsa_setup
    啟動MySQL,會生成一個密碼當前位置,控制檯也會輸出該密碼
    shell> bin/mysqld_safe –user=mysql &
    可選,應該是設定開機啟動
    shell> cp support-files/mysql.server /etc/init.d/mysql.server
    登入mysql
    mysql -umysql -p
    如果密碼過期,則進行免密登入
    重啟服務
    mysqld –user=mysql –skip-grant-tatbles &
    重新登入
    mysql
    設定密碼,永久有效
    update user set authentication_string = password(‘mysql’), password_expired = ‘N’, password_last_changed = now() where user = ‘mysql’ and Host = ‘localhost’;
    重啟服務
    mysqld –user=mysql &
    登入
    mysql -u mysql -p
    設定遠端登入
    GRANT ALL PRIVILEGES ON *.* TO’mysql’@’%’ IDENTIFIED BY ‘mysql’ WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    這時可以遠端連線MySQL 了

  • 安裝sonar
    請先安裝jdk1.8
    下載sonar5.6
    wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.7.zip
    解壓 unzip sonarqube-5.6.7.zip
    修改配置檔案 vi conf/sonar.properties
    連線池配置
    sonar web配置
    啟動sonar
    ./sonar.sh start &
    登入sonar web
    http://192.168.1.117:9000
    使用者名稱/密碼 admin/admin 登入
    下載外掛
    漢化包
    Setting >> Update Center >> Available Plugins >> LOCALIZATION >> Chinese Pack >> Install

  • 安裝maven ,在settings.xml 新增sonar配置
<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://myserver:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>
  • 分析maven專案
    在專案的根目錄下執行命令: mvn clean verify sonar:sonar