I've setup a ssh tunnel to allow connecting to NeptuneDB
and now i want to use Java from local machine to connect
to NeptuneDB by using ssh, so is there any way to do that?
Yes it’s possible. You need to add the DNS name of the Neptune cluster to your local hosts file and use that name in your code and when creating the SSH tunnel. Do not use localhost as the SSL certs will not resolve if you do. The line in your hosts file will be of the form:
127.0.0.1 localhost my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com
The ssh tunnel can then be created using something like
ssh -i mypem.pem ec2-user#ec2-xx-xx-xx-xx.compute-1.amazonaws.com -N -L 8182:my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com:8182
In your Java code you can then build the connection something like this:
Cluster.Builder builder = Cluster.build();
builder.addContactPoint("my.cluster-abcdefghijk.us-east-1.neptune.amazonaws.com");
builder.port(8182);
builder.serializer(Serializers.GRAPHBINARY_V1D0);
builder.enableSsl(true);
cluster = builder.create();
drc = DriverRemoteConnection.using(cluster);
g = traversal().withRemote(drc);
Related
I have a Springboot app that I have Dockerized.
I have it exposed on port 8081, and can access it as expected.
http://<ipaddress>:8081
Problem
The Springboot app in the docker container needs to connect to a postgres database on the same host (not in a container), but it appears like it does not gave access to the host network.
Connection to localhost:5432 refused
Docker cmd:
docker run -t --rm -d -p 8081:8081 --name nexct-approval-service-container nexct-approval-service-image
So I have read in order to connect to the network, you can use:
--network host
However, then it stops allowing access to the application itself (port 8081):
WARNING: Published ports are discarded when using host network mode
Question
How can I allow access to the SpringBoot app on port 8081 and allow the Springboot app access to the host network so it can connect to the database?
UPDATE
My database connection is defined in Spring Boot:
application.properties
spring.datasource1.driver-class-name=org.postgresql.Driver
spring.datasource1.jdbc-url=jdbc:postgresql://localhost:5432/pims
spring.datasource1.username=postgres
spring.datasource1.password=
MultipleDBConfig.java
#Configuration
#ComponentScan(basePackages = "com.nexct")
public class MultipleDBConfig {
#Bean(name = "datasource1")
#ConfigurationProperties("spring.datasource1")
#Primary
public DataSource dataSource1(){
return DataSourceBuilder.create().build();
}
#Bean(name = "datasource2")
#ConfigurationProperties("spring.datasource2")
public DataSource dataSource2(){
return DataSourceBuilder.create().build();
}
}
In my service, I replaced the references to localhost with host.docker.internal, and I was able to publish the container's ports with -p and connect to services on localhost without having to use --network host. My services references a .env file that has the hostnames, so I just created another .env file with the updated hostname.
You can not publish port in the network mode host.
Note: Given that the container does not have its own IP-address when using host mode networking, port-mapping does not take effect, and the -p, --publish, -P, and --publish-all option are ignored, producing a warning instead:
host networking
How can I allow access to the SpringBoot app on port 8081 and allow the Springboot app access to the host network so it can connect to the database?
Still, you can not reach to Host network by assigning host network to the container. To reach host Network you can use Host IP or use special DNS for mac and window.
host.docker.internal:DB_PORT
Or you can use Host IP if you are on linux
HOST_IP:DB_PORT
or you can try (works on ubuntu)
docker run -it --rm -e HOST_IP=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p') image_name
Now use HOST_IP as a host name in your application.
You should change : localhost in connection string to :
172.17.0.1 its an IP address of containers network
Then check again.
I'm working on a little java project and I have a problem.
The Mysql-Protocol is blocked by the Firewall and the only ports I'm able to use are 80 or 443. Is there any way to connect to my database over these ports? Acutally I'm using the mysql-connector library for java to connect.
You can change the port of MySQL.
change the port in /etc/mysql/my.cnf
example :
cp /etc/mysql/my.cnf /etc/mysql/my-3307.cnf
//edit my-3307.cnf, for example
port = 3307
basedir = /var/lib/mysql-3307
datadir = /var/lib/mysql-3307
//end-edit
mysql_upgrade --defaults-file=/etc/mysql/my-3307.cnf #checks the syntax and creates the dirs you need.
#start mysqld
mysqld --defaults-file=/etc/mysql/my-3307.cnf
source : http://dev.mysql.com/doc/refman/5.1/en/multiple-servers.html
PS : 443 is default https port. It is not advisable to use this and 80(http) port.
Maybe you can change the MySQL port to 443;
But, i think it's bad...
I recommend you to setup SSH server on 443 port and use it for tunelling traffic to your database and any other service.
Here's how you can tunnel traffic from your local machine to remote database:
ssh -L 9000:localhost:3307 user#1.2.3.4 -p 443
Now you can connect to database, like you have it running locally on localhost:9000. All your traffic to SSH server is encrypted. Check this article for another examples.
You can also check chisel project, however I'm not very familiar with it.
Good afternoon. I'm using Mongodb 2.6.7 + Java driver ( IntelliJ).
Presently i have cluster RF5 4 inst.+1arbiter. I would like to connect to my primary using ssh, but i don't have any idea how to do it...
to connect to local host i'm using -
MongoClient client = new MongoClient( new ServerAddress("localhost", 27003)), but how can i made connection to concert IP address using my xxx.pem key?
Thank You in advance, hope for quick reply
You need to set-up an ssh tunnel. Once the tunnel is set-up, you can connect to your end of the ssh tunnel.
You can set-up the tunnel outsied of your application using the ssh client of your operating system. Or you can use a ssh java library like JSCH and set-up the tunnel from your java application.
i'm coding a command line tool to manage the S3 service. on my local machine, everything works but on the server where it should be executed, fails with the following message:
Error Message: Unable to execute HTTP request: Connection to http://s3.amazonaws.com refused
i make the connection with the following code:
s3 = new AmazonS3Client(credentials,clientConf);
clientConf only sets the protocol to HTTP, as i suspected that maybe could be a problem to connect to HTTPS but i'm having the same result.
now, the server have the following configuration:
debian 6 64 bits
LAMP installed from source
openssl installed from source
java installed from distribution packages packages
this is the network configuration:
auto eth0
iface eth0 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
auto eth0:0
iface eth0:0 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
auto eth0:1
iface eth0:1 inet static
address XX.XX.XX.XX
netmask 255.255.255.255
broadcast XX.XX.XX.XX (same as address)
post-up route add 10.255.255.1 dev eth0
post-up route add default gw 10.255.255.1
wget, telnet, curl, everything works, except this, i have 3 network interfaces as i have 2 SSL and another ip for the other sites.
how i should configure the clientConf to make this work? is a java problem? a network problem? at least, how i can get more debug info? i tried to catch the AmazonClientException exception but doesn't work.
Thanks in advance :)
Regards.
This has been reported as a bug in the Amazon S3 API. Quoth ZachM#AWS:
This appears to be a bug in the SDK. The problem is that the client
configuration object is shared with the Security Token Service client
that DynamoDB uses to establish a session, and it (unlike Dynamo)
doesn't accept the HTTP protocol. There are a couple workarounds:
1) Create your own instance of STSSessionCredentialsProvider and
provide it to your DynamoDB client, or
2) Instead of specifying the protocol in the ClientConfiguration,
specify it with a call to setEndpoint("http://...")
We'll discuss solutions for this bug.
I would recommend using one of the workarounds for now. Good luck getting your connection to work successfully.
(Additional documentation and workarounds)
I have a client server architecture project in android. I cant connect with my public IP to server. I closed firewall, and did the port redirection for server. My friend can connect from outside to my server, but i can't, why? how can it be?..
Thanks..
Which OS are you running your client server code. If Windows, look for c:\Windows\System32\drivers\etc\hosts, if it's linux go the /etc/hosts/ file
Open the file with sudo privileges.
Format:
<IP> <HOSTNAME>.<DOMAIN> <ALIAS>
Example:
127.0.0.1 localhost.localdomain localhost
Add your IP here with domain name. Your Domain Name can be anything and try again. Also your question is a bit vague. Please add more details such as your os env and what exactly are you trying to achieve?