useradd -s /sbin/nologin -M mysql
cd /home/tools
wget https://downloads.mysql.com/archives/get/file/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
cd /home/tools
tar xf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
mkdir -p /application
mv /home/tools/mysql-5.6.36-linux-glibc2.5-x86_64 /application/mysql-5.6.36
ln -s /application/mysql-5.6.36/ /application/mysql
chown -R mysql.mysql /application/mysql
cd /application/mysql && /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
\cp -f /application/mysql/support-files/my-default.cnf /etc/my.cnf
/etc/init.d/mysqld start
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
chkconfig --add mysqld
chkconfig mysqld on
mysqladmin -uroot password '要设置的密码'
mysql -uroot -p123456
mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw';
mysql> FLUSH PRIVILEGES;
yum install -y java-1.8.0
cd /usr/local/src
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip
unzip sonarqube-6.7.6.zip
mv sonarqube-6.7.6 /usr/local/
ln -s /usr/local/sonarqube-6.7.6/ /usr/local/sonarqube
说明:Sonar的配置文件主要是配置相关启动参数和数据库的信息,数据库不需要初始化,Sonar启动的过程中会自动初始化。
cd /usr/local/sonarqube/conf/
ls
sonar.properties wrapper.conf
vim sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar@pw
sonar.jdbc.url=jdbc:mysql://192.168.1.100:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
说明:你可以在Sonar的配置文件来配置Sonar Web监听的IP地址和端口,默认是9000端口
vim sonar.properties
sonar.web.host=0.0.0.0
sonar.web.port=9000
/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start
cd /usr/local/src
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
unzip sonar-scanner-cli-3.3.0.1492-linux.zip
mv sonar-scanner-cli-3.3.0.1492 /usr/local
ln -s /usr/local/sonar-scanner-cli-3.3.0.1492-linux /usr/local/sonar-scanner
6.3、配置sonar客户端
cd /usr/local/sonar-scanner/conf/
cat sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://192.168.1.201:9000 #填写sonar服务端的ip和port
#----- Default source code encoding
sonar.sourceEncoding=UTF-8 #打开此行的注释即可
cat sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=icp-service-interface #填写sonar唯一的key,可随意填写,不能与其它项目重复
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=icp-service-interface #sonar客户端识别的用户名,可随意填写,唯一即可
sonar.projectVersion=1.0 #sonar的版本(保持不变即可)
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=. #源码路径(默认即可)
sonar.java.binaries=. #java路径(默认接口)
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8 #字符集(默认即可)
/usr/local/sonar-scanner/bin/sonar-scanner