I am trying to connect to rabbitmq broker (rabbitmq-server-3.8.0) by nodejs and amqplib/callback_api library so after install amqplib library with :
npm i amqplib
I wrote this code :
const amqp = require("amqplib/callback_api");
amqp.connect('amqp://guest:guest#xxxx:5672', (err, conn) => {
if (err) throw err;
else console.log(`Connect to brocker success!`);
})
As official site say:
By default, the guest user is prohibited from connecting from remote hosts; it can only connect over a loopback interface (i.e. localhost).
It is possible to allow the guest user to connect from a remote host by setting the loopback_users configuration to none.
In %APPDATA%\RabbitMQ\ location of my broker server it did not exist rabbitmq.conf file so i'd created this file just by this content:
loopback_users = none
C:\Users\tazik.WIN-LKH5BTVHRCM\AppData\Roaming\RabbitMQ>dir
Volume in drive C has no label.
Volume Serial Number is A852-F618
Directory of C:\Users\tazik.WIN-LKH5BTVHRCM\AppData\Roaming\RabbitMQ
10/13/2019 11:39 AM <DIR> .
10/13/2019 11:39 AM <DIR> ..
10/12/2019 02:05 PM 3 advanced.config
10/13/2019 11:41 AM <DIR> db
10/12/2019 02:07 PM 23 enabled_plugins
10/13/2019 10:37 AM <DIR> log
10/13/2019 10:22 AM 21 rabbitmq.conf
3 File(s) 47 bytes
4 Dir(s) 116,768,235,520 bytes free
C:\Users\tazik.WIN-LKH5BTVHRCM\AppData\Roaming\RabbitMQ>
Now after run nodejs code i still got this error:
2019-10-13 10:37:46.818 [info] <0.895.0> accepting AMQP connection <0.895.0> (94.182.192.28:25759 -> *********:5672)
2019-10-13 10:37:46.834 [error] <0.895.0> Error on AMQP connection <0.895.0> (94.182.192.28:25759 -> ******:5672, state: starting):
PLAIN login refused: user 'guest' can only connect via localhost
2019-10-13 10:37:46.849 [info] <0.895.0> closing AMQP connection <0.895.0> (94.182.192.28:25759 -> ******:5672)
Have you restarted after configuration? Also, check if RABBITMQ_CONFIG_FILE env is set to the location you placed the config file:
Open the "RabbitMQ Command Prompt (sbin dir)"
.\rabbitmq-service.bat stop
.\rabbitmq-service.bat remove
Run the following commands in the previous shell:
.\rabbitmq-service.bat install
.\rabbitmq-service.bat start
After that, you should be able to connect
Related
kubernetes version: v1.16.3
linux version: 7.3.1611
Starting Vitess cluster on kubernetes using default operator.yaml and 101_initial_cluster.yaml, one of example-vttablet-zone1-xxx pod is restarting forever.
using kubectl logs -f example-vttablet-zone1-2548885007-46a852d0 -c vttablet to see the logs, i got
W0706 07:42:02.200507 1 tm_init.go:531] Cannot get current mysql port, will keep retrying every 1s: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
E0706 07:42:02.285406 1 engine.go:213] Error starting vreplication engine: error in connecting to mysql db with connection <nil>, err net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000), will keep retrying.
E0706 07:42:02.285504 1 state_manager.go:276] Error transitioning to the desired state: MASTER, Serving, will keep retrying: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
I0706 07:42:02.285527 1 state_manager.go:661] State: exiting lameduck
E0706 07:42:02.285539 1 tm_state.go:258] Cannot start query service: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
I0706 07:42:02.285553 1 tm_state.go:305] Publishing state: alias:<cell:"zone1" uid:2548885007 > hostname:"10.233.107.217" port_map:<key:"grpc" value:15999 > port_map:<key:"vt" value:15000 > keyspace:"commerce" shard:"-" key_range:<> type:MASTER db_name_override:"vt_commerce" mysql_hostname:"10.233.107.217" master_term_start_time:<seconds:1625527268 nanoseconds:196807555 >
I didn't change any yaml in operator directory, anyone know why is this?
Code
To reproduce requires two application running and connecting to each other through TCP. So I've made a tiny repo that also includes the powershell build script. link to the full repo
However to avoid the extra click, here is the code for clientA.go.
package main
import (
"fmt"
"net"
"time"
)
func main() {
clientA, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf(":%v", "2222"))
if err != nil {
fmt.Println(err)
return
}
clientB, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf(":%v", "3333"))
if err != nil {
fmt.Println(err)
return
}
for {
clientAtoB, err := net.DialTCP("tcp4", clientA, clientB)
if err != nil {
fmt.Println(err)
} else {
defer clientAtoB.Close()
clientAtoB.SetLinger(0)
clientAtoB.SetNoDelay(true)
clientAtoB.SetKeepAlive(false)
fmt.Println("connected as Client A!")
buffer := make([]byte, 64)
_, err = clientAtoB.Read(buffer)
if err != nil {
continue
}
}
time.Sleep(time.Second)
}
}
The code for clientB.go is identical except the local and remote endpoints are swapped around:
clientBtoA, err := net.DialTCP("tcp4", clientB, clientA)
Problem
I build the same go code for both Windows and Linux but at runtime the applications produce different results. Specifically with how TCP connections are dialed on each platform.
On Windows, when I run the two executables clientA.exe and clientB.exe (built from the build.ps1 script) I get the desired result. As seen in this screenshot:
However when I upload and execute the Linux binaries, the result is different:
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ sudo chmod +x clientA clientB
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ ls -la
total 10984
drwxrwxr-x 3 ubuntu ubuntu 4096 Apr 27 03:09 .
drwxrwxr-x 4 ubuntu ubuntu 4096 Apr 27 03:08 ..
drwxrwxr-x 8 ubuntu ubuntu 4096 Apr 27 03:08 .git
-rw-rw-r-- 1 ubuntu ubuntu 11255 Apr 27 03:12 A.txt
-rw-rw-r-- 1 ubuntu ubuntu 11255 Apr 27 03:12 B.txt
-rw-rw-r-- 1 ubuntu ubuntu 247 Apr 27 03:08 build.ps1
-rwxrwxr-x 1 ubuntu ubuntu 2950662 Apr 27 03:08 clientA
-rw-rw-r-- 1 ubuntu ubuntu 2642944 Apr 27 03:08 clientA.exe
-rw-rw-r-- 1 ubuntu ubuntu 718 Apr 27 03:08 clientA.go
-rwxrwxr-x 1 ubuntu ubuntu 2950662 Apr 27 03:08 clientB
-rw-rw-r-- 1 ubuntu ubuntu 2642944 Apr 27 03:08 clientB.exe
-rw-rw-r-- 1 ubuntu ubuntu 718 Apr 27 03:08 clientB.go
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ ./clientA > A.txt & ./clientB > B.txt &
[1] 24914
[2] 24915
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ cat A.txt
dial tcp4 :2222->:3333: connect: connection refused
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ cat B.txt
dial tcp4 :3333->:2222: connect: connection refused
ubuntu#ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$
I don't expect the connection refused error since these two applications are running under the same environment, so no firewalls are in effect, and the permissions are identical.
How can I get the same result regardless of platform? Or why are they different in the first place?
Edit
The successful connection on Windows is not just the luck of good timing. On Windows, I can run A for 5 minutes, then when I run B, both connect successfully.
Update (2020-04-27)
After receiving feedback from Go developers, I've been told that this is likely a Linux configuration issue and not specific to Go. Other than permissions, I can't thing of anything that would prevent two applications in the same environment from establishing a TCP connection like this? (These low level Linux stuff isn't really my forte.)
Why this doesn't work on Linux is quite obvious. Both A and B are clients that are connecting to counterpart that needs to listen. On Linux (or UNIX) if you try to run ClientA it will try to dial in to ClientB's address and port. If there's no process already listening on this address and port to accept the connection in that moment ClientA will immediately end up with connection refused error (this is not entirely true, but most of time is, see my EDIT at the end of answer).
On Windows, under the hood Golang uses (for tcp, tcp4 and tcp6 protocols) ConnectEx API which is for connection-oriented sockets. This API behaves different from Linux connect API. If ConnectEx cannot connect immediately it returns error code ERROR_IO_PENDING and behind the scenes OS waits/retries until connection is accepted and established (or it gives up and makes it definitively failed) and then notifies back - this is called overlapped I/O.
Relevant part of MSDN ConnectEx documentation:
Connection-oriented sockets are often unable to complete their connection immediately, and therefore the operation is initiated and the function immediately returns with the ERROR_IO_PENDING or WSA_IO_PENDING error. When the connect operation completes and success or failure is achieved, status is reported using the completion notification mechanism indicated in lpOverlapped.
Now, what happens in your case on Windows is that you try to ConnectEx from both sides and OS connects those sockets for you. This will only work if other side gets connected within certain period. If you try to reasonably increase time.Sleep interval in both clients (e.g. 17 and 28), you can see even on Windows they will have hard time to connect anymore.
Answer to your question is that your code as it is written now depends on OS-specific behavior of TCP dialing in Golang on Windows and is not portable. To fix your software to be portable on any platform supported by Golang you probably want to change logic so both ClientA and ClientB listen for incoming connection and also periodically try to connect to the opposite side.
EDIT: I'm not saying your code can not work on Linux at all. It actually uses rare connection mode called TCP simultaneous connect where you can connect two processes without having any of them listen. Both dialing sides send their SYN simultaneously, so each side responds with SYN/ACK and then ACK to complete the 3-way handshake and ESTABLISH connection. That requires very precise timing and syncing of the connect call in both clients. Both sides would connect if TCP simultaneous connect is allowed in Linux kernel and that sync between connects is achieved (hardly done by just running both clients by hand or from same script; even simulating within same process and thread is not that easy).
rabbitmq has connected to my ports and everything looks good so far but when i try to connect to my localhost in browser im getting this error message:
The connection was reset
The connection to the server was reset while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web
so the first thing i did was go and look at my rabbitmq log and i see this:
Starting RabbitMQ 3.7.9 on Erlang 20.2.2
Copyright (C) 2007-2018 Pivotal Software, Inc.
Licensed under the MPL. See http://www.rabbitmq.com/
2019-09-15 08:06:51.710 [info] <0.240.0>
node : rabbit#bowzer
home dir : /var/lib/rabbitmq
config file(s) : (none)
cookie hash : XC8syc3LUBiQChoU4UJxPA==
log(s) : /var/log/rabbitmq/rabbit#bowzer.log
: /var/log/rabbitmq/rabbit#bowzer_upgrade.log
database dir : /var/lib/rabbitmq/mnesia/rabbit#bowzer
2019-09-15 08:06:52.982 [info] <0.248.0> Memory high watermark set to 6421 MiB (6733540556 bytes) of 16054 MiB (16833851392 bytes) total
2019-09-15 08:06:52.987 [info] <0.250.0> Enabling free disk space monitoring
2019-09-15 08:06:52.987 [info] <0.250.0> Disk free limit set to 50MB
2019-09-15 08:06:52.991 [info] <0.253.0> Limiting to approx 32668 file handles (29399 sockets)
2019-09-15 08:06:52.991 [info] <0.254.0> FHC read buffering: OFF
2019-09-15 08:06:52.991 [info] <0.254.0> FHC write buffering: ON
2019-09-15 08:06:52.993 [info] <0.240.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2019-09-15 08:06:53.164 [info] <0.240.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2019-09-15 08:06:53.164 [info] <0.240.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping registration.
2019-09-15 08:06:53.165 [info] <0.240.0> Priority queues enabled, real BQ is rabbit_variable_queue
2019-09-15 08:06:53.219 [info] <0.278.0> Starting rabbit_node_monitor
2019-09-15 08:06:53.241 [info] <0.306.0> Making sure data directory '/var/lib/rabbitmq/mnesia/rabbit#bowzer/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L' for vhost '/' exists
2019-09-15 08:06:53.302 [info] <0.306.0> Starting message stores for vhost '/'
2019-09-15 08:06:53.303 [info] <0.310.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_transient": using rabbit_msg_store_ets_index to provide index
2019-09-15 08:06:53.305 [info] <0.306.0> Started message store of type transient for vhost '/'
2019-09-15 08:06:53.306 [info] <0.313.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent": using rabbit_msg_store_ets_index to provide index
2019-09-15 08:06:53.308 [info] <0.306.0> Started message store of type persistent for vhost '/'
2019-09-15 08:06:53.312 [warning] <0.334.0> Setting Ranch options together with socket options is deprecated. Please use the new map syntax that allows specifying socket options separately from other options.
2019-09-15 08:06:53.313 [info] <0.348.0> started TCP listener on [::]:5672
2019-09-15 08:06:53.314 [info] <0.240.0> Setting up a table for connection tracking on this node: tracked_connection_on_node_rabbit#bowzer
2019-09-15 08:06:53.314 [info] <0.240.0> Setting up a table for per-vhost connection counting on this node: tracked_connection_per_vhost_on_node_rabbit#bowzer
2019-09-15 08:06:53.315 [info] <0.33.0> Application rabbit started on node rabbit#bowzer
2019-09-15 08:06:53.375 [notice] <0.86.0> Changed loghwm of /var/log/rabbitmq/rabbit#bowzer.log to 50
2019-09-15 08:06:53.540 [info] <0.5.0> Server startup complete; 0 plugins started.
2019-09-15 08:10:51.196 [info] <0.378.0> accepting AMQP connection <0.378.0> (127.0.0.1:55986 -> 127.0.0.1:5672)
2019-09-15 08:10:51.196 [error] <0.378.0> closing AMQP connection <0.378.0> (127.0.0.1:55986 -> 127.0.0.1:5672):
{bad_header,<<"GET / HT">>}
2019-09-15 08:13:26.916 [info] <0.385.0> accepting AMQP connection <0.385.0> (127.0.0.1:55990 -> 127.0.0.1:5672)
2019-09-15 08:13:26.916 [error] <0.385.0> closing AMQP connection <0.385.0> (127.0.0.1:55990 -> 127.0.0.1:5672):
{bad_header,<<"GET / HT">>}
2019-09-15 08:13:27.007 [info] <0.389.0> accepting AMQP connection <0.389.0> (127.0.0.1:55992 -> 127.0.0.1:5672)
2019-09-15 08:13:27.007 [error] <0.389.0> closing AMQP connection <0.389.0> (127.0.0.1:55992 -> 127.0.0.1:5672):
{bad_header,<<"GET /fav">>}
so i went and checked my ports and i get this:
sudo lsof -i -p -n | grep rabbitmq:
epmd 5687 rabbitmq 3u IPv4 59822 0t0 TCP *:4369 (LISTEN)
epmd 5687 rabbitmq 4u IPv6 59823 0t0 TCP *:4369 (LISTEN)
beam.smp 5892 rabbitmq 59u IPv4 57068 0t0 TCP *:25672 (LISTEN)
beam.smp 5892 rabbitmq 69u IPv6 58166 0t0 TCP *:5672 (LISTEN)
sudo service rabbitmq-server status:
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset:
Active: active (running) since Sun 2019-09-15 07:53:32 MST; 2min 19s ago
Main PID: 875 (beam.smp)
Status: "Initialized"
Tasks: 90 (limit: 4915)
CGroup: /system.slice/rabbitmq-server.service
├─ 875 /usr/lib/erlang/erts-9.2/bin/beam.smp -W w -A 64 -P 1048576 -t 500000
├─1037 /usr/lib/erlang/erts-9.2/bin/epmd -daemon
├─1387 erl_child_setup 32768
├─1691 inet_gethost 4
└─1692 inet_gethost 4
Sep 15 07:53:27 bowzer rabbitmq-server[875]: ## ##
Sep 15 07:53:27 bowzer rabbitmq-server[875]: ## ## RabbitMQ 3.7.9. Copyright (C
Sep 15 07:53:27 bowzer rabbitmq-server[875]: ########## Licensed under the MPL. See
Sep 15 07:53:27 bowzer rabbitmq-server[875]: ###### ##
Sep 15 07:53:27 bowzer rabbitmq-server[875]: ########## Logs: /var/log/rabbitmq/rabb
Sep 15 07:53:27 bowzer rabbitmq-server[875]: /var/log/rabbitmq/rabb
Sep 15 07:53:27 bowzer rabbitmq-server[875]: Starting broker...
Sep 15 07:53:32 bowzer rabbitmq-server[875]: systemd unit for activation check: "rabbit
Sep 15 07:53:32 bowzer systemd[1]: Started RabbitMQ broker.
Sep 15 07:53:33 bowzer rabbitmq-server[875]: completed with 0 plugins.
i also noticed that when others download and install the server they get 'completed with 6 plugins' and mine started with 0 plugins.
Your browser is trying to talk HTTP on port 5672 which is the AMQP port of the RabbitMQ broker.
If you want to access the management console, enable the management plugin and access it on http://your-rabbitmq-host:15672/.
Slackware OS, trying to setup fetchmail
I have coded this .fetchmailrc file:
set daemon 600 //fetches mail every hour or 60 minutes.
set logfile /root/fetchmail.log
poll 10.200.***.** protocol POP3
user "bob" password "bob" is "bob" here preconnect "date>>/root/fetchmail.log"
ssl
no rewrite
keep
It worked before but now it is failing to retrieve mail, i checked the fetchmail.log file and i get this error:
Thu Nov 5 10:15:32 GMT 2015
fetchmail: connection errors for this poll:
name 0: connection to 10.200.***.**:pop3s [10.200.***.**/995] failed: Connection refused.
fetchmail: POP3 connection to 10.200.***.** failed: Connection refused
fetchmail: Query status=2 (SOCKET)
I've reset the daemons, ended the process and no progress.
I had exactly the same problem on a Mageia 5 Linux. Apparently, I
solved it by redoing network configuration, which the Mageia can do
with a single click on the relevant Configure button in the Network
Center window.
I did not touch my .fetchmailrc file.
I can able to connect postgres from terminal as well as python manage.py dbshell command
But when i'm trying to connect from apache i'm Getting error as follows.
Error : OperationalError: could not connect to server: Permission denied
Is the server running on host "192.168.1.10" and accepting
TCP/IP connections on port 5432?
My listen Address on postgress conf file is 192.168.1.10 Address
pg_hg_cong allowed host all all 192.168.0.0/24 trust
And also selinux turned httpd_can_network_connect_db on
Port is listening on 192.168.1.10:5432 on netstat output.
And database's are storing in /tmp directory
wxrwxrwx. 1 postgres postgres 0 Dec 18 07:40 .s.PGSQL.5432
-rw-------. 1 postgres postgres 50 Dec 18 07:40 .s.PGSQL.5432.lock
Actually I have enabled selinux httpd_can_network_connect_db parameters on db server instead of web server
So issue got solved after enabling httpd_can_network_connect_db on web server