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.

operate-server.md 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ---
  2. title: Operating the Server
  3. url: /setup/operate-server/
  4. ---
  5. ## Running SonarQube as a Service on Windows
  6. ### Install or Uninstall NT Service (may have to run these files via Run As Administrator):
  7. ```
  8. %SONARQUBE_HOME%/bin/windows-x86-64/InstallNTService.bat
  9. %SONARQUBE_HOME%/bin/windows-x86-64/UninstallNTService.bat
  10. ```
  11. ### Start or Stop the Service:
  12. ```
  13. %SONARQUBE_HOME%/bin/windows-x86-64/StartNTService.bat
  14. %SONARQUBE_HOME%/bin/windows-x86-64/StopNTService.bat
  15. ```
  16. **Note:** `%SONARQUBE_HOME%/bin/windows-x86-64/StopNTService.bat` does a graceful shutdown where no new analysis report processing can start, but the tasks in progress are allowed to finish. The time a stop will take depends on the processing time of the tasks in progress. You'll need to kill all SonarQube processes manually to force a stop.
  17. ## Running SonarQube Manually on Linux
  18. ### Start or Stop the Instance
  19. ```
  20. Start:
  21. $SONAR_HOME/bin/linux-x86-64/sonar.sh start
  22. Graceful shutdown:
  23. $SONAR_HOME/bin/linux-x86-64/sonar.sh stop
  24. Hard stop:
  25. $SONAR_HOME/bin/linux-x86-64/sonar.sh force-stop
  26. ```
  27. **Note:** Stop does a graceful shutdown where no new analysis report processing can start, but the tasks in progress are allowed to finish. The time a stop will take depends on the processing time of the tasks in progress. Use force stop for a hard stop.
  28. ## Running SonarQube as a Service on Linux with SystemD
  29. On a Unix system using SystemD, you can install SonarQube as a service. You cannot run SonarQube as `root` in 'nix systems. Ideally, you will created a new account dedicated to the purpose of running SonarQube.
  30. Let's suppose:
  31. * The user used to start the service is `sonarqube`
  32. * The group used to start the service is `sonarqube`
  33. * The Java Virtual Machine is installed in `/opt/java/`
  34. * SonarQube has been unzipped into `/opt/sonarqube/`
  35. Then create the file `/etc/systemd/system/sonarqube.service` _based on_ the following
  36. ```
  37. [Unit]
  38. Description=SonarQube service
  39. After=syslog.target network.target
  40. [Service]
  41. Type=simple
  42. User=sonarqube
  43. Group=sonarqube
  44. PermissionsStartOnly=true
  45. ExecStart=/bin/nohup /opt/java/bin/java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-7.4.jar
  46. StandardOutput=syslog
  47. LimitNOFILE=65536
  48. LimitNPROC=8192
  49. TimeoutStartSec=5
  50. Restart=always
  51. SuccessExitStatus=143
  52. [Install]
  53. WantedBy=multi-user.target
  54. ```
  55. **Note**
  56. * Because the sonar-application jar name ends with the version of SonarQube, you will need to adjust the `ExecStart` command accordingly on install and at each upgrade.
  57. * The SonarQube data directory, `/opt/sonarqube/data`, and the extensions directory, `/opt/sonarqube/extensions` should be owned by the `sonarqube` user. As a good practice, the rest should be owned by `root`
  58. Once your `sonarqube.service` file is created and properly configured, run:
  59. ```
  60. sudo systemctl enable sonarqube.service
  61. sudo systemctl start sonarqube.service
  62. ```
  63. ## Running SonarQube as a Service on Linux with initd
  64. The following has been tested on Ubuntu 8.10 and CentOS 6.2.
  65. Create the file /etc/init.d/sonar with this content:
  66. ```
  67. #!/bin/sh
  68. #
  69. # rc file for SonarQube
  70. #
  71. # chkconfig: 345 96 10
  72. # description: SonarQube system (www.sonarsource.org)
  73. #
  74. ### BEGIN INIT INFO
  75. # Provides: sonar
  76. # Required-Start: $network
  77. # Required-Stop: $network
  78. # Default-Start: 3 4 5
  79. # Default-Stop: 0 1 2 6
  80. # Short-Description: SonarQube system (www.sonarsource.org)
  81. # Description: SonarQube system (www.sonarsource.org)
  82. ### END INIT INFO
  83. /usr/bin/sonar $*
  84. ```
  85. Register SonarQube at boot time (RedHat, CentOS, 64 bit):
  86. ```
  87. sudo ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar
  88. sudo chmod 755 /etc/init.d/sonar
  89. sudo chkconfig --add sonar
  90. ```
  91. Once registration is done, run:
  92. ```
  93. sudo service sonar start
  94. ```
  95. ## Securing the Server Behind a Proxy
  96. This section helps you configure the SonarQube Server if you want to run it behind a proxy. This can be done for security concerns or to consolidate multiple disparate applications.
  97. ### Server Configuration
  98. To run the SonarQube server over HTTPS, you must build a standard reverse proxy infrastructure.
  99. The reverse proxy must be configured to set the value `X_FORWARDED_PROTO: https` in each HTTP request header. Without this property, redirection initiated by the SonarQube server will fall back on HTTP.
  100. ### Using an Apache Proxy
  101. We assume that you've already installed Apache 2 with module mod_proxy, that SonarQube is running and available on `http://private_sonar_host:sonar_port/` and that you want to configure a Virtual Host for `www.public_sonar.com`.
  102. At this point, edit the HTTPd configuration file for the `www.public_sonar.com` virtual host. Include the following to expose SonarQube via `mod_proxy` at `http://www.public_sonar.com/`:
  103. ```
  104. ProxyRequests Off
  105. ProxyPreserveHost On
  106. <VirtualHost *:80>
  107. ServerName www.public_sonar.com
  108. ServerAdmin admin@somecompany.com
  109. ProxyPass / http://private_sonar_host:sonar_port/
  110. ProxyPassReverse / http://www.public_sonar.com/
  111. ErrorLog logs/somecompany/sonar/error.log
  112. CustomLog logs/somecompany/sonar/access.log common
  113. </VirtualHost>
  114. ```
  115. Apache configuration is going to vary based on your own application's requirements and the way you intend to expose SonarQube to the outside world. If you need more details about Apache HTTPd and mod_proxy, please see [http://httpd.apache.org](http://httpd.apache.org).
  116. ### Using Nginx
  117. We assume that you've already installed Nginx, that you are using a Virtual Host for www.somecompany.com and that SonarQube is running and available on `http://sonarhost:sonarport/`.
  118. At this point, edit the Nginx configuration file. Include the following to expose SonarQube at http://www.somecompany.com/:
  119. ```
  120. # the server directive is nginx's virtual host directive
  121. server {
  122. # port to listen on. Can also be set to an IP:PORT
  123. listen 80;
  124. # sets the domain[s] that this vhost server requests for
  125. server_name www.somecompany.com;
  126. location / {
  127. proxy_pass http://sonarhost:sonarport;
  128. }
  129. }
  130. ```
  131. Nginx configuration will vary based on your own application's requirements and the way you intend to expose SonarQube to the outside world. If you need more details about Nginx, please see [https://www.nginx.com/resources/admin-guide/reverse-proxy/](https://www.nginx.com/resources/admin-guide/reverse-proxy/).
  132. Note that you may need to increase the max URL length since SonarQube requests can have URLs longer than 2048.
  133. ### Using IIS
  134. Please see: [http://blog.jessehouwing.nl/2016/02/configure-ssl-for-sonarqube-on-windows.html](http://blog.jessehouwing.nl/2016/02/configure-ssl-for-sonarqube-on-windows.html)
  135. Note that the setup described in this blog post is not approprite for SAML through IIS.
  136. <!-- /sonarqube -->