hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.25k stars 4.41k forks source link

UI not starting with ui_dir in config file #166

Closed bscott closed 10 years ago

bscott commented 10 years ago

I cannot get the UI to start using the ui_dir directive in the config file, only via as a command line flag.

ryanuber commented 10 years ago

@bscott can you show us what the config looks like? Specifying ui as the ui_dir seems to work as expected, as well as specifying an absolute path.

bscott commented 10 years ago

{ "bind_addr": "x.x.x.x", "bootstrap": false, "datacenter": "us-west-1.compute.internal", "data_dir": "/var/lib/consul", "log_level": "INFO", "node_name": "ip-1-1-1-3", "server": true, "start_join": [], "ui_dir": "/opt/consul/ui" }

armon commented 10 years ago

@bscott When you hit the index page (http://localhost:8500/) what do you get? Does it say "Consul Agent" or do a redirect?

Also unrelated, but you will run into issues if you datacenter has periods in it. It makes the DNS parsing ambiguous. Instead, you might try making the datacenter "us-west-1", and if you want, set the domain to "compute.internal".

bscott commented 10 years ago

@armon The node isn't even listening on port 8500

armon commented 10 years ago

The default listen port for HTTP is 8500 unless configured otherwise. Is the agent even starting?

bscott commented 10 years ago

@armon Yes, the agent is starting and joining the cluster.

armon commented 10 years ago

So when it starts, it should log the HTTP port. Can you try to curl port it is logging? Based on the response we can determine if it is loading the UI.

webcoyote commented 10 years ago

I'm able to get the UI working on Linux, but not on Windows (version 0.2.1). Here's the output from curl:

Windows:

c:\>curl 127.0.0.1:8500/ -v
* About to connect() to 127.0.0.1 port 8500 (#0)
*   Trying 127.0.0.1...
* Adding handle: conn: 0x4c2d38
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x4c2d38) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 8500 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: 127.0.0.1:8500
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 28 May 2014 00:20:33 GMT
< Content-Length: 12
< Content-Type: text/plain; charset=utf-8
<
Consul Agent* Connection #0 to host 127.0.0.1 left intact

^^^ No redirect

Linux:

~$ curl localhost:8500/ -v                                                                                                 
* About to connect() to localhost port 8500 (#0)
*   Trying 127.0.0.1... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8500
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Location: /ui/
< Date: Wed, 28 May 2014 00:16:20 GMT
< Content-Length: 39
< Content-Type: text/html; charset=utf-8
< 
<a href="/ui/">Moved Permanently</a>.

* Connection #0 to host localhost left intact
* Closing connection #0

^^^ Provides a redirect to /ui/

Incidentally I've tried several forms of path in the consul json configuration file on Windows and none appear to work:

"ui_dir": "./ui"
"ui_dir": ".\\ui"
"ui_dir": "C:\\consul\\ui"
"ui_dir": "C:/consul/ui"

I hope that helps you track down the problem.

bscott commented 10 years ago

Hey guys,

I'll respond shortly , traveling at the moment.

On Tuesday, May 27, 2014, Patrick Wyatt notifications@github.com wrote:

I'm able to get the UI working on Linux, but not on Windows. Here's the output from curl:

Windows:

c:>curl 127.0.0.1:8500/ -v

  • About to connect() to 127.0.0.1 port 8500 (#0)
  • Trying 127.0.0.1...
  • Adding handle: conn: 0x4c2d38
  • Adding handle: send: 0
  • Adding handle: recv: 0
  • Curl_addHandleToPipeline: length: 1
  • - Conn 0 (0x4c2d38) send_pipe: 1, recv_pipe: 0
  • Connected to 127.0.0.1 (127.0.0.1) port 8500 (#0)

    GET / HTTP/1.1 User-Agent: curl/7.30.0 Host: 127.0.0.1:8500 Accept: /

    < HTTP/1.1 200 OK < Date: Wed, 28 May 2014 00:20:33 GMT < Content-Length: 12 < Content-Type: text/plain; charset=utf-8 < Consul Agent* Connection #0 to host 127.0.0.1 left intact

^^^ No redirect

Linux:

~$ curl localhost:8500/ -v

  • About to connect() to localhost port 8500 (#0)
  • Trying 127.0.0.1... connected

    GET / HTTP/1.1 User-Agent: curl/7.22.0 (x8664-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 Host: localhost:8500 Accept: /_

    < HTTP/1.1 301 Moved Permanently < Location: /ui/ < Date: Wed, 28 May 2014 00:16:20 GMT < Content-Length: 39 < Content-Type: text/html; charset=utf-8 < Moved Permanently.

  • Connection #0 to host localhost left intact
  • Closing connection #0

^^^ Provides a redirect to /ui/

Incidentally I've tried several forms of path in the consul json configuration file on Windows and none appear to work:

"ui_dir": "./ui" "ui_dir": ".\ui" "ui_dir": "C:\consul\ui" "ui_dir": "C:/consul/ui"

I hope that helps you track down the problem.

— Reply to this email directly or view it on GitHubhttps://github.com/hashicorp/consul/issues/166#issuecomment-44352191 .

Brian Scott - DevOps and Automation Guy, Ruby/Rails Guy, all around Good Guy. Email: brainscott@gmail.com / b@bscott.me Github: http://github.com/bscott http://github.com/bscott

armon commented 10 years ago

@webcoyote Can you verify if this is happening with the latest build? Might be the same issue of running the older Consul build.

webcoyote commented 10 years ago

@armon: The UI >does< work on Windows when I compiled the latest version from source (re: https://github.com/hashicorp/consul/issues/177#issuecomment-44442962).

bscott commented 10 years ago

I'm still having this issue on latest build with Linux, but I'll test again.

armon commented 10 years ago

Closing. Please re-open if still an issue.

calvn commented 8 years ago

I am encountering this issue. I Can enable the UI on the servers. However on a consul client, requests to http://localhost:8500 and http://localhost:8500/ui/ gives me a 301. Running Consul 0.5.2. on all nodes.

$ curl -v http://127.0.0.1:8500
* Rebuilt URL to: http://127.0.0.1:8500/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8500 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8500
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Location: /ui/
< Date: Fri, 20 Nov 2015 22:24:56 GMT
< Content-Length: 39
< Content-Type: text/html; charset=utf-8
< 
<a href="/ui/">Moved Permanently</a>.

* Connection #0 to host 127.0.0.1 left intact

The config.json on the client:

{
        "data_dir": "/var/lib/consul",
        "datacenter": "qas",
        "log_level": "INFO",
        "start_join": [<servers>],
        "ui_dir": "/var/lib/consul/ui/dist"
}

Removed start_join servers, but consul members is able to give me back a list of members. Nothing suspicious in the consul logs either, all logs are INFO.

slackpad commented 8 years ago

Hi @cleung2010 - there's no difference in the client vs. server code path that I can see for the server. If you do a curl http://localhost:8500/v1/agent/self?pretty does your UiDir look correctly configured in there? Is it possible you've got another JSON file that's stomping on the one above?

calvn commented 8 years ago

"DataDir": "/var/lib/consul", "UiDir": "/var/lib/consul/ui/dist"

$ ls -lha /var/lib/consul/ui/dist
total 40K
drwxr-xr-x 3 root root 4.0K May 12  2015 .
drwxr-xr-x 3 root root 4.0K Nov 20 22:14 ..
-rw-r--r-- 1 root root    0 May  1  2014 .gitkeep
-rw-r--r-- 1 root root  28K May 12  2015 index.html
drwxr-xr-x 2 root root 4.0K May 12  2015 static
$ ls -lha /etc/consul/
total 12K
drwxr-xr-x  2 root root 4.0K Nov 20 22:14 .
drwxr-xr-x 94 root root 4.0K Nov 20 22:14 ..
-rw-r--r--  1 root root  332 Nov 20 22:14 config.json
slackpad commented 8 years ago

Actually - I get a 301 when running that curl command locally as well. It kicks you over to the /ui/ page which should serve up index.html. If you tell curl to follow the redirect it should work - curl -L -v http://127.0.0.1:8500.

calvn commented 8 years ago

I get a 200, but the response contains this:

<p>This is an error page for the Consul web UI. You may have visited a URL that is loading an
unknown resource, so you can try going back to the <a href="#">root</a>.</p>

When I curl -v http://127.0.0.1:8500 on the server nodes I get a 200 and Consul Agent on the response

slackpad commented 8 years ago

Hmm - that's actually part of the static index.html page - so it looks like that might be getting served up properly by Consul's web server:

https://github.com/hashicorp/consul/blob/master/ui/index.html#L44-L45

When I curl -v http://127.0.0.1:8500 on the server nodes I get a 200 and Consul Agent on the response

I don't follow what you mean by "Consul Agent on the response" there. Is that not serving up the same index.html?

hridyeshpant commented 8 years ago

i am also getting same issue

HTTP error code from Consul: 0 error This is an error page for the Consul web UI. You may have visited a URL that is loading an unknown resource, so you can try going back to the root.

inside the host => curl http://localhost:8500/ui/

  • Hostname was NOT found in DNS cache
  • Trying 127.0.0.1...
  • connect to 127.0.0.1 port 8500 failed: Connection refused
  • Failed to connect to localhost port 8500: Connection refused
  • Closing connection 0 curl: (7) Failed to connect to localhost port 8500: Connection refused

but when running same command "curl http://localhost:8500/ui/" inside the container , i am getting valid output.

docker ps output in host =>

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ebfb17a2b580 server "/bin/consul agent -s" 2 minutes ago Up 2 minutes 0.0.0.0:8300-8302->8300-8302/tcp, 0.0.0.0:8400->8400/tcp, 0.0.0.0:8500->8500/tcp, 0.0.0.0:8301-8302->8301-8302/udp, 8600/tcp, 8600/udp, 0.0.0.0:8600->53/udp elegant_panini

Inside the container =>

bash-4.3# ps PID USER TIME COMMAND 1 root 0:01 /bin/consul agent -server -config-dir=/config -bootstrap -ui-dir=/ui

ls -ltr /ui total 32 drwxr-xr-x 2 root root 4096 Nov 22 05:36 static -rw-r--r-- 1 root root 28045 Nov 22 05:36 index.html

calvn commented 8 years ago

@slackpad I mean this:

$ curl -v localhost:8500
* Rebuilt URL to: localhost:8500/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8500 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8500
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 23 Nov 2015 17:45:24 GMT
< Content-Length: 12
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact
Consul Agent

I also get a 200 and the same response on the body of the client if I do not specify ui_dir. However, as soon as I enable it I get a 301 on both the root and /ui endpoints. Why does root / redirect to /ui, is that intended or is that a side-effect on some misconfiguration on my part?

calvn commented 8 years ago

Noticed that curl -v -L localhost:8500/ serves index.html but it's still in template form, meaning that it's not parsed before being rendered:

<button {{ action "reset" }} {{ bind-attr class=":btn :btn-danger" }}>Reset Defaults</button>

The security group on AWS allows TCP inbound connection from 0.0.0.0/0 to 8500. Networking seems fine too.

$ sudo lsof -i :8500
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
consul  3777 consul    8u  IPv4  17365      0t0  TCP localhost:8500 (LISTEN)
$ sudo iptables -L -nv
Chain INPUT (policy ACCEPT 16638 packets, 1674K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 14625 packets, 2196K bytes)
 pkts bytes target     prot opt in     out     source               destination         
$ netstat -natlp
(No info could be read for "-p": geteuid()=1001 but you should be root.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:8600          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:40267           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:8400          0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:8500          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:53              0.0.0.0:*               LISTEN      -               
tcp        0      0 10.66.30.190:38856      10.66.12.149:8300       TIME_WAIT   -               
tcp        0    476 10.66.30.190:22         10.87.65.5:51004        ESTABLISHED -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 :::8301                 :::*                    LISTEN      -               
tcp6       0      0 :::111                  :::*                    LISTEN      -               
tcp6       0      0 :::46644                :::*                    LISTEN      -               
tcp6       0      0 :::53                   :::*                    LISTEN      -    
calvn commented 8 years ago

@slackpad @hridyeshpant Got it working by adding this to my config.json:

{
    "addresses": {
        "http": "0.0.0.0"
    },
...
}

As explained in #599 the client binds the HTTP address to localhost by default so within the client you're able to curl the /ui endpoint, but you'll just get connection refused if you try to resolve it from the outside.

I'd suggest to update the docs on the Web-UI page so that it explicitly states that the default config only enables the UI within localhost.

hridyeshpant commented 8 years ago

@cleung2010 it is not working for me . i am running consul in local box and trying to access in same box.

docker run test -bootstrap -ui-dir /ui ==> WARNING: Bootstrap mode enabled! Do not enable unless necessary ==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1 ==> Starting Consul agent... ==> Starting Consul agent RPC... ==> Consul agent running! Node name: '200d4ea560f4' Datacenter: 'dc1' Server: true (bootstrap: true) Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400) Cluster Addr: 172.17.0.12 (LAN: 8301, WAN: 8302) Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false Atlas:

Log data will now stream in as it occurs:

2015/12/17 14:47:53 [INFO] serf: EventMemberJoin: 200d4ea560f4 172.17.0.12
2015/12/17 14:47:53 [INFO] serf: EventMemberJoin: 200d4ea560f4.dc1 172.17.0.12
2015/12/17 14:47:53 [INFO] raft: Node at 172.17.0.12:8300 [Follower] entering Follower state
2015/12/17 14:47:53 [INFO] consul: adding server 200d4ea560f4 (Addr: 172.17.0.12:8300) (DC: dc1)
2015/12/17 14:47:53 [INFO] consul: adding server 200d4ea560f4.dc1 (Addr: 172.17.0.12:8300) (DC: dc1)
2015/12/17 14:47:53 [ERR] agent: failed to sync remote state: No cluster leader
2015/12/17 14:47:55 [WARN] raft: Heartbeat timeout reached, starting election
2015/12/17 14:47:55 [INFO] raft: Node at 172.17.0.12:8300 [Candidate] entering Candidate state
2015/12/17 14:47:55 [INFO] raft: Election won. Tally: 1
2015/12/17 14:47:55 [INFO] raft: Node at 172.17.0.12:8300 [Leader] entering Leader state
2015/12/17 14:47:55 [INFO] consul: cluster leadership acquired
2015/12/17 14:47:55 [INFO] consul: New leader elected: 200d4ea560f4
2015/12/17 14:47:55 [INFO] raft: Disabling EnableSingleNode (bootstrap)
2015/12/17 14:47:55 [INFO] consul: member '200d4ea560f4' joined, marking health alive
2015/12/17 14:47:55 [INFO] agent: Synced service 'consul'
Newer Consul version available: 0.6.0

my config file

    "data_dir": "/var/consul",
    "ui_dir": "/ui",
    "log_level": "INFO",
    "server": true,
    "dns_config": {
            "allow_stale": false
    },
    "addresses": {
    "http": "0.0.0.0"
    }

}

and i am using setup from >>https://github.com/gliderlabs/docker-consul/tree/master/0.6/consul-server

in local box outside the container

curl -v -L 172.17.0.12:8500

  • Rebuilt URL to: 172.17.0.12:8500/
  • Hostname was NOT found in DNS cache
  • Trying 172.17.0.12...

but inside the container, i am able to get page using curl -v -L localhost:8500

calvn commented 8 years ago

@hridyeshpant Can you check the port mapping for that container with docker ps? Perhaps port 8500 is mapped to some other port on the host. https://ewegithub.sb.karmalab.net/EWE/docker/tree/master/stratus/consul/server is not accessible for me.

hridyeshpant commented 8 years ago

@cleung2010 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b3459a09f0bd test "/bin/consul agent -s" 5 hours ago Up About a minute 8300-8302/tcp, 8400/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp admiring_curie the git hub repo is our internal repo, you create a image from https://github.com/gliderlabs/docker-consul/tree/master/0.6/consul-server with the changed in server.json "addresses": { "http": "0.0.0.0" } i tried running command like docker run -p 8500:8500 test -bootstrap -ui-dir /ui , but no success.

gvenka008c commented 8 years ago

I am facing the issues in access the consul UI. Here is how I am starting it

consul agent -ui -ui-dir /tmp/consul_web/ -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-one -bind=xx.xxx.xx.xxx -config-dir /etc/consul.d
 #curl -v http://xx.xxx.xx.xxx:8500
* About to connect() to 127.0.0.1 port 8500 (#0)
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8500 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:8500
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Location: /ui/
< Date: Tue, 19 Jul 2016 16:06:14 GMT
< Content-Length: 39
< Content-Type: text/html; charset=utf-8
<
<a href="/ui/">Moved Permanently</a>.

* Connection #0 to host 127.0.0.1 left intact

Please suggest. Let me know if any details required. Thanks.

slackpad commented 8 years ago

@gvenka008c that's the correct behavior - Consul is trying to redirect you to /ui/ which is the location of the web UI. If you add a -L to your curl command it will follow the redirect.

gvenka008c commented 8 years ago

@slackpad Thanks. When I try to hit the URL http://xx.xxx.xxx.xx:8500/ui/ from the browser, it says "Failed to Open Page". I have opened the ports on the server but still the same problem.

# netstat -an | grep 8500
tcp        0      0 127.0.0.1:8500          0.0.0.0:*               LISTEN
gvenka008c commented 8 years ago

@slackpad I started consul with -client argument and that fixed the issues.


consul agent -ui -ui-dir /tmp/consul_web/ -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-one -bind=xx.xxx.xxx.xx -config-dir /etc/consul.d -client 0.0.0.0