Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

install-server.md 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. ---
  2. title: Install the Server
  3. url: /setup/install-server/
  4. ---
  5. ## Installing the Database
  6. Several [database engines](/requirements/requirements/) are supported. Be sure to follow the requirements listed for your database, they are real requirements not recommendations.
  7. Create an empty schema and a `sonarqube` user. Grant this `sonarqube` user permissions to `create`, `update`, and `delete` objects for this schema.
  8. ### Microsoft SQL Server
  9. [[warning]]
  10. | Collation **MUST** be case-sensitive (CS) and accent-sensitive (AS).
  11. | `READ_COMMITED_SNAPSHOT` **MUST** be set on the SonarQube database.
  12. 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.
  13. Example of query to check `is_read_committed_snapshot_on`:
  14. ```
  15. SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name='YourSonarQubeDatabase';
  16. ```
  17. Example of query to update `is_read_committed_snapshot_on`:
  18. ```
  19. ALTER DATABASE YourSonarQubeDatabase SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
  20. ```
  21. #### Integrated Security
  22. To use integrated security:
  23. 1. Download the [Microsoft SQL JDBC Driver 7.2.2 package](https://www.microsoft.com/en-us/download/details.aspx?id=57782) and copy the 64-bit version of `sqljdbc_auth.dll` to any folder in your path.
  24. 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.
  25. **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.
  26. 3. Ensure that `sonar.jdbc.username` or `sonar.jdbc.password` properties are commented out or SonarQube will use SQL authentication.
  27. ```
  28. sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true
  29. ```
  30. #### SQL Authentication
  31. To use SQL Authentication, use the following connection string. Also ensure that `sonar.jdbc.username` and `sonar.jdbc.password` are set appropriately:
  32. ```
  33. sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
  34. sonar.jdbc.username=sonarqube
  35. sonar.jdbc.password=mypassword
  36. ```
  37. ### Oracle
  38. 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:
  39. - Either privileges associated to the SonarQube Oracle user should be decreased
  40. - Or a trigger should be defined on the Oracle side to automatically alter the SonarQube Oracle user session when establishing a new connection:
  41. [[warning]]
  42. | 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)).
  43. ### PostgreSQL
  44. If you want to use a custom schema and not the default "public" one, the PostgreSQL `search_path` property must be set:
  45. ```
  46. ALTER USER mySonarUser SET search_path to mySonarQubeSchema
  47. ```
  48. ## Installing the Server from the ZIP file
  49. 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).
  50. SonarQube cannot be run as `root` on Unix-based systems, so create a dedicated user account to use for SonarQube if necessary.
  51. _$SONARQUBE-HOME_ (below) refers to the path to the directory where the SonarQube distribution has been unzipped.
  52. ### Setting the Access to the Database
  53. 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:
  54. ```
  55. Example for PostgreSQL
  56. sonar.jdbc.username=sonarqube
  57. sonar.jdbc.password=mypassword
  58. sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  59. ```
  60. ### Adding the JDBC Driver
  61. Drivers for the supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported.
  62. For Oracle, copy the JDBC driver into _$SONARQUBE-HOME/extensions/jdbc-driver/oracle_.
  63. ### Configuring the Elasticsearch storage path
  64. 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.
  65. Edit _$SONARQUBE-HOME/conf/sonar.properties_ to configure the following settings:
  66. ```
  67. sonar.path.data=/var/sonarqube/data
  68. sonar.path.temp=/var/sonarqube/temp
  69. ```
  70. The user used to launch SonarQube must have read and write access to those directories.
  71. ### Starting the Web Server
  72. The default port is "9000" and the context path is "/". These values can be changed in _$SONARQUBE-HOME/conf/sonar.properties_:
  73. ```
  74. sonar.web.host=192.0.0.1
  75. sonar.web.port=80
  76. sonar.web.context=/sonarqube
  77. ```
  78. Execute the following script to start the server:
  79. - On Linux/Mac OS: bin/<YOUR OS>/sonar.sh start
  80. - On Windows: bin/windows-x86-XX/StartSonar.bat
  81. You can now browse SonarQube at _http://localhost:9000_ (the default System administrator credentials are `admin`/`admin`).
  82. ### Tuning the Web Server
  83. By default, SonarQube is configured to run on any computer with a simple Java JRE.
  84. For better performance, the first thing to do when installing a production instance is to use a Java JDK and activate the server mode by uncommenting/setting the following line in _$SONARQUBE-HOME/conf/sonar.properties_:
  85. ```
  86. sonar.web.javaOpts=-server
  87. ```
  88. To change the Java JVM used by SonarQube, simply edit _$SONARQUBE-HOME/conf/wrapper.conf_ and update the following line:
  89. ```
  90. wrapper.java.command=/path/to/my/jdk/bin/java
  91. ```
  92. ### Advanced Installation Features
  93. - Running SonarQube as a Service on [Windows](/setup/operate-server/) or [Linux](/setup/operate-server/)
  94. - Running SonarQube [behind a Proxy](/setup/operate-server/)
  95. - Running SonarQube Community Edition with [Docker](https://hub.docker.com/_/sonarqube/)
  96. ## Installing the Server from the Docker Image
  97. Click your SonarQube version below for instructions on installing the server from a Docker image.
  98. [[collapse]]
  99. | ## SonarQube 8.2+
  100. |
  101. | Follow these steps for your first installation:
  102. |
  103. | 1. Creating the following volumes helps prevent the loss of information when updating to a new version or upgrading to a higher edition:
  104. | - `sonarqube_data` – contains data files, such as the embedded H2 database and Elasticsearch indexes
  105. | - `sonarqube_logs` – contains SonarQube logs about access, web process, CE process, and Elasticsearch
  106. | - `sonarqube_extensions` – contains plugins, such as language analyzers
  107. |
  108. | Create the volumes with the following commands:
  109. | ```bash
  110. | $> docker volume create --name sonarqube_data
  111. | $> docker volume create --name sonarqube_extensions
  112. | $> docker volume create --name sonarqube_logs
  113. | ```
  114. |
  115. | 2. Configure the database with SonarQube properties using environment variables. Define these variables using the -e flag as shown in the following example:
  116. |
  117. | ```console
  118. | #Example for PostgreSQL
  119. | -e SONAR_JDBC_USERNAME=sonar \
  120. | -e SONAR_JDBC_PASSWORD=sonar \
  121. | -e SONAR.JDBC.URL=jdbc:postgresql://localhost/sonar \
  122. | ```
  123. |
  124. | For more configuration environment variables, see the [Docker Environment Variables](/setup/environment-variables/).
  125. |
  126. | [[info]]
  127. | | 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 the `sonarqube_extensions` volume.
  128. |
  129. | [[warning]]
  130. | | Use of the environment variables `SONARQUBE_JDBC_USERNAME`, `SONARQUBE_JDBC_PASSWORD`, and `SONARQUBE_JDBC_URL` is deprecated and will stop working in future releases.
  131. |
  132. | 3. Run the image:
  133. |
  134. | ```bash
  135. | $> docker run -d --name sonarqube \
  136. | -p 9000:9000 \
  137. | -e SONAR_JDBC_URL=... \
  138. | -e SONAR_JDBC_USERNAME=... \
  139. | -e SONAR_JDBC_PASSWORD=... \
  140. | -v sonarqube_data:/opt/sonarqube/data \
  141. | -v sonarqube_extensions:/opt/sonarqube/extensions \
  142. | -v sonarqube_logs:/opt/sonarqube/logs \
  143. | <image_name>
  144. | ```
  145. [[collapse]]
  146. | ## SonarQube 7.9.x LTS
  147. |
  148. | Follow these steps for your first installation:
  149. |
  150. | 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.
  151. |
  152. | ```console
  153. | $ docker run --rm \
  154. | -p 9000:9000 \
  155. | -v sonarqube_conf:/opt/sonarqube/conf \
  156. | -v sonarqube_extensions:/opt/sonarqube/extensions \
  157. | -v sonarqube_logs:/opt/sonarqube/logs \
  158. | -v sonarqube_data:/opt/sonarqube/data \
  159. | <image_name>
  160. | ```
  161. |
  162. |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.
  163. |
  164. | ```plain
  165. | #Example for PostgreSQL
  166. | -e sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
  167. | ```
  168. |
  169. |[[info]]
  170. || 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`.
  171. |
  172. |3. Run the image with your JDBC username and password :
  173. |
  174. | ```console
  175. | $ docker run -d --name sonarqube \
  176. | -p 9000:9000 \
  177. | -e sonar.jdbc.url=... \
  178. | -e sonar.jdbc.username=... \
  179. | -e sonar.jdbc.password=... \
  180. | -v sonarqube_conf:/opt/sonarqube/conf \
  181. | -v sonarqube_extensions:/opt/sonarqube/extensions \
  182. | -v sonarqube_logs:/opt/sonarqube/logs \
  183. | -v sonarqube_data:/opt/sonarqube/data \
  184. | <image_name>
  185. | ```
  186. ## Next Steps
  187. 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/).
  188. ## Troubleshooting/FAQ
  189. ### Grant more memory to the web server / compute engine / elastic search
  190. To grant more memory to a server-side process, uncomment and edit the relevant javaOpts property in `$SONARQUBE_HOME/conf/sonar.properties`, specifically:
  191. - `sonar.web.javaOpts` (minimum values: `-server -Xmx768m`)
  192. - `sonar.ce.javaOpts`
  193. - `sonar.search.javaOpts`
  194. ### Failed to start on Windows Vista
  195. SonarQube seems unable to start when installed under the `Program Files` directory on Windows Vista. It should therefore not be installed there.
  196. ### Failed to start SonarQube with Oracle due to bad `USERS` table structure
  197. When other `USERS` tables exist in the Oracle DB, if the `sonarqube` user has read access on this other `USERS` table, the SonarQube web server can't start and an exception like the following one is thrown:
  198. ```
  199. ActiveRecord::ActiveRecordError: ORA-00904: "TOTO": invalid identifier
  200. : INSERT INTO users (login, name, email, crypted_password, salt,
  201. created_at, updated_at, remember_token, remember_token_expires_at, toto, id)
  202. VALUES('admin', 'Administrator', '', 'bba4c8a0f808f9798cf8b1c153a4bb4f9178cf59', '2519754f77ea67e5d7211cd1414698f465aacebb',
  203. TIMESTAMP'2011-06-24 22:09:14', TIMESTAMP'2011-06-24 22:09:14', null, null, null, ?)
  204. ActiveRecord::ActiveRecordError: ORA-00904: "TOTO": invalid identifier
  205. : INSERT INTO users (login, name, email, crypted_password, salt,
  206. created_at, updated_at, remember_token, remember_token_expires_at, toto, id)
  207. VALUES('admin', 'Administrator', '', 'bba4c8a0f808f9798cf8b1c153a4bb4f9178cf59',
  208. '2519754f77ea67e5d7211cd1414698f465aacebb', TIMESTAMP'2011-06-24 22:09:14', TIMESTAMP'2011-06-24 22:09:14', null, null, null, ?)
  209. ```
  210. To fix this issue, the rights of the `sonarqube` Oracle user must be decreased to remove read access on the other `USERS` table(s).
  211. ### Failed to connect to the Marketplace via proxy
  212. Double check that settings for proxy are correctly set in `$SONARQUBE_HOME/conf/sonar.properties`.
  213. Note that if your proxy username contains "\" (backslash), then it should be escaped - for example username "domain\user" in file should look like:
  214. ```
  215. http.proxyUser=domain\\user
  216. ```
  217. For some proxies, the exception "java.net.ProtocolException: Server redirected too many times" might mean an incorrect username or password has been configured.
  218. ### Exception java.lang.RuntimeException: can not run elasticsearch as root
  219. 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.