Run Tomcat on *:<port> instead of localhost:<port> - java

I am trying to access my localhost server from Parallels Desktop and facing some issues.
For example, I have an app on Spring Boot that runs on port 8081, and running sudo lsof -PiTCP -sTCP:LISTEN in Terminal gives me the following output:
java 8168 username 107u IPv6 0x53524f3d71f26ae5 0t0 TCP *:8081 (LISTEN)
And the output for second application (not Spring Boot, but Spring inside Tomcat 7) is:
java 7756 username 504u IPv6 0x53524f3d6cfe6fa5 0t0 TCP localhost:8096 (LISTEN)
I can easily access the first application from Parallels Desktop by address http://10.211.55.2:8081/, but doing the same for http://10.211.55.2:8096/ gives me this site can’t be reached error message.
So, how can I run my second application on *:8096 instead of localhost:8096?

The IP address tomcat listens in is controlled by the address attribute in the connector element in tomcat configuration file server.xml.
To listen on all addresses, set the address to 0.0.0.0:
<Connector port="8096"
address="0.0.0.0"
...other attributes.../>

Related

How to create a domain data grid in Payara Server with domain discovery mode?

I want to create a Domain Data Grid in Payara Server 5.191 with Domain Discovery Mode, where each node discovers each other by knowing the node IP address and port. According to the documentation, the nodes are configured in the domain.xml. However, I couldn't find anything on how to exactly specify the nodes in the domain.xml. What is the name of the configuration option, where the nodes are specified?
It is similar to Glassfish.
Create it in the Windows Operating System
You must download the application server. enter link description here
when installed a directory is created
C:\Payara_Server
C:\Payara_Server\bin
We open shell command window
and inside the command window
C:\Payara_Server\bin ./asadmin
asadmin> create-domain --adminport 4848 domain1
Enter admin user name[Enter to accept default]>
Using port 4848 for Admin.
Default port 8080 for HTTP Instance is in use. Using 1161
Using default port 7676 for JMS.
Using default port 3700 for IIOP.
Using default port 8081 for HTTP_SSL.
Using default port 3820 for IIOP_SSL.
Using default port 3920 for IIOP_MUTUALAUTH.
Default port 8686 for JMX_ADMIN is in use. Using 1162
Distinguished Name of the self-signed X.509 Server Certificate is:
[CN=moonbeam.gateway.2wire.net,OU=GlassFish,O=Oracle Corp.,L=Redwood Shores,ST
California,C=US]
Domain domain1 created.
Command create-domain executed successfully.
C:\Payara_Server\glassfish\domains\domain1 created
Start the server
asadmin> start-domain domain1
link it with IDE NETBEANS

How to make Spring Boot application accessible by external IP address of the server?

I'm a newbie to Spring Boot. I have a REST API application written in Spring Boot. When I execute my Spring Boot JAR, everything is okay and I can access the REST API with the localhost address instead of the actual one:
http://localhost:8083/articles
But when I try to access the REST API by my external IP address, I can't do it:
http://100.90.80.70:8083/articles
netstat -antu command in the Linux terminal gives me the following output:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp6 0 0 :::8083 :::* LISTEN
As I understand, my app is accessible only in localhost, because it hasn't a foreign address.
My application.properties file has only this line:
server.port=8083
Also, when I try to add a server.address line to application.properties like that:
server.address=100.90.80.70
server.port=8083
I have the following Exception: Caused by: java.net.BindException: Cannot assign requested address.
So my question is: how to make Spring Boot application accessible by external IP address of the server? Thank you.
As #Mark said, the problem is in the firewall. I have opened 8083 port in the firewall settings and now I can access my REST API app by the external IP address:
http://100.90.80.70:8083/articles
Linux command to check firewall status:
sudo ufw status verbose
Open 8083 port for remote access by TCP protocol:
sudo ufw allow 8083/tcp
More settings here: https://www.cyberciti.biz/faq/how-to-open-firewall-port-on-ubuntu-linux-12-04-14-04-lts/
I fixed the same by configuring port forwarding on my router, to allow traffic from public ip
In my OpenStack environment, after much debugging, the solution was to create a new Security Group Rule, which looks like this:
Security Group Rule.
Note that my Spring Boot application was deployed on port 8080.
I also noticed that on ubuntu18 the firewall is disabled by default. It did not cause any problems.

How to Change Default Port no to Tomcat Port No 8080?

