Why I can't connect port 8080 using node.js in CentOS? - node.js

I created web server using node.js in CentOS 8.
But It doesn't work.
This is my node.js web server.
const http = require('http');
const hostname = '0.0.0.0';
const port = '8080';
httpd = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
});
httpd.listen(port, hostname, function(){
console.log('Server Start');
});
I sent ping to centos for port 22 and 8080.
I couldn't receive response for only port 8080.
C:\Users\user>tcping -p 22 <centOS IP>
Probing <centOS IP>:22/tcp - Port is open - time=14.019ms
Probing <centOS IP>:22/tcp - Port is open - time=13.159ms
Probing <centOS IP>:22/tcp - Port is open - time=8.601ms
Probing <centOS IP>:22/tcp - Port is open - time=9.896ms
C:\Users\user>tcping -p 8080 <centOS IP>
Probing <centOS IP>:8080/tcp - No response - time=2010.980ms
Probing <centOS IP>:8080/tcp - No response - time=2008.277ms
Probing <centOS IP>:8080/tcp - No response - time=2008.509ms
Probing <centOS IP>:8080/tcp - No response - time=2000.949ms`
I cheked below info.
(I checked listening port 8080)
(I turned off the firewalld, iptables...)
<Linux>
[opc#instance-20220607-1056 webTest]$ netstat -tnlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9003 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
.
.
[opc#instance-20220607-1056 webTest]$ sudo service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
[opc#instance-20220607-1056 webTest]$ sudo systemctl status nftables
nftables.service - Netfilter Tables
Loaded: loaded (/usr/lib/systemd/system/nftables.service; disabled; vendor p>
Active: inactive (dead)
Docs: man:nft(8)
lines 1-4/4 (END)
[opc#instance-20220607-1056 webTest]$ sudo systemctl status firewalld
firewalld.service
Loaded: masked (Reason: Unit firewalld.service is masked.)
Active: inactive (dead)
Jan 05 17:49:52 instance-20220607-1056 systemd[1]: Starting firewalld - dynamic firewall daemon...
Jan 05 17:49:54 instance-20220607-1056 systemd[1]: Started firewalld - dynamic firewall daemon.
Jan 05 17:49:54 instance-20220607-1056 firewalld[1480]: WARNING: AllowZoneDrifting is enabled. This is consi>
Jan 05 20:38:06 instance-20220607-1056 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jan 05 20:38:10 instance-20220607-1056 systemd[1]: firewalld.service: Succeeded.
Jan 05 20:38:10 instance-20220607-1056 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[opc#instance-20220607-1056 webTest]$ sudo lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: OracleServer
Description: Oracle Linux Server release 8.7
Release: 8.7
Codename: n/a
What more should I check?
Thank you for your answer.

This issues occurred for Oracle cloud setting
I solved this problem by referring to the link below.
link

Related

Unable to connect to any servers

I have lost connection to Cassandra server and I am not able to restore it back.
When I run: sudo service cassandra status I can see service is running:
● cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; generated; vendor preset: enabled)
Active: active (exited) since Fri 2018-04-27 13:06:21 UTC; 4min 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 18479 ExecStop=/etc/init.d/cassandra stop (code=exited, status=0/SUCCESS)
Process: 18539 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/cassandra.service
Apr 27 13:06:21 serveur-1 systemd[1]: Starting LSB: distributed storage system for structured data...
Apr 27 13:06:21 serveur-1 systemd[1]: Started LSB: distributed storage system for structured data.
But When I run > cqlsh, I got the following:
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
Deleting content of directory /var/lib/cassandra/commitlog and restarting cassandra fixed my issue !
Check that Cassandra really accepts connections through loopback interface.
See what's in your cassandra.yaml under listen_address and listen_interface property
# cat /etc/cassandra/cassandra.yaml | grep listen
...
listen_address: 172.17.0.2
...
If you see a non local address, it might happen that cqlsh needs to connect through another interface to your Cassandra instance. Try this command (by replacing the IP with the same IP in configuration:
# cqlsh 172.17.0.2
You can check which hosts are allowed co access your Cassandra service using the following command
# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:7199 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9042 0.0.0.0:* LISTEN
tcp 0 0 localhost:38899 0.0.0.0:* LISTEN
tcp 0 0 20f1802:afs3-fileserver 0.0.0.0:* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
0.0.0.0 means that my Cassandra instance allows connection from both loopback and ethernet interface.
Delete all content from commitlog and it will work.

How to make Mongodb 27017 port available on Ubuntu

After installing and starting mongodb on Google Ubuntu instance I can verify that 'mongodb' is running with: sudo systemctl status mongodb:
● mongodb.service - LSB: An object/document-oriented database
Loaded: loaded (/etc/init.d/mongodb; generated; vendor preset: enabled)
Active: active (running) since Mon 2017-02-27 19:41:17 UTC; 57min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 13 (limit: 4915)
Memory: 71.7M
CPU: 14.520s
CGroup: /system.slice/mongodb.service
└─1914 /usr/bin/mongod --config /etc/mongodb.conf
Feb 27 19:41:15 instance-1 systemd[1]: Starting LSB: An object/document-oriented database...
Feb 27 19:41:16 instance-1 mongodb[1827]: * Starting database mongodb
Feb 27 19:41:17 instance-1 mongodb[1827]: ...done.
Feb 27 19:41:17 instance-1 systemd[1]: Started LSB: An object/document-oriented database.
It all looks good. But by some reason another application running on the same machine is not able to connect to the what-seems-to-be-running-properly mongodb.
Running nmap 127.0.0.1 returns:
PORT STATE SERVICE
22/tcp open ssh
631/tcp open ipp
There is no mongodb's port # 27017 listed there as *open*.
Interesting that the firewall is disabled. How can I assure themongodbport27017` is open and available to other applications?
nmap scan all common port, mongodb use port 27017 by default which is not listed in default nmap default port scan. On the other hand, you can specify the port manually :
nmap -p 27017 127.0.0.1
You will get :
PORT STATE SERVICE
27017/tcp open unknown
If you see STATE close, this means mongodb is not running and then you should begin to worry about it
Or as suggested by #Dimitri using netstat such as :
netstat -tulpn
which gives :
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -

