You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install-server.md 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. ---
  2. title: Install the Server
  3. url: /setup/install-server/
  4. ---
  5. ## Overview
  6. This section describes a single-node SonarQube instance. For details on clustered setup, see [Install the Server as a Cluster](/setup/install-cluster/).
  7. ### Instance components
  8. A SonarQube instance comprises three components:
  9. ![SonarQube Instance Components](/images/SQ-instance-components.png)
  10. 1. The SonarQube server running the following processes:
  11. - a web server that serves the SonarQube user interface.
  12. - a search server based on Elasticsearch.
  13. - the compute engine in charge of processing code analysis reports and saving them in the SonarQube database.
  14. 2. The database to store the following:
  15. - Metrics and issues for code quality and security generated during code scans.
  16. - The SonarQube instance configuration.
  17. 3. One or more scanners running on your build or continuous integration servers to analyze projects.
  18. ### Hosts and locations
  19. For optimal performance, the SonarQube server and database should be installed on separate hosts, and the server host should be dedicated. The server and database hosts should be located in the same network.
  20. All hosts must be time-synchronized.
  21. ## Installing the database
  22. Several [database engines](/requirements/requirements/) are supported. Be sure to follow the requirements listed for your database. They are real requirements not recommendations.
  23. Create an empty schema and a `sonarqube` user. Grant this `sonarqube` user permissions to `create`, `update`, and `delete` objects for this schema.
  24. [[collapse]]
  25. | ## Microsoft SQL Server
  26. |
  27. |[[warning]]
  28. || Collation **MUST** be case-sensitive (CS) and accent-sensitive (AS).
  29. || `READ_COMMITED_SNAPSHOT` **MUST** be set on the SonarQube database.
  30. |
  31. |MS SQL database's shared lock strategy may impact SonarQube runtime. Making sure that `is_read_committed_snapshot_on` is set to `true` to prevent SonarQube from facing potential deadlocks under heavy loads.
  32. |
  33. |Example of query to check `is_read_committed_snapshot_on`:
  34. |```
  35. |SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name='YourSonarQubeDatabase';
  36. |```
  37. |Example of query to update `is_read_committed_snapshot_on`:
  38. |```
  39. |ALTER DATABASE YourSonarQubeDatabase SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
  40. |```
  41. |### Integrated Security
  42. |
  43. |To use integrated security:
  44. |
  45. |1. Download the [Microsoft SQL JDBC Auth 10.2.1 package](https://github.com/microsoft/mssql-jdbc/releases/download/v10.2.1/mssql-jdbc_auth.zip) and copy `mssql-jdbc_auth-10.2.1.x64.dll` to any folder in your path.
  46. |
  47. |2. **If you're running SonarQube as a Windows service,** make sure the Windows account under which the service is running has permission to connect your SQL server. The account should have `db_owner` database role membership.
  48. |
  49. | **If you're running the SonarQube server from a command prompt,** the user under which the command prompt is running should have `db_owner` database role membership.
  50. |
  51. |3. Ensure that `sonar.jdbc.username` or `sonar.jdbc.password` properties are commented out or SonarQube will use SQL authentication.
  52. |
  53. |```
  54. |sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true
  55. |```
  56. |
  57. |### SQL Authentication
  58. |
  59. |To use SQL Authentication, use the following connection string. Also ensure that `sonar.jdbc.username` and `sonar.jdbc.password` are set appropriately:
  60. |
  61. |```
  62. |sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
  63. |sonar.jdbc.username=sonarqube
  64. |sonar.jdbc.password=mypassword
  65. |```
  66. [[collapse]]
  67. | ## Oracle
  68. |
  69. |If there are two SonarQube schemas on the same Oracle instance, especially if they are for two different versions, SonarQube gets confused and picks the first it finds. To avoid this issue:
  70. |
  71. |- Either privileges associated to the SonarQube Oracle user should be decreased
  72. |- Or a trigger should be defined on the Oracle side to automatically alter the SonarQube Oracle user session when establishing a new connection:
  73. | `ALTER SESSION SET current_schema="MY_SONARQUBE_SCHEMA"`
  74. |
  75. |[[warning]]
  76. || Oracle JDBC driver versions 12.1.0.1 and 12.1.0.2 have major bugs, and are not recommended for use with the SonarQube ([see more details](https://groups.google.com/forum/#!msg/sonarqube/Ahqt1iarqJg/u0BVRJZnBQAJ)).
  77. [[collapse]]
  78. | ## PostgreSQL
  79. |
  80. |If you want to use a custom schema and not the default "public" one, the PostgreSQL `search_path` property must be set:
  81. |
  82. |```
  83. |ALTER USER mySonarUser SET search_path to mySonarQubeSchema
  84. |```
  85. ## Installing SonarQube from the ZIP file
  86. First, check the [requirements](/requirements/requirements/). Then download and unzip the [distribution](https://www.sonarqube.org/downloads/) (do not unzip into a directory starting with a digit).
  87. SonarQube cannot be run as `root` on Unix-based systems, so create a dedicated user account for SonarQube if necessary.
  88. _$SONARQUBE-HOME_ (below) refers to the path to the directory where the SonarQube distribution has been unzipped.
  89. ### Setting the Access to the Database
  90. Edit _$SONARQUBE-HOME/conf/sonar.properties_ to configure the database settings. Templates are available for every supported database. Just uncomment and configure the template you need and comment out the lines dedicated to H2:
  91. ```
  92. Example for PostgreSQL
  93. sonar.jdbc.username=sonarqube
  94. sonar.jdbc.password=mypassword
  95. sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  96. ```
  97. ### Adding the JDBC Driver
  98. Drivers for the supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported.
  99. For Oracle, copy the JDBC driver into _$SONARQUBE-HOME/extensions/jdbc-driver/oracle_.
  100. ### Configuring the Elasticsearch storage path
  101. By default, Elasticsearch data is stored in _$SONARQUBE-HOME/data_, but this is not recommended for production instances. Instead, you should store this data elsewhere, ideally in a dedicated volume with fast I/O. Beyond maintaining acceptable performance, doing so will also ease the upgrade of SonarQube.
  102. Edit _$SONARQUBE-HOME/conf/sonar.properties_ to configure the following settings:
  103. ```
  104. sonar.path.data=/var/sonarqube/data
  105. sonar.path.temp=/var/sonarqube/temp
  106. ```
  107. The user used to launch SonarQube must have read and write access to those directories.
  108. ### Starting the Web Server
  109. The default port is "9000" and the context path is "/". These values can be changed in _$SONARQUBE-HOME/conf/sonar.properties_:
  110. ```
  111. sonar.web.host=192.168.0.1
  112. sonar.web.port=80
  113. sonar.web.context=/sonarqube
  114. ```
  115. Execute the following script to start the server:
  116. - On Linux: bin/linux-x86-64/sonar.sh start
  117. - On macOS: bin/macosx-universal-64/sonar.sh start
  118. - On Windows: bin/windows-x86-64/StartSonar.bat
  119. You can now browse SonarQube at _http://localhost:9000_ (the default System administrator credentials are `admin`/`admin`).
  120. ### Adjusting the Java Installation
  121. By default, the scripts will use the Java executable available in the PATH.
  122. If there are multiple versions of Java installed on your server, you may need to explicitly define which version of Java is used.
  123. It is possible to overwrite the default Java executable by setting the environmental variable SONAR_JAVA_PATH
  124. #### Linux / MacOS
  125. ```
  126. export SONAR_JAVA_PATH="path/to/java_home/bin/java"
  127. ```
  128. #### Windows
  129. ```
  130. setx SONAR_JAVA_PATH "C:\Program Files\java_home\bin\java.exe"
  131. ```
  132. ### Advanced Installation Features
  133. - Running SonarQube as a Service on [Windows](/setup/operate-server/) or [Linux](/setup/operate-server/)
  134. - Running SonarQube [behind a Proxy](/setup/operate-server/)
  135. - Monitoring and adjusting [Java Process Memory](/instance-administration/monitoring/)
  136. ## Installing SonarQube from the Docker Image
  137. Follow these steps for your first installation:
  138. 1. Creating the following volumes helps prevent the loss of information when updating to a new version or upgrading to a higher edition:
  139. - `sonarqube_data` – contains data files, such as the embedded H2 database and Elasticsearch indexes
  140. - `sonarqube_logs` – contains SonarQube logs about access, web process, CE process, and Elasticsearch
  141. - `sonarqube_extensions` – will contain any plugins you install and the Oracle JDBC driver if necessary.
  142. Create the volumes with the following commands:
  143. ```bash
  144. $> docker volume create --name sonarqube_data
  145. $> docker volume create --name sonarqube_logs
  146. $> docker volume create --name sonarqube_extensions
  147. ```
  148. [[warning]]
  149. | Make sure you're using [volumes](https://docs.docker.com/storage/volumes/) as shown with the above commands, and not [bind mounts](https://docs.docker.com/storage/bind-mounts/). Using bind mounts prevents plugins from populating correctly.
  150. 2. Drivers for supported databases (except Oracle) are already provided. If you're using an Oracle database, you need to add the JDBC driver to the `sonar_extensions` volume. To do this:
  151. a. Start the SonarQube container with the embedded H2 database:
  152. ```
  153. $ docker run --rm \
  154. -p 9000:9000 \
  155. -v sonarqube_extensions:/opt/sonarqube/extensions \
  156. <image_name>
  157. ```
  158. b. Exit once SonarQube has started properly.
  159. c. Copy the Oracle JDBC driver into `sonarqube_extensions/jdbc-driver/oracle`.
  160. 3. Run the image with your database properties defined using the -e environment variable flag:
  161. ```bash
  162. $> docker run -d --name sonarqube \
  163. -p 9000:9000 \
  164. -e SONAR_JDBC_URL=... \
  165. -e SONAR_JDBC_USERNAME=... \
  166. -e SONAR_JDBC_PASSWORD=... \
  167. -v sonarqube_data:/opt/sonarqube/data \
  168. -v sonarqube_extensions:/opt/sonarqube/extensions \
  169. -v sonarqube_logs:/opt/sonarqube/logs \
  170. <image_name>
  171. ```
  172. For docker based setups, environment variables supersede all parameters that were provided with properties. See [Docker Environment Variables](/setup/environment-variables/).
  173. [[warning]]
  174. | Use of the environment variables `SONARQUBE_JDBC_USERNAME`, `SONARQUBE_JDBC_PASSWORD`, and `SONARQUBE_JDBC_URL` is deprecated and will stop working in future releases.
  175. ####**Example Docker Compose configuration**
  176. If you're using [Docker Compose](https://docs.docker.com/compose/), use the following example as a reference when configuring your `.yml` file. Click the heading below to expand the `.yml` file.
  177. [[info]]
  178. | The example below will use the latest version of the SonarQube Docker image. If want to use the LTS version of SonarQube, you need to update the example with the `sonarqube:lts-community` image tag.
  179. [[collapse]]
  180. | ## Docker Compose .yml file example
  181. |
  182. | ```
  183. | version: "3"
  184. |
  185. | services:
  186. | sonarqube:
  187. | image: sonarqube:community
  188. | depends_on:
  189. | - db
  190. | environment:
  191. | SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
  192. | SONAR_JDBC_USERNAME: sonar
  193. | SONAR_JDBC_PASSWORD: sonar
  194. | volumes:
  195. | - sonarqube_data:/opt/sonarqube/data
  196. | - sonarqube_extensions:/opt/sonarqube/extensions
  197. | - sonarqube_logs:/opt/sonarqube/logs
  198. | ports:
  199. | - "9000:9000"
  200. | db:
  201. | image: postgres:12
  202. | environment:
  203. | POSTGRES_USER: sonar
  204. | POSTGRES_PASSWORD: sonar
  205. | volumes:
  206. | - postgresql:/var/lib/postgresql
  207. | - postgresql_data:/var/lib/postgresql/data
  208. |
  209. | volumes:
  210. | sonarqube_data:
  211. | sonarqube_extensions:
  212. | sonarqube_logs:
  213. | postgresql:
  214. | postgresql_data:
  215. | ```
  216. ## Next Steps
  217. Once your server is installed and running, you may also want to [Install Plugins](/setup/install-plugin/). Then you're ready to begin [Analyzing Source Code](/analysis/overview/).
  218. ## Troubleshooting/FAQ
  219. ### Failed to connect to the Marketplace via proxy
  220. Double check that settings for proxy are correctly set in `$SONARQUBE_HOME/conf/sonar.properties`.
  221. Note that if your proxy username contains a backslash, then it should be escaped - for example username "domain\user" in file should look like:
  222. ```
  223. http.proxyUser=domain\\user
  224. ```
  225. For some proxies, the exception "java.net.ProtocolException: Server redirected too many times" might mean an incorrect username or password has been configured.
  226. ### Exception java.lang.RuntimeException: can not run elasticsearch as root
  227. SonarQube starts an Elasticsearch process, and the same account that is running SonarQube itself will be used for the Elasticsearch process. Since Elasticsearch cannot be run as `root`, that means SonarQube can't be either. You must choose some other, non-`root` account with which to run SonarQube, preferably an account dedicated to the purpose.
  228. ### Sonarqube DNS cache
  229. When reporting Quality Gate status to DevOps platforms, SonarQube uses a DNS cache time to live policy of 30 seconds. If necessary, you can change this setting in your JVM:
  230. ```bash
  231. echo "networkaddress.cache.ttl=5" >> "${JAVA_HOME}/conf/security/java.security"
  232. ```
  233. Please be aware that low values increases the risk of DNS spoofing attacks.
  234. ### Self Signed Certificates of DevOps platforms
  235. When running in an environment where the DevOps platform or other related tooling is secured by self signed certificates, the CA needs to be added to the java truststore of SonarQube.
  236. On a zip installation the systems truststore can be found in `$JAVA_HOME/lib/security/cacerts`. In order to add a new certificate to the truststore you can use the following command as an example:
  237. ```bash
  238. keytool -importcert -file $PATH_TO_CERTIFICATE -alias $CERTIFICATE_NAME -keystore /$JAVA_HOME/lib/security/cacerts -storepass changeit -trustcacerts -noprompt
  239. ```
  240. In our official Docker images you can find the systems truststore in `$JAVA_HOME/lib/security/cacerts`. In order to add new certificates here as well you can:
  241. * bind mount an existing truststore containing your certificates to `$JAVA_HOME/lib/security/cacerts`
  242. [[collapse]]
  243. | ## Example
  244. |
  245. | ```bash
  246. | docker run -d --name sonarqube -v /path/to/your/cacerts.truststore:/usr/lib/jvm/java-11-openjdk/lib/security/cacerts:ro -p 9000:9000 sonarqube
  247. | ```
  248. * import your CA certificate the same way as in the zip installation but inside the container.
  249. If you deploy SonarQube on Kubernetes using the official Helm Chart, you can create a new secret containing your required certificates and reference this via:
  250. ```yaml
  251. caCerts:
  252. enabled: true
  253. image: adoptopenjdk/openjdk11:alpine
  254. secret: your-secret
  255. ```