- For UNIX
- Check if key already exists.
cat ~/.ssh/id_rsa.pub
- If key does not exist, generate it.
ssh-keygen
- The default location is best.
- A passcode is only needed for high security sites, just don't lose your computer.
- You can find your public key in the file with a .pub extension.
- Check if key already exists.
- For Windows
- Run puttyGen and generate a key.
- You can get the public key in puttyGen in the upper window.
- Save the private key somewhere.
- Make sure to point putty and WinSCP to the private key.
- Create a server.
- Make sure to set the server to ubuntu 16.04.
- 32-bit is recommended unless you have more than 4gb of RAM, except for if you use Aerospike, which requires 64-bit for both main database and API.
- Make sure you turn on private networking so you can connect to your database without using up bandwidth.
- Make sure you have put in an ssh key here to avoid unsecure password logins.
- It is a good idea to turn on IPv6 so your server will support it.
- Connect to server's root account.
- Use ssh on unix machines.
ssh root@<ip_address>
- Make sure you have setup ssh keys with your computer.
- Windows users should use putty.
- Use ssh on unix machines.
- Create a user with sudo access.
adduser <username>
- Make sure to put in a good password!
- You can leave the other settings blank, just keep pressing enter.
- Give the user sudo access.
gpasswd -a <username> sudo
- Add ssh key access to new user account.
- Flip your access to the new user.
su <username>
- Move to the home directory.
cd
- Create folder and restrict access to only yourself.
mkdir .ssh
chmod 700 .ssh
- Create a file and add ssh key to it.
nano .ssh/authorized_keys
- Paste key into file and save and exit with Ctrl-X.
- Ctrl-Shift-V for unix users to paste.
- Right-click in window to paste for putty.
- Restrict the permissions of the file.
chmod 600 .ssh/authorized_keys
- Return to root.
exit
- Test if it worked.
- Connect to your new account with either putty or ssh
ssh <username>@<ip_address>
- If it asks for your password, something went wrong.
- Connect to your new account with either putty or ssh
- Flip your access to the new user.
- Restrict ssh access to root and password connections.
- As root, edit the settings in the ssh config file.
nano /etc/ssh/sshd_config
- Set the line
PermitRootLogin
to no to disable root login. - Set the line
PasswordAuthentication
to no to disable logging in with a password.- Make sure to uncomment the line as well.
- Restart the ssh service.
service ssh restart
- Make sure you test if you can still access it with normal connection before you disconnect the root terminal.
- And test that the root login really is disabled.
- As root, edit the settings in the ssh config file.
- Setup firewall.
- Allow ssh through the firewall.
sudo ufw allow ssh
- or
sudo ufw allow 22/tcp
- Examine the rules.
sudo ufw show added
- If everything looks right, enable the firewall.
sudo ufw enable
- Make sure everything is running right.
sudo ufw status
- Allow ssh through the firewall.
- Synchronize the system clock.
- Set timezone.
sudo dpkg-reconfigure tzdata
- A graphical menu will allow you to choose a city to sync time with.
- Install NTP.
- If you have not used apt-get yet, run
sudo apt-get update
sudo apt-get install ntp
- ntp will automatically place enable run on boot.
- If you have not used apt-get yet, run
- Set timezone.
- Create a swapspace.
- Reserve the space.
sudo fallocate -l <size> /swapfile
<size>
is something like1G
or512M
- Restrict access to root only.
sudo chmod 600 /swapfile
- Configure into a swapfile.
sudo mkswap /swapfile
- Start using the swapfile.
sudo swapon /swapfile
- Setup automatically using the swapfile on boot.
sudo sh -c 'echo "/swapfile none swap sw 0 0" >> /etc/fstab'
- Reserve the space.
- This is a good point to make a snapshot of your server.
- Shut the server down.
sudo poweroff
- Save a snapshot in the digitalocean console.
- Shut the server down.
- (optional) install Go.
- If you have Go 1.5 or newer, you can cross compile most programs and transfer the executable.
- Some packages still require a native Go install to build though.
- Download Go.
wget <url>
- The url for 32-bit 1.7.1 is
https://storage.googleapis.com/golang/go1.7.1.linux-386.tar.gz
- The url for 64-bit 1.7.1 is
https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
- Extract Go from the archive file.
tar -xf <filename>
- Move Go to the default install location.
sudo mv go /usr/local/go
- Change owner to root and alter permissions.
sudo chown root:root /usr/local/go
sudo chmod 755 /usr/local/go
- Create workspace folder.
mkdir <workspace_name>{,/bin,/pkg,/src}
- Edit environment variables.
- Use
nano <filename>
to edit the file.- You have to use
sudo nano <filename>
to edit a file that does not start in~/
- You have to use
- Add
export PATH=$PATH:/usr/local/go/bin
to/etc/profile
- Add
export GOPATH=$HOME/<workspace_name>
to~/.profile
- Add
export PATH=$HOME/<workspace_name>/bin:$PATH
to~/.profile
- Use
- Delete the go archive file.
rm <filename>
- This will probably be called something like:
go1.7.1.linux-386.tar.gz
- This will probably be called something like:
- Install git.
sudo apt-get install git
- Reconnect to the server to allow environment variables to update.
- Adjust firewall to allow http connections.
- Allow http through the firewall.
sudo ufw allow http
- or
sudo ufw allow 80/tcp
- Allow https through the firewall, if needed.
sudo ufw allow https
- or
sudo ufw allow 443/tcp
- Allow http through the firewall.
- Setup haproxy.
-
Install haproxy.
sudo apt-get install haproxy
-
Configure haproxy.
- Edit
/etc/haproxy/haproxy.cfg
- Add
retries 3
to the default section. - Add
option redispatch
to the default section. - Add the following block to the end of the file:
listen serv bind *:80 mode http option http-server-close timeout http-keep-alive 3000 server serv 127.0.0.1:9000 check
- If you want to bind to both IPv6 and IPv4, change the bind command to
bind :::80 v4v6
- If your server can handle https traffic, change mode to
mode tcp
- Edit
-
More information available here.
-
- Reload haproxy
sudo service haproxy reload
-
Get your code onto the server.
- If you are on windows, use WinSCP.
- If you are on a unix machine, use scp.
scp <source> <destination>
- Add -rp if it is a folder you are transfering.
scp -rp <source> <destination>
- The format for remote connections is
<username>@<ip_address>:<path>
- Example:
scp -rp ~/Desktop/testServer [email protected]:~/testServer
- Make sure it is built, whether on your system or on the server directly.
-
Configure systemd.
- Create configuration file:
sudo nano /etc/systemd/system/<filename>.service
- can be anything, just remember what it is so you can use it below.
- Add the following code to the file:
[Unit] Description=Go Server [Service] ExecStart=/home/<username>/<exepath> WorkingDirectory=/home/<username>/<exefolderpath> User=<username> Group=<username> Restart=always [Install] WantedBy=multi-user.target
- Add the service to systemd.
sudo systemctl enable <filename>.service
- Activate the service.
sudo systemctl start <filename>.service
- Check if systemd started it.
sudo systemctl status <filename>.service
- More information about systemd commands can be found here.
- Check if the server is running with your web-browser, just use the server ip address as the url.
- Create configuration file:
- Download and install Aerospike.
- Aerospike only works for 64-bit machines unless you build it from source yourself, and recommends at least 2gb of RAM.
- You can get step-by-step instructions for installation here.
- Download the archive file.
wget -O aerospike.tgz 'http://aerospike.com/download/server/latest/artifact/ubuntu12'
- Extract the archive file.
tar -xvf aerospike.tgz
- Go into the directory on run the installer.
cd aerospike-server-community-*-ubuntu12
sudo ./asinstall
- Allow the database port through the firewall.
sudo ufw allow in on eth1 to any port 3000 proto tcp
- Start the service.
sudo service aerospike start
- Check when it is ready with:
sudo tail -f /var/log/aerospike/aerospike.log | grep cake
- Delete the aerospike install files.
- rm -rf aerospike*
- Install Aerospike management server (optional).
- Install python2.x, python development libraries, and gcc
sudo apt-get install python gcc python-dev
- Download the package file.
wget -O amc.deb http://www.aerospike.com/download/amc/latest/artifact/ubuntu12
- Install the server.
sudo dpkg -i amc.deb
- Allow the server port through the firewall.
sudo ufw allow 8081/tcp
- Start the server.
sudo /etc/init.d/amc start
- Examine the amc in your web-browser, address is:
<server_ip>:8081
- When it asks you for the ip of a node, enter the localhost ip:
127.0.0.1
- When it asks you for the ip of a node, enter the localhost ip:
- Delete amc install file.
rm amc.deb
- Configure Aerospike.
- Add namespaces as needed.
sudo nano /etc/aerospike/aerospike.conf
- At the bottom of the file is the test and bar namespaces, comment them out and use them as examples.
- This is also the file where you can configure having multiple nodes in a cluster. More information on configuring Aerospike here.
- Restart Aerospike.
sudo service aerospike restart
- Get the go client library (64-bit only).
*
go get github.com/aerospike/aerospike-client-go
- Run the benchmark tool, (64-bit only).
* Change into the client code directory, tools/benchmark
cd $GOPATH/src/github.com/aerospike/aerospike-client-go/tools/benchmark
* Run the tool.go run benchmark.go -h <ip_address>
- Note this will only work from a server in digitalocean, since the firewall is configured to only allow connections from eth1, which is the private network.
- Private ip address can be found with:
ifconfig | grep "inet addr"
, the middle address should be the private one.
- The godoc page is very large, but has everything, including enterprise edition commands.
- Information on connecting can be found here.
- Information on writing a record, including how to write to a single value in a field and how to set an expiration date for data can be found here.
- Information on reading a record, including only getting parts of an object, can be found here.
- Information on queries can be found here.
- When you are querying on something, make sure you add a secondary index for that field. You can do that programmatically with Go, or using the Aerospike management server.