I am using centOs VPS server with root access. I am using Apache Tomcat to run my java application. The problem that i am facing is that the Tomcat runs on port no 8080 and the default port no of Domain is 80.
so whenever i hit my domain name it move to port no 80 where nothing is present.
My application is working perfectly fine on domain.com:8080/.
I want when even i hit my domain domain.com . it automatically open my Java application. It does not show me the empty space.
I don't want to change my default port no of tomcat to 80.
Is there any way to change the port no. of the website. i am having the root access and using WHMCpanel.
HTTP protocol works on port 80 if you don't specify it. So somehow you need to find a way that when you reach the server at port 80, it redirects it to Tomcat.
I don't want to change my default port no of tomcat to 80. Is there any way to change the port no. of the website. i am having the root access and using WHMCpanel.
The answer is "depends". There are couple workarounds and a good solution to go:
You can create a simple webpage or configure the Apache or Nginx to redirect you to http://domain.com:8080 with a 302 redirection. I don't really recommend to go on that direction, but if you don't want to modify the ports.
Also, there's a trick with iptables where you can redirect the port 80 to 8080, but it that case you'd need to switch off the webserver running at port 80 as the port is already bound.
The good solution: Switch off Nginx or Apache and configure on server.xml the port to 80. Refer to this post for more details.
Nothing seems to be present on port 80 so you could switch off what is running on port 80.
Then do not run tomcat on port 80 because tomcat will need root and this is not a good solution.
The good solution is to redirect port 80 on port 8080 using iptable:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
then to make it persistent:
apt-get install iptables-persistent
iptables-save > /etc/iptables/rules.v4

Tomcat is running on 8080 port but unable to access remotely using ip address?

I have freshly installed apache-tomcat-7.0.62 on server. It starts without any error but i am unable to access it using : -
http://IP:8080/
here IP is ip address of server.
I have also run following command : -
here is the screenshot
Thanks
Find the server.xml located under confs folder of the catalina(tomcat).
Find out Connector tag which each one indicates for one connector isntance.
If the connector comes with no address attribute(as default), so tomcat will listen for all addresses. If it has address attribute, so just remove it out, or either have another Connector to listen for the related ipv4 address.
<Connector ... address="ip_v4_addr"/>
Check tomcat spec for Connectors here.
Next make sure the port is open and allowed to be invoked by any firewall, also make sure the ip-address is valid(public and reachable), and ISP doesn't block it.
Default port for tomcat(HTTP) is 8080 and 8443 for HTTPS, maybe your ISP doesn't let you workout with non-std ports, or the firewall issue.

eclipse: remote debugging a tomcat server behind a firewall

