synching postgresql database between two EC2 instances - amazon-web-services

When running (fictitious ip addresses) on an EC2 instance that is intended to be a slave postgresql database:
ubuntu#ip-127-31-71-50:/var/lib/postgresql/9.3$ sudo -u postgres pg_basebackup -h 54.419.311.274 -D /var/lib/postgresql/9.3/main -U rep -v -P -x
The response is:
pg_basebackup: could not connect to server: could not connect to server: Connection refused
Is the server running on host "54.419.311.274" and accepting
TCP/IP connections on port 5432?
Having run this command on non_AWS instances successfully, I wonder what configuration is required under AWS to make this run properly.
User postgres exists on the master as
sudo su postgres
allows editing postgre via its main user.
postgresql.conf on master EC2 instance has
listen_addresses = 'localhost,54.419.311.274,54.86.79.188'
What am I missing?

Related

Jenkins installed via docker cannot run on AWS EC2

I'm new to devops. I want to install Jenkins in AWS EC2 with docker.
I have installed the Jenkins by this command:
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
On AWS security group, I have enabled port 8080 and 50000. I also enabled port 22 for SSH, 27017 for Mongo and 3000 for Node.
I can see the Jenkins container when I run docker ps. However, when I run https://xxxx.us-east-2.compute.amazonaws.com:8080, there is not a Jenkins window popup for Jenkins setting and display error, ERR_SSL_PROTOCOL_ERROR.
Does someone know what's wrong here? Should I install Nginx as well? I didn't install it yet.
The error is due to the fact that you are using https:
https://xxxx.us-east-2.compute.amazonaws.com:8080
From your description it does not seem that you've setup any type of ssl connection to your instance. So you should connect using http only:
http://xxxx.us-east-2.compute.amazonaws.com:8080
But this is not good practice as you communicate using plain text. A common solution is to access your jenkins web-ui through ssh tunnel. This way the connection is encrypted and you don't have to exposed any jenkins port in your security groups.

Problem with run docker from Apache AMI (AWS)

I created a web server with apache and php in AWS. Then I created a docker with the AMI from web server.
tar -c -C /mnt/ . | docker import - MY-IMAGE-NAME
The image was created:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
workshop latest 6de90688f964 About a minute ago 1.14GB
I ran the docker exposing the port 80
docker run -tid -p 80:80 6de90688f964 /bin/bash
But I cant load the web. I used the public IP from the docker server. When I used curl I obtained
root#ip-10-10-0-10:/home/ubuntu# curl 18.206.153.112
curl: (7) Failed to connect to 18.206.153.112 port 80: Connection refused
Could you help me?
You need to adjust the security policy for this AWS Instance to allow TCP
inbound traffic on port 80 (EC2 Dashboard --> Security Groups).
Something like this:

Connection Refused on AWS Instance?

I have a linux AWS instance. I am running the following script on it:
#!/usr/bin/env bash
#This script installs java, sbt and the application
#Run this script on a new EC2 instance as the user-data script, which is run by `root` on machine start-up.
sudo yum update -y
sudo yum install -y docker
sudo service docker start
docker run repo/carrie
Everything installs and I get the below message in the logs:
REST interface bound to /0.0.0.0:8080
However when I try to actually access the port like so:
curl 0.0.0.0/8080
I get the below message:
Failed to connect to 0.0.0.0 port 8080: Connection refused
I have tried editing the inbound rules so that 8080 is open but it doesn't seem to work. Maybe because I'm editing the rules after the instance has already launched?
You have to publish the container's port to the host in the docker run command
$ docker run --help
...
-p, --publish list Publish a container's port(s) to the host
...
The last line of your script should look like this if the process in the container listens on port 80:
docker run -p 8080:80 repo/carrie
The container gets its own interface, hence host's 0.0.0.0 is not applicable.
Tell docker to bind container port 8080 out to the host:
docker run -p 8080:8080 repo/carrie

Connect a docker node running on a separate ec2 host to Jenkins

I have 2 aws ec2 instances. One instance is running Jenkins, the other is running Docker. I am trying to connect the container running on the Docker host to Jenkins as a node.
To start the container on the Docker host I ran the following:
sudo dockerd -H tcp://127.0.0.1:2376 -H unix:///var/run/docker.sock
In the cloud settings (under jenkins/configure)
Docker Host URI:
tcp://IP-ADDRESS-OF-EC2-DOCKER-HOST:2376
Docker Hostname or IP address: IP-ADDRESS-OF-EC2-DOCKER-HOST
Dockerfile:
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install openjdk-8-jdk -y
RUN mkdir -p /home/jenkins
EXPOSE 22
ec2 Docker host security open incoming ports: 2375, 2376, 4243, 22
When I hit the "Test Connection" button, I get:
Connection refused: /IP-ADDRESS-OF-EC2-DOCKER-HOST:2376
java.net.ConnectException: Connection refused
Caused: io.netty.channel.AbstractChannel$AnnotatedConnectException:
Connection refused: /IP-ADDRESS-OF-EC2-DOCKER-HOST:2376
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at
sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:352)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:748)
On another stackoverflow post, someone recommended hitting the "Apply" button first, but that doesn't work because I get an error popup stactrace stating a java.lang.NullPointerException.
Try giving IP-ADDRESS-OF-EC2-DOCKER-HOST instead of 127.0.0.1 in below CMD
sudo dockerd -H tcp://127.0.0.1:2376 -H unix:///var/run/docker.sock
Test port is open from docker to Jenkins host using
telnet docker_host_ ip 2376

How to setup SSH tunneling in AWS

I have a RDS instance with mysql database and which can only be accessed by an ec2 instance running in AWS. Now i want to access my RDS instance from local machine using SSH tunneling. I searched a lot on the net but none of the solutions worked. Can any one please tell me how to do it step by step with working solution.
Any help will be highly appreciated!
I tried to run -
ssh -i myNewKey.pem -N -L 3306:myredinstance:3306 ec2-user#myec2-instance.
mysql -u dbauser -p -h 127.0.0.1 on mysql-js utility and it gave me error. Please see below :-
You can do it by setting up a ssh tunel
ssh -i /path/to/key -N -L 3306:an_rds_endpoint:3306 user#yourserver.com
Then connect locally
mysql -u myuser -p -h 127.0.0.1