Node web application was started in Linux, but web service access prompts no server data

Recently, I rented a Linux server, and on that, I developed a Node.js web program. I have opened the port, but I still can't access this web service.
iptables setting is below:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
iptables status is below:
[root#VAM_60_90_centos firewalld]# systemctl status iptables.service
* iptables.service - IPv4 firewall with iptables
Loaded: loaded (/user/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2017-03-02 22:41:10 CST; 11min ago
Main PID: 22884 (code=exited, status=0/SUCCESS)
Mar 02 22:41:10 VM_60_90_centos systemd[1]: Starting IPv4 firewall with iptables...
Mar 02 22:41:10 VM_60_90_centos iptables.init[22884]: iptables: Applying firewall rules: [ OK ]
Mar 02 22:41:10 VM_60_90_centos systemd[1]: Started IPv4 firewall with iptables.
What can I do to fix this?

Unable to tell what port Logstash is bound to or listening on when started normally

My logstash version is:
# /opt/logstash/bin/logstash --version
logstash 2.2.4
it is configured to receive input from port 5044 according to the filebeat file:
/etc/logstash/conf.d/02-beats-input.conf
input {
beats {
port => 5044
ssl => false
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
}
I have set ssl to false as I am not using it
but when I start the logstash service normally with systemctl it start and checking the status confirms it is running
systemctl status logstash
● logstash.service - LSB: Starts Logstash as a daemon.
Loaded: loaded (/etc/rc.d/init.d/logstash)
Active: active (exited) since Mon 2016-07-18 19:14:51 BST; 15h ago
Docs: man:systemd-sysv-generator(8)
Process: 19965 ExecStop=/etc/rc.d/init.d/logstash stop (code=exited, status=0/SUCCESS)
Process: 19970 ExecStart=/etc/rc.d/init.d/logstash start (code=exited, status=0/SUCCESS)
...
logstash started
The problem is that logstash does not seem to be receiving input on port 5044. hosts sending filebeats encounter:
single.go:126: INFO Connecting error publishing events (retrying): dial tcp 192.72.0.92:5044: getsockopt: connection refused
when I check the port
# netstat -an | grep 5044
I get nothing. So even though logstash is running, I can't tell what port it is bound to and listening on.
Also the firewall is stopped temporarily to investigate this.
The strange thing is that is I run logstash is debug mode like so:
# ./logstash --debug -f /etc/logstash/conf.d/02-beats-input.conf
I can see
# netstat -an | grep 5044
tcp6 0 0 :::5044 :::* LISTEN
tcp6 0 0 192.72.0.92:5044 192.168.36.70:53720 ESTABLISHED
tcp6 0 0 192.72.0.92:5044 192.72.0.90:45980 ESTABLISHED
tcp6 0 0 192.72.0.92:5044 192.72.0.90:45975 ESTABLISHED
tcp6 0 0 192.72.0.92:5044 192.72.0.90:45976 ESTABLISHED
or
# lsof -i :5044
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 15136 root 7u IPv6 7191510 0t0 TCP *:lxi-evntsvc (LISTEN)
java 15136 root 33u IPv6 7192379 0t0 TCP hostname:lxi-evntsvc->192.72.0.90:45975 (ESTABLISHED)
and the host sending filebeats can connect
output.go:87: DBG output worker: publish 7 events
2016/07/19 10:02:08.017890 client.go:146: DBG Try to publish 7 events to logstash with window size 10
2016/07/19 10:02:08.038579 client.go:124: DBG 7 events out of 7 events sent to logstash. Continue sending ...
2016/07/19 10:02:08.038615 single.go:135: DBG send completed
Please help point out what I may be doing wrong with this configuration. Thanks
Based on the hing provided by #LiGhTx117
I think
The startup script used by logstash in:
/etc/init.d/logstash
has the following variables among others:
LS_USER=logstash
LS_GROUP=logstash
LS_HOME=/var/lib/logstash
LS_LOG_DIR=/var/log/logstash
LS_LOG_FILE="${LS_LOG_DIR}/$name.log"
LS_CONF_DIR=/etc/logstash/conf.d
The ownership and permission on these seem to be the issue.
I ensured that the directories where recursively accessible to the
user logstash as well as the group logstash
and
Then I also ensured that the log_file: logstash.log was writeable by
the user/group logstash
restarted logstash

Not start play! application in Microsoft Azure on CentOS

I created a virtual machine CentOS.
Created end-point in the control panel on port 80 and 443. In CentOS added rules to iptables:
# Generated by iptables-save v1.4.7 on Thu Aug 9 18:07:49 2012
*filter
:INPUT ACCEPT [142:12032]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [146:18544]
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
COMMIT
# Completed on Thu Aug 9 18:07:49 2012
Run the application:
CompilerOracle: exclude jregex/Pretokenizer.next
Listening for transport dt_socket at address: 8000
18:07:05,799 INFO ~ Starting /srv/play-1.2.5/localevent
18:07:05,808 INFO ~ Module .svn is ignored, name starts with a dot
18:07:06,820 WARN ~ You're running Play! in DEV mode
18:07:06,975 INFO ~ Listening for HTTP at /127.0.0.1:80 (Waiting a first request to start) ...
I went to the address: *.сloudapp.net
But the application does not start. In what may be the reason?
#update1
SELinux is disabled. Version of CentOS - 6.2
#update2
For the test was installed Apache. Home Apache displayed.
Added proxy from 80 to 9000 port in httpd.conf. Play was launched at the 9000 port.
Apache returns a 503 error. Wget 127.0.0.1:9000 gets everything right.
AFAIK, you have to add an endpoint to your Azure virtual machine in order to allow to connect to the 80 TCP port.
For instance, see this doc, under the "Expose Redis to the outside" section, by setting your private and public ports to 80.
Looked logs Apache:
[error] (13) Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:9000 (127.0.0.1) failed
[error] ap_proxy_connect_backend disabling worker for (127.0.0.1)
Solution:
setsebool httpd_can_network_connect 1

Resources