安裝參考連接php
[root@test-node3 ~]# yum install -y java-1.8.0 [root@test-node3 ~]# cd /etc/yum.repos.d/ [root@test-node3 yum.repos.d]# wget http://pkg.jenkins.io/redhat/jenkins.repo [root@test-node3 yum.repos.d]# rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key [root@test-node3 yum.repos.d]# yum install -y jenkins [root@test-node3 yum.repos.d]# systemctl start jenkins
[root@test-node3 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword d71307d2e9764f428d853bc49ac6b5ea
選擇默認安裝,會安裝通用的插件,剩下的在須要用的的時候再安裝。
java
等待安裝完成
設置用戶名密碼
user:admin
key: 123..abc
node
[root@test-node3 ~]# usermod -s /bin/bash jenkins -bash-4.2$ ssh-copy-id -i .ssh/id_rsa.pub www@10.0.0.204 The authenticity of host '10.0.0.204 (10.0.0.204)' can't be established. ECDSA key fingerprint is cd:9c:13:52:1a:96:c6:2b:4c:0c:5a:83:f6:94:01:48. Are you sure you want to continue connecting (yes/no)? yes /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys www@10.0.0.204's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'www@10.0.0.204'" and check to make sure that only the key(s) you wanted were added. -bash-4.2$ -bash-4.2$ ssh www@10.0.0.204 Last login: Wed Apr 12 09:33:40 2017 [www@salt-node4 ~]$ [www@salt-node4 ~]$ logout Connection to 10.0.0.204 closed.
測試
點擊當即構建
自動部署完成。
mysql
注:jenkins填寫的是私鑰(gitlab服務器上填寫的是公鑰 - 步驟同gitlab添加ssh 公鑰,jenkins用ssh協議到gitlab上面去拉取代碼。)linux
Sonar 是一個用於代碼質量管理的開放平臺。經過插件機制,Sonar 能夠集成不一樣的測試工具,代碼分析工具,以及持續集成工具。與持續集成工具(例如 Hudson/Jenkins 等)不一樣,Sonar 並非簡單地把不一樣的代碼檢查工具結果(例如 FindBugs,PMD 等)直接顯示在 Web 頁面上,而是經過不一樣的插件對這些結果進行再加工處理,經過量化的方式度量代碼質量的變化,從而能夠方便地對不一樣規模和種類的工程進行代碼質量管理。 在對其餘工具的支持方面,Sonar 不只提供了對 IDE 的支持,能夠在 Eclipse 和 IntelliJ IDEA 這些工具裏聯機查看結果;同時 Sonar 還對大量的持續集成工具提供了接口支持,能夠很方便地在持續集成中使用 Sonar。 此外,Sonar 的插件還能夠對 Java 之外的其餘編程語言提供支持,對國際化以及報告文檔化也有良好的支持
注:1 sonar 須要安裝數據庫版本爲mysql 5.6及以上。 2 須要java環境,java版本爲1.8以上
git
mysql 5.6 Yum源 https://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm yum -y install mysql-community-server
[sonar部署參考連接] (https://www.unixhot.com/article/56)github
[root@test-node3 ~]# cd /server/tools/ [root@test-node3 ~]# wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip [root@test-node3 tools]# unzip sonarqube-5.6.zip [root@test-node3 tools]# mv sonarqube-5.6 /usr/local/ [root@test-node3 tools]# ln -s /usr/local/sonarqube-5.6/ /usr/local/sonarqube
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw'; GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw'; FLUSH PRIVILEGES;
[root@test-node3 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.36 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.01 sec) mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw'; GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw'; Query OK, 0 rows affected (0.06 sec) mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql>
[root@test-node3 tools]# cd /usr/local/sonarqube/conf/ [root@test-node3 conf]# vim sonar.properties sonar.jdbc.username=sonar sonar.jdbc.password=sonar@pw sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
若是沒有正常啓動,查看日誌通常就能夠解決。
web
能夠在Sonar的配置文件來配置Sonar Web監聽的IP地址和端口,默認是9000端口。sql
[root@test-node3 conf]# vim sonar.properties sonar.web.host=0.0.0.0 sonar.web.port=9000 [root@test-node3 conf]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start [root@test-node3 logs]# netstat -tnlpua|grep 9000 tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 44042/java
分析什麼語言就下載對應的語言插件。數據庫
web界面 用戶名密碼,默認爲:admin/admin
步驟:
方法一 web界面安裝
Administration --> System --> Update Center --> Available 搜索chiness Pack 點擊install。 安裝完成以後須要重啓sonar [root@test-node3 plugins]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart
方法二 下載jar包進行替換下載的鏈接能夠根據在web界面安裝插件的失敗提醒來下載,若是不能下載,用迅雷下載。
https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.11/sonar-l10n-zh-plugin-1.11.jar 下載到/usr/local/sonarqube/extensions/plugins目錄 須要重啓才能生效 [root@test-node3 plugins]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart
[root@test-node3 plugins]# cd /server/tools/ [root@test-node3 tools]# wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.6.1.zip [root@test-node3 tools]# cp -rf sonar-scanner-2.6.1 /usr/local/sonar-scanner
[root@test-node3 tools]# cd /usr/local/sonar-scanner/conf [root@test-node3 conf]# cat sonar-scanner.properties #----- Default SonarQube server sonar.host.url=http://localhost:9000 #----- Default source code encoding sonar.sourceEncoding=UTF-8 #----- Global database settings (not used for SonarQube 5.2+) sonar.jdbc.username=sonar sonar.jdbc.password=sonar@pw #----- MySQL sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
掃描的是php語言,所以須要php語言的插件SonarPHP
[root@test-node3 tools]# unzip sonar-examples-4.5.zip [root@test-node3 tools]# cd /server/tools/sonar-examples-4.5/projects/languages/php/php-sonar-runner [root@test-node3 php-sonar-runner]# /usr/local/sonar-scanner/bin/sonar-scanner ..... INFO: Sensor PHP sensor INFO: 1 source files to be analyzed INFO: 1/1 source files have been analyzed INFO: No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property) INFO: No PHPUnit unit test coverage report provided (see 'sonar.php.coverage.reportPath' property) INFO: No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property) INFO: No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property) INFO: Sensor PHP sensor (done) | time=1030ms INFO: Sensor Analyzer for "php.ini" files INFO: Sensor Analyzer for "php.ini" files (done) | time=6ms INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=24ms INFO: Sensor Code Colorizer Sensor INFO: Sensor Code Colorizer Sensor (done) | time=1ms INFO: Sensor CPD Block Indexer INFO: DefaultCpdBlockIndexer is used for php INFO: Sensor CPD Block Indexer (done) | time=0ms INFO: Calculating CPD for 1 files INFO: CPD calculation finished INFO: Analysis report generated in 265ms, dir size=22 KB INFO: Analysis reports compressed in 14ms, zip size=9 KB INFO: Analysis report uploaded in 472ms INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/org.sonarqube:php-simple-sq-scanner INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AVthpV-GZk_1lOkjIdp8 INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 16.131s INFO: Final Memory: 43M/117M
注意:這裏面有一個文件須要定義的,告訴sonar 語言,版本,及相關。
[root@test-node3 php-sonar-runner]# cat sonar-project.properties # Required metadata sonar.projectKey=org.sonarqube:php-simple-sq-scanner sonar.projectName=PHP :: Simple Project :: SonarQube Scanner sonar.projectVersion=1.0 # Comma-separated paths to directories with sources (required) sonar.sources=src # Language sonar.language=php # Encoding of the source files sonar.sourceEncoding=UTF-8