Closed victor7costa closed 6 years ago
Hi @victorseth, thank you for trying Network API.
I think the documentation guided you wrong. You can just load the $NETWORKAPI_FOLDER/dev/load_example_environment.sql
file to get things working.
It sound like you are installing it by hand. I encourage you to try using docker to run the project:
# Get to project root directory and run
$> docker-compose up -d
We will update the documentation with those informations. If you have other problems, please let us know.
Regards.
Hi @pantuza
When i try to use mysql to import the SQL file:
ERROR 1146 (42S02) at line 12: Table '
this sql doesn't have the db schema. Where do I get it?
Try it by doing:
mysql -u root -h localhost -e 'drop database if exists networkapi;'
mysql -u root -h localhost -e 'create database networkapi;'
cd /vagrant/dbmigrate; db-migrate --show-sql
mysql -u root -h localhost networkapi < /vagrant/dev/load_example_environment.sql
As you are trying to install it manually, take a look at this file, that is a bash to run Network API inside a Vagrant VM. Some commands there may also help you.
Thanks for your time! Now it just worked. But now when i try to connect after turning gunicorn up, it gives "Internal Server Error". Not using Gunicorn just gives "ERR_CONNECTION_REFUSED"
I'm trying to make it work with docker, but it is complaining about my docker version.
EDIT: Docker now works, BUT, what do I do after the "docker-compose up -d" Is there a docker guide? I'll be glad to use it.
Hi @victorseth,
After "docker-compose up -d" you should check containers by "docker ps --all". There are lots of good docker tutorials. I think these two are good to start with. One for docker and one for compose:
For Network API I also recommend you to always verify the logs. They are at /tmp/
directory. To follow application logs use /tmp/networkapi.log
and for Gunicorn use /tmp/gunicorn-networkapi_*.log
Tip: To get a shell within the application docker container use:
docker exec -it netapi_app bash
Regards
Checking logs: OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")
I think there is something wrong with netapi_db from docker.
Ok. It should not happen.
Try to run docker-compose restart
I will recreate locally my environment and check if the problem occurs.
Same error after restarting "ERR_CONNECTION_REFUSED", this is the full error on networkapi.log:
[ERROR] 25/Sep/2017:16:17:34 +0000 - U:NoRequestUser, P:/favicon.ico, C:NoRequestContext, N:gunicorn.error:143 , T:K2FKCI4UQESMBIQ1ZFGOUA, MSG:Error handling request
Traceback (most recent call last):
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 102, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in call
response = self.get_response(request)
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 220, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/root/virtualenvs/networkapi_env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
import(name)
File "/opt/app/GloboNetworkAPI/networkapi/urls.py", line 34, in
Now after restarting, there is no new log. Still not working.
Ok. Please paste here the following commands:
docker --version
docker-compose version
And also, refer to this page and check if docker version is compatible with the v3 of docker-compose file format. Your docker version should be greater than 1.13.0+
Docker version 17.09.0-ce-rc3, build 2357fb2 docker-compose version 1.16.1, build 6d1ac21 docker-py version: 2.5.1 CPython version: 2.7.13 OpenSSL version: OpenSSL 1.0.1t 3 May 2016
Ok, let's try this way:
docker-compose down
docker-compose build --no-cache
docker-compose up -d
As our problem seems to be at the Database container, let's check it by running:
docker logs netapi_db
You should see something like "[Note] mysqld: ready for connections"mysql -u root -h 127.0.0.1
Also, log into the application container and try to ping the database container: docker exec -it netapi_app ping -c 1 netapi_db
just to check connectivity.
Verify if all containers are up and running: docker ps --all
. You should have 5 containers like netapi_*
--- netapi_db ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.086/0.086/0.086/0.000 ms Ping worked. docker logs netapi_db shows "ready for connections" connecting works. logs at /tmp/ still dating from yesterday Do I access my machine by the interface? http://XXX.XXX.XXX.XXX:8000?
docker ps --all show 5 containers from netapi.
Sounds like everything is now ok.
Do a request to the API to see if it is working:
curl --user networkapi:networkapi http://localhost:8000/api/v3/environment/
You should see a Json as a response.
curl: (56) Recv failure: Connection reset by peer
Check if the port 8000 is open: netstat -antl | grep 8000
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
Open.
Try to switch localhost to 127.0.0.1. Your OS may not resolving localhost:
curl --user networkapi:networkapi http://127.0.0.1:8000/api/v3/environment/
Where do I change it? gunicorn.conf.py?
Switch it on the curl:
curl --user networkapi:networkapi http://127.0.0.1:8000/api/v3/environment/
Same message curl: (56) Recv failure: Connection reset by peer
Ok. Seems like the OS is blocking the request. Two things now:
# Enter container
docker exec -it netapi_app bash
# Verify open port inside the container
netstat -antl
# Run the curl
curl --user networkapi:networkapi http://127.0.0.1:8000/api/v3/environment/
If curl do not exist at the container install it with apt-get install curl
Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.11:43812 0.0.0.0:* LISTEN
Can't install curl and can't ping outside. " Temporary failure resolving 'archive.ubuntu.com'"
I think this is the problem. Do docker have an interface that interacts with the external network?
Yes it has. Make sure you have no Firewall.
Ok, sounds like you have a networking problem at the OS. Please paste here the result of the following commands:
# Outside the container (on host machine)
uname -a
sysctl net.ipv4.ip_forward
cat /etc/resolv.conf
ifconfig
Within the container (netapi_app):
cat /etc/resolv.conf
netstat -antl
ping globo.com -c 1
nslookup globo.com
If any of these commands do not exist inside the container ignore it.
OUTSIDE CONTAINER uname -a Linux observium 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
sysctl net.ipv4.ip_forward = 1
resolv.conf
nameserver 8.8.8.8
ifconfig(removing only my IP with XXX.XXX.XXX.XXX) br-981623d8363e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.18.0.1 netmask 255.255.0.0 broadcast 0.0.0.0 inet6 fe80::42:4ff:fee2:b60c prefixlen 64 scopeid 0x20 ether 02:42:04:e2:b6:0c txqueuelen 0 (Ethernet) RX packets 135 bytes 13438 (13.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 138 bytes 465027 (454.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0 inet6 fe80::42:dff:fea1:1c53 prefixlen 64 scopeid 0x20 ether 02:42:0d:a1:1c:53 txqueuelen 0 (Ethernet) RX packets 789 bytes 71046 (69.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 804 bytes 4263718 (4.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet XXX.XXX.XXX.XXX netmask 255.255.255.192 broadcast XXX.XXX.XXX.XXX
inet6 XXXX prefixlen 64 scopeid 0x0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
veth0218642: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::54ab:6eff:fecc:13bb prefixlen 64 scopeid 0x20 ether 56:ab:6e:cc:13:bb txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 24 bytes 1624 (1.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth0b1b4bd: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::98fa:91ff:feb2:254d prefixlen 64 scopeid 0x20 ether 9a:fa:91:b2:25:4d txqueuelen 0 (Ethernet) RX packets 135 bytes 13438 (13.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 138 bytes 465027 (454.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth107ebf6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::846f:eeff:fe0d:d898 prefixlen 64 scopeid 0x20 ether 86:6f:ee:0d:d8:98 txqueuelen 0 (Ethernet) RX packets 2030 bytes 385499 (376.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1746 bytes 143744 (140.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth24123f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::4c95:38ff:fe38:cf1e prefixlen 64 scopeid 0x20 ether 4e:95:38:38:cf:1e txqueuelen 0 (Ethernet) RX packets 1731 bytes 143543 (140.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1981 bytes 381608 (372.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vetha3e927e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::ec7f:92ff:fe4f:f7eb prefixlen 64 scopeid 0x20 ether ee:7f:92:4f:f7:eb txqueuelen 0 (Ethernet) RX packets 58 bytes 5633 (5.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 90 bytes 9133 (8.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
INSIDE CONTAINER resolv.conf nameserver 127.0.0.11 options ndots:0
netstat Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.11:43812 0.0.0.0:* LISTEN
ping ping: unknown host globo.com
nslookup ;; connection timed out; no servers could be reached
Ok. Thank you for the results.
Run inside the container the DNS search using other DNS server like OpenDNS:
nslookup globo.com 208.67.220.220
Outside the container, please provide the routing information:
route -n
nslookup ;; connection timed out; no servers could be reached
route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 XXX.XXX.XXX.XXX 0.0.0.0 UG 100 0 0 ens192 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-981623d8363e XXX.XXX.XXX.XXX 0.0.0.0 255.255.255.192 U 100 0 0 ens192
Ok. Good. Let's see the docker information about the networking:
docker network inspect bridge
What Linux distribution are you using?
[ { "Name": "bridge", "Id": "26a48e6df54e251e85445dff7cf5e233c38beb03bd4ddafacc75158af6870893" , "Created": "2017-09-21T18:11:30.352843335-03:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": {}, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]
I'm using CentOS 7
Things seems ok.
One container pings another, right? The container pings the host machine? Try to ping from inside the container the IP XXXX.
Ok, explaining
I'm using my PC to access a server hosting a CentOS 7. So i'm acessing XXX.XXX.XXX.XXX:8000 from my PC.
Pinging from inside 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.050/0.062/0.081/0.013 ms
I can ping the server IP (XXX.XXX.XXX.XXX) but can't ping any other address on the same subnet from the INSIDE container.
Ok. So you are logged into XXX server using SSH, right?
Within the server (not the container), does the ping and the nslookup works?
ping globo.com -c 1
nslookup globo.com
Let's consider this server XXXX as our host machine where the container are running on.
--- globo.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.768/0.768/0.768/0.000 ms
Server: 8.8.8.8 Address: 8.8.8.8#53
Non-authoritative answer: Name: globo.com Address: 186.192.90.5
Yes, ping and lookup.
Ok, perfect!
I would suggest now to restart the docker service on OS. Seems like the bridge is not forwarding traffic from docker to local interface.
When restart occurs, all containers goes down. So, do as follows:
# Restart docker
systemctl restart docker.service
# Run containers again
docker-compose up -d
Then, check if you can ping, lookup or even install curl.
What is the Linux distribution of the host machine?
Worked. I can ping. Curl installed. Then: Curl from INSIDE the container curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refused
Nice. Network is OK. this curl connection refused were from host machine or inside the container?
We had stopped at curl on application running from inside the container:
docker exec -it netapi_app bash
netstat -antl # Port 8000 should be in listen state
curl --user networkapi:networkapi http://localhost:8000/api/v3/environment/
If it does not work please paste the result of tail /tmp/gunicorn-networkapi_error.log
netstat (from inside container) shows: Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.11:35218 0.0.0.0:* LISTEN
tailing (from outside): OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)") 2017-09-25 16:18:08 [18658] [DEBUG] Closing connection. It's a log from yesterday. There is no new log since.
So, the application/server is not up. Go to host machine and check if all containers are running docker ps --all
Then restart only the application container docker restart netapi_app
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6681f8b36d0a globonetworkapi_celery "sh scripts/docker..." 5 hours ago Up 26 minutes 8000/tcp netapi_celery
3ebe43c0699f globonetworkapi_netapi "sh scripts/docker..." 5 hours ago Up 26 minutes 127.0.0.1:8000-8001->8000-8001/tcp netapi_app
d17d522e05a8 rabbitmq:3.6.9 "docker-entrypoint..." 5 hours ago Up 26 minutes 4369/tcp, 0.0.0.0:5672->5672/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp netapi_queue
dc8d32d74081 mysql:8.0.0 "docker-entrypoint..." 5 hours ago Up 26 minutes 0.0.0.0:3306->3306/tcp netapi_db
8645c038ce5b memcached:1.4.33 "docker-entrypoint..." 5 hours ago Up 26 minutes 0.0.0.0:32768->11211/tcp netapi_cache
e7d00a41d8e6 hello-world "/hello" 5 days ago Created jolly_kepler
All up.
I just installed nmap inside the container and then scanned port 8000 from the inside, port 8000:
Host is up (0.000075s latency). PORT STATE SERVICE 8000/tcp closed http-alt
It must be "open", right?
Does the curl from inside the container works now?
. Check the port 8000 netstat -antl
. Do the curl curl --user networkapi:networkapi http://localhost:8000/api/v3/environment/
Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.11:45419 0.0.0.0:* LISTEN
curl: (7) Failed to connect to localhost port 8000: Connection refused
Inside the container, paste the result of tail /tmp/gunicorn-networkapi_error.log
Do you have any other software that are using port 8000 at host machine? Maybe the container is having problem to listen on port 8000. The gunicorn logs will tell us
Now just worked: 2017-09-26 21:21:18 [34] [INFO] Booting worker with pid: 34 2017-09-26 21:21:18 [36] [INFO] Booting worker with pid: 36 2017-09-26 21:21:18 [37] [INFO] Booting worker with pid: 37 2017-09-26 21:21:18 [38] [INFO] Booting worker with pid: 38 2017-09-26 21:21:18 [35] [INFO] Booting worker with pid: 35 2017-09-26 21:21:18 [39] [INFO] Booting worker with pid: 39 2017-09-26 21:21:18 [40] [INFO] Booting worker with pid: 40 2017-09-26 21:21:18 [41] [INFO] Booting worker with pid: 41 2017-09-26 21:21:18 [42] [INFO] Booting worker with pid: 42
Tried curl and return JSON and log: 2017-09-26 21:22:35 [42] [DEBUG] GET /api/v3/environment/
Acessing from another PC , XXX.XXX.XXX.XXX:8000 still returning ERR_CONNECTION_REFUSED
Great!
Now the Network API is running 👍
As the name says, it is a API. It does not have an user interface. I encorage you to check Network API UI project that will bring you a WEB interface to register equipments, networks, IPs and etc. All through web forms.
Thank you for trying Globo Network API.
I just used curl from INSIDE enviroment, outside from the same machine worked too IF i use "localhost" instead of the XXX.XXX.XXX.XXX.
But curl from another machine via IP or from the same machine via IP XXX.XXX.XXX.XXX
curl: (7) couldn't connect to host
And I installed WebUI and it's up, but I can't access it via my IP:8080 (WebUI)
Good day, I was installing the API but I got stuck on the Schema import part:
mysql -u \<user> -p \<password> -h \<host> \<dbname> \< $NETWORKAPI_FOLDER/dev/database_configuration.sql
There is no database_configuration.sql file in the dev folder. What am I missing?