After starting tomcat with jpda on, while at my company I can remote debug a bunch of web applications in eclipse. For a number of reasons I am now in need of developing and remote debugging those same webapps from outside the company firewall, and i can only access that server via ssh on port 22.
I tunneled most needed ports (svn, nexus, tomcat itself, from the server or via the server) to localhost and those services work fine, but I cannot start the eclipse debugger in any way; i'm getting "connection timed out while waiting for packet XXX" or "connection refused" from the second time i try on.
Checking with nmap on the server, it reports the port open before the first connection attempt, and it becomes closed after that. I get no interesting output log in catalina.out
The command i use to start the tunnel is:
ssh -L 8000:localhost:8000 user#mycompany.com
iptables was temporarily stopped both on the server and in the local machine for testing.
Am i missing something? Do I need to forward some other port to localhost? Or is it in some way involved name resolution?
EDIT
Open ports before connection attemp from eclipse:
root#lnxulisse:/opt/apache-tomcat-6.0.32/bin# lsof -p 2147 -n |grep TCP
java 2147 root 4u IPv4 640850 0t0 TCP *:8000 (LISTEN)
java 2147 root 38u IPv6 640859 0t0 TCP *:http-alt (LISTEN)
java 2147 root 40u IPv6 640865 0t0 TCP *:https (LISTEN)
java 2147 root 46u IPv6 640908 0t0 TCP 127.0.0.1:18005 (LISTEN)
java 2147 root 48r IPv6 642625 0t0 TCP 172.24.0.82:48347->172.24.0.82:mysql (ESTABLISHED)
java 2147 root 181u IPv6 640891 0t0 TCP 172.24.0.82:60353->172.24.0.82:mysql (ESTABLISHED)
and after:
java 2147 root 4u IPv6 642769 0t0 TCP 172.24.0.82:48956->172.24.0.82:mysql (ESTABLISHED)
java 2147 root 5u IPv4 640851 0t0 TCP 127.0.0.1:8000->127.0.0.1:34193 (ESTABLISHED)
java 2147 root 38u IPv6 640859 0t0 TCP *:http-alt (LISTEN)
java 2147 root 40u IPv6 640865 0t0 TCP *:https (LISTEN)
java 2147 root 46u IPv6 640908 0t0 TCP 127.0.0.1:18005 (LISTEN)
java 2147 root 181u IPv6 640891 0t0 TCP 172.24.0.82:60353->172.24.0.82:mysql (ESTABLISHED)
exact eclipse error returned is:
Exception occurred during launch
Failed to connect to remote JVM. Connection timed out.
Timeout occurred while waiting for packet 204.
(the packet number varies on each attempt).
in workspace/.metadata/.log i get:
!ENTRY org.eclipse.osgi 2 0 2011-07-17 18:43:53.024
!MESSAGE While loading class "org.eclipse.core.net.proxy.IProxyService", thread "Thread[main,6,main]" timed out waiting (5000ms) for thread "Thread[Thread-6,5,main]" to finish starting bundle "org.eclipse.core.net_1.2.1.r35x_20090812-1200 [232]". To avoid deadlock, thread "Thread[main,6,main]" is proceeding but "org.eclipse.core.net.proxy.IProxyService" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "reference:file:plugins/org.eclipse.core.net_1.2.1.r35x_20090812-1200.jar" by thread "Thread-6".
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1073)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:278)
[...]
!ENTRY org.eclipse.ui.ide 4 4 2011-07-17 18:43:53.028
!MESSAGE Proxy service could not be found.
eclipse is configured for direct internet connection.
EDIT 2
I think the solution might be here:
http://blog.cantremember.com/debugging-with-jconsole-jmx-ssh-tunnels/
but i have some trouble understanding his JNDI/RMI settings, and to what extent that applies to my configuration.
EDIT 3
This is a clarification for those answering "use <lan|local ip address> instead of <localhost>"
computer A: my workstation in the company
computer B: my workstation at home
computer C: server running tomcat
B and C are in two different sub-networks in the same network infrastructure; only connections to port 22 of C from outside are allowed (and somewhat "proxied", I don't know network internals).
A is "outside" (my dsl connection with dynamic ip address).
Debugging on C from B via ssh tunnel -> works
Debugging on C from A via ssh tunnel -> connection timed out while waiting for packet XXX
This article suggests that the default port on which the remote Java virtual machine (JVM) is listening in debugging mode is 1044. You should tunnel the port on which the remote JVM is running as well.
More generally, you could run wireshark/tcpdump to see to which port connection attempts are made when starting the debugger.
EDIT:
A few more things I would try:
check on the remote host (e.g. with ps auxwww if it's Linux) with which arguments (look for what comes behind -Xrunjdwp or with lsof -p PID_OF_JVM_TO_BE_DEBUGGED on which TCP port it listens (look for lines with TCP and LISTEN in the lsof output)
make sure that the JVM on the remote host listens on the lo interface, not the network interface (that's what you specify with the localhost in the -L option to ssh).
Does starting the debugger by hand on the machine where you start eclipse with jdb -attach localhost:8000 work ? (you could also try this on the remote host to ensure the debugger is running on the port 8000)
make sure that eclipse tries to connect to localhost (when not specifying a bind address before the first 8000 with the -L option ssh listens on the lo interface)
I often had this problem when doing remote debugging. I do not know the exact reason for this problem, but I used the below solution and maybe it works for you, too:
instead of
ssh -L 8000:localhost:8000 user#remotehost
is used
ssh -L 8000:remotehost:8000 user#remotehost
for creating the SSH tunnel (note the remotehost instead of localhost between the port numbers in the second example). Instead of the remote host's name, you can also use the normal IP address of the remote host (not the loopback address 127.0.0.1, but the true local network IP address).
Hope it helps and good luck!
Assuming the remote Tomcat instance has been started with something like -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n, try this command:
ssh -L 8000:0.0.0.0:8000 user#mycompany.com -N
On my Mac, I tried out ssh -L 10701:localhost:10700 user#localhost -N locally, where a Tomcat instance was started with -Xrunjdwp:transport=dt_socket,server=y,address=10700,suspend=n, and attempting to attach on port 10701 within Eclipse, I kept seeing "Failed to connect to remote VM com.sun.jdi.connect.spi.ClosedConnectionException". By changing the tunnel command to ssh -L 10701:0.0.0.0:10700 user#localhost -N, Eclipse was able to attach.
Can you please give the exact parameters of the -Xrunjdwp parameter?
Also do you have tried different methods for debugging (server=y/n, suspend=y/n)?
Perhaps inversing the connection (let the tomcat connect to the debugger instead of letting the debugger connect to tomcat) may help.
Well I am answering myself after a long time; in my specific case, the solution was to put eclipse JVM in listening mode:
Connection Type: "Standard (Socket Listen)"
and reverse the direction of the tunnel:
ssh -L 8001:localhost:8001 user#work (run on server (S), "localhost" is W)
ssh -R 8001:localhost:8001 user#work (run at home (H), "localhost" is W)
Some explanation: as in the question, my situation was:
H -------------------> S not working ( ssh -L 8001:S:8001 user#S from H)
H W -------> S working ( ssh -L 8001:S:8001 user#S from W)
home work server
While reversing like this:
H <------- W S ssh -R 8001:localhost:8001 user#W (from H)
H W <------- S ssh -L 8001:localhost:8001 user#W (from S)
home work server
did the trick. In other words, whatever is written on S:8001, is forwarded to W:8001, and whatever in turn is written to W:8001, is forwarded to H:8001, where my eclipse JVM is listening.
The tomcat JVM on S should be started with server=n, with arguments:
-agentlib:jdwp=transport=dt_socket,server=n,suspend=n,address=8001

Categories

Resources