ERROR: Sonar server 'http://localhost:9000' can not be reached
Asked Answered
V

11

65

when running the following command: cmd /c C:\sonar-runner-2.4\bin\sonar-runner.bat

(sonar runner is installed on the build machine) i get the following errors:
ERROR: Sonar server 'http://localhost:9000' can not be reached
ERROR: Error during Sonar runner execution
ERROR: java.net.ConnectException: Connection refused: connect
ERROR: Caused by: Connection refused: connect

what can cause these errors?

Hi dinesh,

this is my sonar-runner.properties file:

sonar.projectKey=NDM
sonar.projectName=NDM
sonar.projectVersion=1.0

sonar.visualstudio.solution=NDM.sln

#sonar.sourceEncoding=UTF-8
sonar.web.host:sonarqube
sonar.web.port=9000

# Enable the Visual Studio bootstrapper
sonar.visualstudio.enable=true

# Unit Test Results
sonar.cs.vstest.reportsPaths=TestResults/*.trx

# Required only when using SonarQube < 4.2
sonar.language=cs

sonar.sources=.

As you can see i set the sonar.web.host:sonarqube sonar.web.port=9000 but when i run sonar-runner.bat i still get the
ERROR: Sonar server 'http://localhost:9000' can not be reached - why is it still looking for localhost:9000
and not sonarqube:9000 as i set?

i saw that in the log of sonar-runner.bat there the following line: INFO: Work directory: D:\sTFS\26091\Sources\NDM\Source..sonar

while my solution is in D:\sTFS\26091\Sources\NDM\Source\

could this be the problem?

thanks, Guy

Verdure answered 19/8, 2015 at 13:48 Comment(3)
I guess you checked the most obvious question. Can you open localhost:9000 in your browser? Could you give some additional information about your setup?Insensibility
no i can't open localhost:9000 in my browser. what can be the reason for that?Verdure
You need to look at the sonar log. I am sure it shows an error and the server doesn't start. If it starts than it doesn't use port 9000. Make sure you can reach the sonar web interface, than this problem should be solved too.Insensibility
S
59

If you use SonarScanner CLI with Docker, you may have this error because the SonarScanner container can not access to the Sonar UI container.

Note that you will have the same error with a simple curl from another container:

docker run --rm byrnedo/alpine-curl 127.0.0.1:9000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

The solution is to connect the SonarScanner container to the same docker network of your sonar instance, for instance with --network=host:

docker run --network=host -e SONAR_HOST_URL='http://127.0.0.1:9000' --user="$(id -u):$(id -g)" -v "$PWD:/usr/src" sonarsource/sonar-scanner-cli

(other parameters of this command comes from the SonarScanner CLI documentation)

Salmonella answered 3/12, 2019 at 19:9 Comment(0)
G
20

I got the same issue, and I changed to IP and it working well

Go to System References --> Network --> Advanced --> Open TCP/IP tabs --> copy the IPv4 Address.

change that IP instead localhost

Hope this can help

Greige answered 5/3, 2020 at 11:52 Comment(0)
O
11

You should configure the sonar-runner to use your existing SonarQube server. To do so, you need to update its conf/sonar-runner.properties file and specify the SonarQube server URL, username, password, and JDBC URL as well. See https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner for details.

If you don't yet have an up and running SonarQube server, then you can launch one locally (with the default configuration) - it will bind to http://localhost:9000 and work with the default sonar-runner configuration. See https://docs.sonarqube.org/latest/setup/get-started-2-minutes/ for details on how to get started with the SonarQube server.

Overexpose answered 20/8, 2015 at 7:55 Comment(3)
The page doesn't exist: docs.sonarqube.org/display/SONAR/…Weinreb
Thank you @SrishtiSinha, I've just fixed the broken links.Overexpose
That link doesn't work either.Kalidasa
G
6

For others who ran into this issue in a project that is not using a sonar-runners.property file, you may find (as I did) that you need to tweak your pom.xml file, adding a sonar.host.url property.

For example, I needed to add the following line under the 'properties' element:

<sonar.host.url>https://sonar.my-internal-company-domain.net</sonar.host.url>

Where the url points to our internal sonar deployment.

Geraldgeralda answered 29/11, 2018 at 17:8 Comment(1)
This was they way to go for me. Seems I forgot to set the path to our company's Sonar Server. Thanks Adam!Thoron
B
3

For me the issue was that the maven sonar plugin was using proxy servers defined in the maven settings.xml. I was trying to access the sonarque on another (not localhost alias) and so it was trying to use the proxy server to access it. Just added my alias to nonProxyHosts in settings.xml and it is working now. I did not face this issue in maven sonar plugin 3.2, only after i upgraded it.

<proxy>
  <id>proxy_id</id>
  <active>true</active>
  <protocol>http</protocol>
  <host>your-proxy-host/host>
  <port>your-proxy-host</port>
  <nonProxyHosts>localhost|127.0.*|other-non-proxy-hosts</nonProxyHosts>
</proxy>enter code here
Boote answered 20/9, 2019 at 12:30 Comment(0)
R
2

In the config file there is a colon instead of an equal sign after the sonar.web.host.

Is:

sonar.web.host:sonarqube

Should be

sonar.web.host=sonarqube
Rickettsia answered 9/3, 2017 at 15:4 Comment(0)
R
2

The issue occurred with me in a different way a little a while ago,
I had a docker container running normally in the main network of my host machine accessible via the browser on the normal localhost:9000. But whenever the scanner wants to connect to the server it couldn't despite being on the same network of the host.

  • I made sure they are, because on the docker run command I mentioned --network=bridge

So the trick was that I pointed to the actual local ip of mine instead of just writing localhost
you can know the ip of your machine by typing ipconfig on windows or ifconfig on linux

so on the scan docker run command I have pointed to the server like that -Dsonar.host.url=http://192.168.1.2:9000 where 192.168.1.2 is my local host address

That was my final docker commands to run the Server:

docker run -d --name sonarqube \
    --network=bridge \
    -p 9000:9000 \
    -e SONAR_JDBC_USERNAME=<db username> \
    -e SONAR_JDBC_PASSWORD=<db password>\
    -v sonarqube_data:/opt/sonarqube/data \
    -v sonarqube_extensions:/opt/sonarqube/extensions \
    -v sonarqube_logs:/opt/sonarqube/logs \
    sonarqube:community

and that's for the Scanner:

docker run \
    --network=bridge \
    -v "<local path of the project to scan>:/usr/src" sonarsource/sonar-scanner-cli \
    -Dsonar.projectKey=<project key> \
    -Dsonar.sources=. \
    -Dsonar.host.url=http://<local-ip>:9000 \
    -Dsonar.login=<token>
Ruffianism answered 25/11, 2021 at 10:36 Comment(0)
E
0

In sonar.properties file in conf folder I had hardcoaded ip of my machine where sobarqube was installed in property sonar.web.host=10.9 235.22 I commented this and it started working for me.

Eradicate answered 11/5, 2017 at 6:2 Comment(0)
B
0

Please check if postgres(or any other database service) is running properly.

Breadth answered 18/2, 2020 at 7:16 Comment(0)
D
0

Late to the party, but to share my experience, I was trying to install SonarQube 10.4 from a zip file in Ubuntu 23.10 and port 9000 wasn't listening, my error was to install default openjdk which was 22 and I needed exactly openjdk 17, after this, port 9000 was binding and everything worked.

Decemvir answered 19/3 at 15:30 Comment(0)
G
-1

When you allow the 9000 port to firewall on your desired operating System the following error "ERROR: Sonar server 'http://localhost:9000' can not be reached" will remove successfully.In ubuntu it is just like as by typing the following command in terminal "sudo ufw allow 9000/tcp" this error will removed from the Jenkins server by clicking on build now in jenkins.

Guillerminaguillermo answered 15/4, 2019 at 13:25 Comment(1)
Please try to elaborate what that image means.Pfennig

© 2022 - 2024 — McMap. All rights reserved.