MacOS下Vagrant虚拟机中Aerospike Java客户端连接失败求助
Let's break down why your Java client can't connect to your Aerospike instance, and how to fix it quickly:
First, the Core Issue: Wrong Port!
You're using port 8081 in your client code—that's the port for the Aerospike Management Console (AMC), which is exactly why you can access AMC without problems. The default port for Aerospike database client connections is 3000.
Step 1: Correct the Client Port in Your Code
Update your AerospikeClient initialization to use the proper database port:
new AerospikeClient("172.28.128.3", 3000);
Step 2: Verify Vagrant Port Forwarding (If Needed)
If you still can't connect after fixing the port, double-check your Vagrant port forwarding setup:
- Open your
Vagrantfileand look for a line like this:config.vm.network "forwarded_port", guest: 3000, host: 3000 - If it's missing, add that line, then run
vagrant reloadto restart your instance. - You can also connect using
localhost:3000from your Mac host if port forwarding is set up:new AerospikeClient("localhost", 3000);
Step 3: Ensure Aerospike is Bound to the Correct Address
Sometimes Aerospike is configured to only listen on localhost inside the Vagrant VM, blocking external connections:
- SSH into your Vagrant instance:
vagrant ssh - Edit the Aerospike config file (typically at
/etc/aerospike/aerospike.conf) - Find the
network > servicesection and make sure theaddressis set toanyor the VM's IP (172.28.128.3):network { service { address any port 3000 } } - Restart the Aerospike service:
sudo systemctl restart aerospike
Step 4: Test Network Connectivity
From your Mac host, test if the port is reachable using telnet or nc:
# Using telnet telnet 172.28.128.3 3000 # Or using netcat nc -zv 172.28.128.3 3000
If the connection succeeds, the network path is good—focus on client code or configuration. If it fails, double-check Vagrant network settings and any firewall rules inside the VM.
内容的提问来源于stack exchange,提问作者user27111987

