Ubuntu 14.04下Elasticsearch启动后localhost:9200连接被拒求助
Let’s walk through fixing that "Connection refused" error when trying to reach Elasticsearch on port 9200. Here are the most common checks and fixes tailored to your setup:
1. Confirm Elasticsearch is Actually Running
First, make sure the service didn’t fail silently on startup:
sudo service elasticsearch status
If the output doesn’t show active (running), dive into your my-application.log to look for ERROR or WARN lines—these will likely tell you why the service crashed (like misconfiguration, missing dependencies, or resource limits). You can also check system logs for clues:
tail -n 50 /var/log/syslog | grep elasticsearch
2. Double-Check Your elasticsearch.yml Config
Since you’ve already edited this file, verify these critical settings (YAML is picky about syntax—don’t skip the space after colons!):
network.host: If you set this to a specific IP (e.g.,192.168.1.10) instead oflocalhostor0.0.0.0, you’ll need to curl that IP instead oflocalhost. For testing, set it to0.0.0.0to allow connections from any address.http.port: Ensure this is set to9200(the default). If you changed it, update your curl command to match the new port.- Single-Node Discovery: For a standalone instance:
- Pre-7.x Elasticsearch versions need these lines:
discovery.zen.ping.unicast.hosts: ["localhost"] discovery.zen.minimum_master_nodes: 1 - 7.x+ versions require:
discovery.type: single-node
- Pre-7.x Elasticsearch versions need these lines:
- Syntax Mistakes: Look for missing spaces after colons, unclosed quotes, or indentation errors—these can break the entire config.
3. Check if Port 9200 is Occupied
Another process might be using the port. Run this to see what’s listening on 9200:
sudo netstat -tulpn | grep 9200
If you see another process listed, either terminate that process or change Elasticsearch’s port in elasticsearch.yml.
4. Verify Firewall Settings
Ubuntu 14.04 uses ufw by default. Check if the firewall is blocking port 9200:
sudo ufw status
If 9200 isn’t allowed, add a rule to open it:
sudo ufw allow 9200/tcp
5. Check JVM Memory Limits
Elasticsearch might fail to start if it doesn’t have enough memory. Open the jvm.options file (usually in /etc/elasticsearch/) and adjust the heap size—for small Ubuntu 14.04 instances, a safe starting point is:
-Xms512m -Xmx512m
After making changes, restart the service:
sudo service elasticsearch restart
Once you’ve worked through these steps, test your curl command again:
curl -X GET 'http://localhost:9200'
内容的提问来源于stack exchange,提问作者Suprit Gandhi

