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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 Driver 9.2.0 package](https://docs.microsoft.com/en-us/sql/connect/jdbc/release-notes-for-the-jdbc-driver?view=sql-server-ver15#92) and copy `mssql-jdbc_auth-9.2.0.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. |
  74. |[[warning]]
  75. || 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)).
  76. [[collapse]]
  77. | ## PostgreSQL
  78. |
  79. |If you want to use a custom schema and not the default "public" one, the PostgreSQL `search_path` property must be set:
  80. |
  81. |```
  82. |ALTER USER mySonarUser SET search_path to mySonarQubeSchema
  83. |```
  84. ## Installing SonarQube from the ZIP file
  85. First, check the [requirements](/requirements/requirements/). Then download and unzip the [distribution](http://www.sonarqube.org/downloads/) (do not unzip into a directory starting with a digit).
  86. SonarQube cannot be run as `root` on Unix-based systems, so create a dedicated user account for SonarQube if necessary.
  87. _$SONARQUBE-HOME_ (below) refers to the path to the directory where the SonarQube distribution has been unzipped.
  88. ### Setting the Access to the Database
  89. 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:
  90. ```
  91. Example for PostgreSQL
  92. sonar.jdbc.username=sonarqube
  93. sonar.jdbc.password=mypassword
  94. sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  95. ```
  96. ### Adding the JDBC Driver
  97. Drivers for the supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported.
  98. For Oracle, copy the JDBC driver into _$SONARQUBE-HOME/extensions/jdbc-driver/oracle_.
  99. ### Configuring the Elasticsearch storage path
  100. 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.
  101. Edit _$SONARQUBE-HOME/conf/sonar.properties_ to configure the following settings:
  102. ```
  103. sonar.path.data=/var/sonarqube/data
  104. sonar.path.temp=/var/sonarqube/temp
  105. ```
  106. The user used to launch SonarQube must have read and write access to those directories.
  107. ### Starting the Web Server
  108. The default port is "9000" and the context path is "/". These values can be changed in _$SONARQUBE-HOME/conf/sonar.properties_:
  109. ```
  110. sonar.web.host=192.168.0.1
  111. sonar.web.port=80
  112. sonar.web.context=/sonarqube
  113. ```
  114. Execute the following script to start the server:
  115. - On Linux: bin/linux-x86-64/sonar.sh start
  116. - On macOS: bin/macosx-universal-64/sonar.sh start
  117. - On Windows: bin/windows-x86-64/StartSonar.bat
  118. You can now browse SonarQube at _http://localhost:9000_ (the default System administrator credentials are `admin`/`admin`).
  119. ### Adjusting the Java Installation
  120. If there are multiple versions of Java installed on your server, you may need to explicitly define which version of Java is used.
  121. To change the Java JVM used by SonarQube, edit _$SONARQUBE-HOME/conf/wrapper.conf_ and update the following line:
  122. ```
  123. wrapper.java.command=/path/to/my/jdk/bin/java
  124. ```
  125. ### Advanced Installation Features
  126. - Running SonarQube as a Service on [Windows](/setup/operate-server/) or [Linux](/setup/operate-server/)
  127. - Running SonarQube [behind a Proxy](/setup/operate-server/)
  128. - Monitoring and adjusting [Java Process Memory](/instance-administration/monitoring/)
  129. ## Installing SonarQube from the Docker Image
  130. See your SonarQube version below for instructions on installing the server from a Docker image.
  131. ### SonarQube 8.2+
  132. Follow these steps for your first installation:
  133. 1. Creating the following volumes helps prevent the loss of information when updating to a new version or upgrading to a higher edition:
  134. - `sonarqube_data` – contains data files, such as the embedded H2 database and Elasticsearch indexes
  135. - `sonarqube_logs` – contains SonarQube logs about access, web process, CE process, and Elasticsearch
  136. - `sonarqube_extensions` – will contain any plugins you install and the Oracle JDBC driver if necessary.
  137. Create the volumes with the following commands:
  138. ```bash
  139. $> docker volume create --name sonarqube_data
  140. $> docker volume create --name sonarqube_logs
  141. $> docker volume create --name sonarqube_extensions
  142. ```
  143. [[warning]]
  144. | 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.
  145. 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:
  146. a. Start the SonarQube container with the embedded H2 database:
  147. ```
  148. $ docker run --rm \
  149. -p 9000:9000 \
  150. -v sonarqube_extensions:/opt/sonarqube/extensions \
  151. <image_name>
  152. ```
  153. b. Exit once SonarQube has started properly.
  154. c. Copy the Oracle JDBC driver into `sonarqube_extensions/jdbc-driver/oracle`.
  155. 3. Run the image with your database properties defined using the -e environment variable flag:
  156. ```bash
  157. $> docker run -d --name sonarqube \
  158. -p 9000:9000 \
  159. -e SONAR_JDBC_URL=... \
  160. -e SONAR_JDBC_USERNAME=... \
  161. -e SONAR_JDBC_PASSWORD=... \
  162. -v sonarqube_data:/opt/sonarqube/data \
  163. -v sonarqube_extensions:/opt/sonarqube/extensions \
  164. -v sonarqube_logs:/opt/sonarqube/logs \
  165. <image_name>
  166. ```
  167. For more configuration environment variables, see the [Docker Environment Variables](/setup/environment-variables/).
  168. [[warning]]
  169. | Use of the environment variables `SONARQUBE_JDBC_USERNAME`, `SONARQUBE_JDBC_PASSWORD`, and `SONARQUBE_JDBC_URL` is deprecated and will stop working in future releases.
  170. ####**Example Docker Compose configuration**
  171. 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.
  172. [[collapse]]
  173. | ## Docker Compose .yml file example
  174. |
  175. | ```
  176. | version: "3"
  177. |
  178. | services:
  179. | sonarqube:
  180. | image: sonarqube:community
  181. | depends_on:
  182. | - db
  183. | environment:
  184. | SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
  185. | SONAR_JDBC_USERNAME: sonar
  186. | SONAR_JDBC_PASSWORD: sonar
  187. | volumes:
  188. | - sonarqube_data:/opt/sonarqube/data
  189. | - sonarqube_extensions:/opt/sonarqube/extensions
  190. | - sonarqube_logs:/opt/sonarqube/logs
  191. | ports:
  192. | - "9000:9000"
  193. | db:
  194. | image: postgres:12
  195. | environment:
  196. | POSTGRES_USER: sonar
  197. | POSTGRES_PASSWORD: sonar
  198. | volumes:
  199. | - postgresql:/var/lib/postgresql
  200. | - postgresql_data:/var/lib/postgresql/data
  201. |
  202. | volumes:
  203. | sonarqube_data:
  204. | sonarqube_extensions:
  205. | sonarqube_logs:
  206. | postgresql:
  207. | postgresql_data:
  208. | ```
  209. ### SonarQube 7.9.x LTS
  210. Follow these steps for your first installation:
  211. 1. Create volumes `sonarqube_conf`, `sonarqube_data`, `sonarqube_logs`, and `sonarqube_extensions` and start the image with the following command. This will populate all the volumes (copying default plugins, create the Elasticsearch data folder, create the sonar.properties configuration file). Watch the logs, and, once the container is properly started, you can force-exit (ctrl+c) and proceed to the next step.
  212. ```console
  213. $ docker run --rm \
  214. -p 9000:9000 \
  215. -v sonarqube_conf:/opt/sonarqube/conf \
  216. -v sonarqube_extensions:/opt/sonarqube/extensions \
  217. -v sonarqube_logs:/opt/sonarqube/logs \
  218. -v sonarqube_data:/opt/sonarqube/data \
  219. <image_name>
  220. ```
  221. 2. Configure sonar.properties if needed. Please note that due to [SONAR-12501](https://jira.sonarsource.com/browse/SONAR-12501), providing `sonar.jdbc.url`, `sonar.jdbc.username`, `sonar.jdbc.password` and `sonar.web.javaAdditionalOpts` in `sonar.properties` is not working, and you will need to explicitly define theses values in the docker run command with the `-e` flag.
  222. ```plain
  223. #Example for PostgreSQL
  224. -e sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  225. ```
  226. [[info]]
  227. | Drivers for supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported. For Oracle, you need to copy the JDBC driver into `$SONARQUBE_HOME/extensions/jdbc-driver/oracle`.
  228. 3. Run the image with your JDBC username and password :
  229. ```console
  230. $ docker run -d --name sonarqube \
  231. -p 9000:9000 \
  232. -e sonar.jdbc.url=... \
  233. -e sonar.jdbc.username=... \
  234. -e sonar.jdbc.password=... \
  235. -v sonarqube_conf:/opt/sonarqube/conf \
  236. -v sonarqube_extensions:/opt/sonarqube/extensions \
  237. -v sonarqube_logs:/opt/sonarqube/logs \
  238. -v sonarqube_data:/opt/sonarqube/data \
  239. <image_name>
  240. ```
  241. ## Next Steps
  242. 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/).
  243. ## Troubleshooting/FAQ
  244. ### Failed to connect to the Marketplace via proxy
  245. Double check that settings for proxy are correctly set in `$SONARQUBE_HOME/conf/sonar.properties`.
  246. Note that if your proxy username contains a backslash, then it should be escaped - for example username "domain\user" in file should look like:
  247. ```
  248. http.proxyUser=domain\\user
  249. ```
  250. For some proxies, the exception "java.net.ProtocolException: Server redirected too many times" might mean an incorrect username or password has been configured.
  251. ### Exception java.lang.RuntimeException: can not run elasticsearch as root
  252. 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.
  253. ### Sonarqube fails to decorate merge requests when DNS entry to ALM changes
  254. If you run SonarQube in an environment with a lot of DNS friction, you should define a DNS cache time to live policy as, by default, SonarQube will hold the DNS cache until it is restarted. You can set this policy to five seconds by doing the following:
  255. ```bash
  256. echo "networkaddress.cache.ttl=5" >> "${JAVA_HOME}/conf/security/java.security"
  257. ```
  258. Please be aware that this increases the risk of DNS spoofing attacks.