Connect to EC2 via SSH; Install a GUI and RDP. GUI: LXDE; RDP: XRDP; Connect to EC2 via remote desktop; Bonus Materials. Install additional IBus input method; 2. Install Midori browser from.deb package; 3. Set up a swapfile for better performance; 4. Use EC2 as a VPN server; Create an AWS EC2 Set up the security groups. Sudo apt-get install -y mongodb-org -allow-unauthenticated Start MongoDB and add it as a service to be started at boot time sudo systemctl daemon-reload sudo systemctl start mongod sudo systemctl enable mongod Configure MongoDB username and password. To install MongoDB Community on your Ubuntu system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB, and is available from its own dedicated repo.
Here at OptimalBI, we've recently switched from using DynamoDB to MongoDB. However, we still use Amazon's EC2 service to manage our servers. Because MongoDB isn't an Amazon Web Service like DynamoDB is, installing Mongo on one of these servers isn't the most obvious process. It took a while for us to chisel out an internal document giving complete instructions on how to do this, and I have to look it up every time I want a new server which uses Mongo! So, we thought we would share with the world what we've put together.
Creating the Server
- From the AWS EC2 console, select the Launch Instance button to create a new server.
- The first screen is Choose AMI. Choose the Ubuntu server.
- When you get to the Configure Security Group screen, add rules to allow the following ports with a source of My IP.
- SSH: Port 22
- 27017
- 27018
- 27019
- 28017
Note that if your IP address changes, you will need to update the security group settings with your new IP.
Environment
Use a fully patched and updated Ubuntu. Please note that these instructions in this blog are for Ubuntu 16.04, and may become outdated in future.
Here's some AWS documentation with instructions on how to connect to your EC2 instance. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
Installing MongoDB
Run these commands individually from the command line to install MongoDB.
Import public key for package system:
[code]sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 0C49F3730359A14518585931BC711F9BA15703C6[/code]Create list file for apt:
[code]echo 'deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntuxenial/mongodb-org/3.4 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list[/code]Reload package system:
[code]sudo apt update[/code]Install MongoDB package:
[code]sudo apt-get install -y mongodb-org[/code]Hooray! Now MongoDB should be installed. Let's get it running.
Running MongoDB
Start
Run the following command to start MongoDB:
[code]sudo systemctl mongod start[/code]You can verify that MongoDB has started successfully by running this command:
[code]sudo cat /var/log/mongodb/mongod.log[/code]and checking that the following line is printed at the end of the file:
[code][initandlisten] waiting for connections on port 27017[/code]If you wish for Mongo to always run on system start, run the following command:
[code]sudo systemctl enable mongod[/code]
Stop
You can stop MongoDB by running the following command:
[code]sudo systemctl mongod stop[/code]
Authorisation
In order to use MongoDB, we need to create users.
Enable Authorisation
Run the following to open the config file:
[code]sudo nano /etc/mongod.conf[/code]The file should contain a security section which is commented out with a ‘#' symbol. Remove this symbol, and change the section to be the same as the following:
[code]security:
authorization: enabled[/code]Use Crtl+X to close the file. You will be prompted to save your changes. Hit the Y key to do this. You will then be prompted to enter a file name, however, we just want to overwrite the current config file, so hit Enter to save the file under the original name of mongod.conf.
At this point, we should restart Mongo. Enter the following command to do so.
[code]sudo systemctl mongod restart[/code]
Create Administrator
Install Mongodb On Aws Ec2 Ubuntu Ec2
Enter the Mongo shell with the following command, while MongoDB is running:
[code]mongo[/code]The following message should be printed:
[code]MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2[/code]Select the database for user data:
[code]use admin[/code]Create the admin user, replacing and with appropriate values.
[code]db.createUser({user: '', pwd: '', roles:[{role: 'root', db: 'admin'}]})[/code]Now let's exit the Mongo shell:
[code]quit()[/code]To test that the admin user was created successfully, enter the following command, replacing with the username you created before:
[code]mongo -u -p –authenticationDatabase admin[/code]You will be prompted to enter the admin password. Note that no characters are displayed as you type the password.
Create Non-Admin User
Open the Mongo shell again:
[code]mongo[/code]Change to the user-data database:
[code]use user-data[/code]Create the new user, replacing , and with appropriate values. The target database is a new database that you want this user to have access to.
[code]db.createUser({user: '', pwd: '', roles:[{role: 'read', db: 'user-data'}, {role: 'readWrite', db: ''}]})[/code]Let's quit mongo shell:
[code]quit()[/code]You can test that the new user was created successfully by entering this command to connect as the new user. Replace with the username you created in the previous step.
[code]mongo -u -p –authenticationDatabase user-data[/code]
Allowing External Mongo Connections
You may be using a firewall to control the access to the server. If this is the case, you will want to allow all external connections. To do this, we want to edit the MongoDB config file again.
Open mongod.conf with the following command:
[code]sudo nano /etc/mongod.conf[/code]Locate and change bind_ip from 127.0.0.1 to 0.0.0.0.
[code]net:
port: 27017
bindIp: 0.0.0.0[/code]Use Crtl+X to close the file. You will be prompted to save your changes. Hit the Y key to do this. You will then be prompted to enter a file name, however, we just want to overwrite the current config file, so hit Enter to save the file under the original name of mongod.conf.
Restart Mongo for the changes to take effect:
[code]sudo systemctl mongod restart[/code]
By default, Mongo sends its data unencrypted, which is obviously an issue if you're storing data that is even remotely sensitive. At Optimal we use SSL encryption for MongoDB. You can read how to set that up here: https://docs.mongodb.com/manual/tutorial/configure-ssl/
If you want to take it a step further, here is information about how to encrypt everything on the disk: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html
Hopefully this blog has been helpful! Patience pays off here, so if you run into trouble, check over these instructions again carefully. It's very easy to make mistakes!
When the time comes to make use of Mongo, Robo3T (previously known as Robomongo) is a great GUI to use for managing your databases.
Best of luck, and happy databasing.
Sarah – The tea-drinking programmer
Sarah blogs about her learning experiences as she navigates the road from student to professional.
Check out our other AWS blogs here.
Overview
This is an guide on how to set up a AWS EC2 free tier with GUI. The EC2 instance will be able to connect via Remote Desktop Protocol (RDP) or SSH.
You need to create a AWS account: https://portal.aws.amazon.com/billing/signup. You may need to provide your credit card information during the signup process.
Sign in to your AWS Account and go to the AWS EC2 Console: https://aws.amazon.com/console/
ssh_private_key.After that, click Download Key Pair and keep the key file save.
Do a chmod
on the key file
You need to make sure that the ssh_private_key.pem
downloaded is able to execute. Run chmod
to change the permission:
Connect to EC2 via SSH
Once you click the Launch instance , you should be able to see your instance in running state in the web console. Then, you can connect to the EC2 via ssh using the pem
key file. Assuming that your DNS name of your EC2 is ec2-0-1-2-3.ap-northeast-1.compute.amazonaws.com
and it is running at ap-northeast-1
region, you can connect to it using user ubuntu
:
You need to confirm your fingerprint at the first connection attempt.
Install a GUI and RDP
Mongodb On Aws Ec2
GUI: LXDE
I choose LXDE as the GUI of the ubuntu server: https://lxde.sourceforge.net/about.html.
LXDE is a new project aimed to provide a new desktop environment which is lightweight and fast
RDP: XRDP
xrdp is an open-source Remote Desktop Protocol server: http://xrdp.org
xrdp provides a graphical login to remote machines using RDP (Microsoft Remote Desktop Protocol)
Install the packages:
Set a password for your accout
Aws Ec2 Ubuntu Username
You need to also set up a password for the ubuntu. This is for your later use in RDP as RDP only allows you to login an password-protected account.
Connect to EC2 via remote desktop
For mac user, you need to download the Microsoft Remote Desktop. If you are using Windows, you should already have the Remote Desktop application preinstalled.
Launch the app and click Add PC:
Set the PC name (i.e. the DNS name of your machine):
Login with user ubuntu
and the password you set in the previous step.
Bonus Materials
1. Install additional IBus input method
If you want to type Japanese, Chinese, etc. you may need to install an input method. For cangjie, you can install Cangjians via the terminal:
2. Install Midori browser from .deb
package
Midori Browser is a browser web light, fast, secure, free software & open source
Download .deb file: https://astian.org/en/midori-browser/download/ or using wget
:
After that, install the deb
package using dpkg
You may see the dependency problems
like the following:
In this case, update the packages and reinstall midori:
3. Set up a swapfile
for better performance
After that, reboot the machine.
4. Use EC2 as a VPN server
Installing MongoDB
Run these commands individually from the command line to install MongoDB.
Import public key for package system:
[code]sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 0C49F3730359A14518585931BC711F9BA15703C6[/code]Create list file for apt:
[code]echo 'deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntuxenial/mongodb-org/3.4 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list[/code]Reload package system:
[code]sudo apt update[/code]Install MongoDB package:
[code]sudo apt-get install -y mongodb-org[/code]Hooray! Now MongoDB should be installed. Let's get it running.
Running MongoDB
Start
Run the following command to start MongoDB:
[code]sudo systemctl mongod start[/code]You can verify that MongoDB has started successfully by running this command:
[code]sudo cat /var/log/mongodb/mongod.log[/code]and checking that the following line is printed at the end of the file:
[code][initandlisten] waiting for connections on port 27017[/code]If you wish for Mongo to always run on system start, run the following command:
[code]sudo systemctl enable mongod[/code]
Stop
You can stop MongoDB by running the following command:
[code]sudo systemctl mongod stop[/code]
Authorisation
In order to use MongoDB, we need to create users.
Enable Authorisation
Run the following to open the config file:
[code]sudo nano /etc/mongod.conf[/code]The file should contain a security section which is commented out with a ‘#' symbol. Remove this symbol, and change the section to be the same as the following:
[code]security:
authorization: enabled[/code]Use Crtl+X to close the file. You will be prompted to save your changes. Hit the Y key to do this. You will then be prompted to enter a file name, however, we just want to overwrite the current config file, so hit Enter to save the file under the original name of mongod.conf.
At this point, we should restart Mongo. Enter the following command to do so.
[code]sudo systemctl mongod restart[/code]
Create Administrator
Install Mongodb On Aws Ec2 Ubuntu Ec2
Enter the Mongo shell with the following command, while MongoDB is running:
[code]mongo[/code]The following message should be printed:
[code]MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2[/code]Select the database for user data:
[code]use admin[/code]Create the admin user, replacing and with appropriate values.
[code]db.createUser({user: '', pwd: '', roles:[{role: 'root', db: 'admin'}]})[/code]Now let's exit the Mongo shell:
[code]quit()[/code]To test that the admin user was created successfully, enter the following command, replacing with the username you created before:
[code]mongo -u -p –authenticationDatabase admin[/code]You will be prompted to enter the admin password. Note that no characters are displayed as you type the password.
Create Non-Admin User
Open the Mongo shell again:
[code]mongo[/code]Change to the user-data database:
[code]use user-data[/code]Create the new user, replacing , and with appropriate values. The target database is a new database that you want this user to have access to.
[code]db.createUser({user: '', pwd: '', roles:[{role: 'read', db: 'user-data'}, {role: 'readWrite', db: ''}]})[/code]Let's quit mongo shell:
[code]quit()[/code]You can test that the new user was created successfully by entering this command to connect as the new user. Replace with the username you created in the previous step.
[code]mongo -u -p –authenticationDatabase user-data[/code]
Allowing External Mongo Connections
You may be using a firewall to control the access to the server. If this is the case, you will want to allow all external connections. To do this, we want to edit the MongoDB config file again.
Open mongod.conf with the following command:
[code]sudo nano /etc/mongod.conf[/code]Locate and change bind_ip from 127.0.0.1 to 0.0.0.0.
[code]net:
port: 27017
bindIp: 0.0.0.0[/code]Use Crtl+X to close the file. You will be prompted to save your changes. Hit the Y key to do this. You will then be prompted to enter a file name, however, we just want to overwrite the current config file, so hit Enter to save the file under the original name of mongod.conf.
Restart Mongo for the changes to take effect:
[code]sudo systemctl mongod restart[/code]
By default, Mongo sends its data unencrypted, which is obviously an issue if you're storing data that is even remotely sensitive. At Optimal we use SSL encryption for MongoDB. You can read how to set that up here: https://docs.mongodb.com/manual/tutorial/configure-ssl/
If you want to take it a step further, here is information about how to encrypt everything on the disk: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html
Hopefully this blog has been helpful! Patience pays off here, so if you run into trouble, check over these instructions again carefully. It's very easy to make mistakes!
When the time comes to make use of Mongo, Robo3T (previously known as Robomongo) is a great GUI to use for managing your databases.
Best of luck, and happy databasing.
Sarah – The tea-drinking programmer
Sarah blogs about her learning experiences as she navigates the road from student to professional.
Check out our other AWS blogs here.
Overview
This is an guide on how to set up a AWS EC2 free tier with GUI. The EC2 instance will be able to connect via Remote Desktop Protocol (RDP) or SSH.
You need to create a AWS account: https://portal.aws.amazon.com/billing/signup. You may need to provide your credit card information during the signup process.
Sign in to your AWS Account and go to the AWS EC2 Console: https://aws.amazon.com/console/
ssh_private_key.After that, click Download Key Pair and keep the key file save.
Do a chmod
on the key file
You need to make sure that the ssh_private_key.pem
downloaded is able to execute. Run chmod
to change the permission:
Connect to EC2 via SSH
Once you click the Launch instance , you should be able to see your instance in running state in the web console. Then, you can connect to the EC2 via ssh using the pem
key file. Assuming that your DNS name of your EC2 is ec2-0-1-2-3.ap-northeast-1.compute.amazonaws.com
and it is running at ap-northeast-1
region, you can connect to it using user ubuntu
:
You need to confirm your fingerprint at the first connection attempt.
Install a GUI and RDP
Mongodb On Aws Ec2
GUI: LXDE
I choose LXDE as the GUI of the ubuntu server: https://lxde.sourceforge.net/about.html.
LXDE is a new project aimed to provide a new desktop environment which is lightweight and fast
RDP: XRDP
xrdp is an open-source Remote Desktop Protocol server: http://xrdp.org
xrdp provides a graphical login to remote machines using RDP (Microsoft Remote Desktop Protocol)
Install the packages:
Set a password for your accout
Aws Ec2 Ubuntu Username
You need to also set up a password for the ubuntu. This is for your later use in RDP as RDP only allows you to login an password-protected account.
Connect to EC2 via remote desktop
For mac user, you need to download the Microsoft Remote Desktop. If you are using Windows, you should already have the Remote Desktop application preinstalled.
Launch the app and click Add PC:
Set the PC name (i.e. the DNS name of your machine):
Login with user ubuntu
and the password you set in the previous step.
Bonus Materials
1. Install additional IBus input method
If you want to type Japanese, Chinese, etc. you may need to install an input method. For cangjie, you can install Cangjians via the terminal:
2. Install Midori browser from .deb
package
Midori Browser is a browser web light, fast, secure, free software & open source
Download .deb file: https://astian.org/en/midori-browser/download/ or using wget
:
After that, install the deb
package using dpkg
You may see the dependency problems
like the following:
In this case, update the packages and reinstall midori:
3. Set up a swapfile
for better performance
After that, reboot the machine.
4. Use EC2 as a VPN server
Free iphone file transfer software. Create a new security group allows all TCP and UDP inbound connections and add this security group to the EC2 instance:
Install openvpn scripts
This repo contains scripts for VPN server set up and profile management. Install it into your EC2:
Download the script:
Make the openvpn-install.sh
exectable in your EC2:
Add a new profile by running openvpn-install.sh
: How to do a manual backup using terminal in mac os.
Use another Terminal to download the .ovpn
file. Assuming that the machine name is ec2-0-1-2-3.ap-northeast-1.compute.amazonaws.com
and the generated .ovpn
file is place under ~/
:
Connect to the VPN
Pritunl Client is a easy-to-use OpenVPN client. Downlaod and install it.
Launch the client and click Import Profile:
After that, click the burger menu of the profile and Connect.
Reference: