Setting up a Go droplet in Digital Ocean
First, ssh into the digitalocean box | ssh root@123.123.123.123
1. Add key to Gitlab / Github so that you can clone the project in your repo and pull when you make a change.
ssh-keygen -t ed25519 -C "<comment>"
vim /root/.ssh/id_ed25519.pub
Add this key to gitlab
Clone the repo
2. Install Go
curl -O https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz
tar xvf go1.15.2.linux-amd64.tar.gz
chown -R root:root ./go
mv go /usr/local
vim ~/.bashrc
(Add the below export commands)
export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
source ~/.bashrc
go version
3. Install Nginx
apt update
apt install nginx
systemctl status nginx
vim /etc/nginx/sites-enabled/default
# Add this in the location block
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
4. Create a systemd service for your server
cd /etc/systemd/system/
touch name.service
# Copy the below service code by changing location
[Unit]
Description= instance to start server
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/{name}
Restart=on-failure
RestartSec=5s
ExecStart=/root/indra/out/{name} server
[Install]
WantedBy=multi-user.target
5. Install Build Essentials for Go to run
apt-get update
apt-get install build-essential
6. Install make (If you are using makefile)
apt install make
7. Install Postgres (or any db | Below points are for postgres)
apt install postgresql postgresql-contrib
sudo -u postgres psql
create user abhi with password 'password';
alter role abhi superuser;
8. Run / Restart services
systemctl start name.service
systemctl restart nginx.service
9. Setting up ulimit (increasing file descriptors, 1024 by default) Making it 65535 to avoid socket: too many open files error
# available limit
user@ubuntu:~$ ulimit -n
1024
# To increase the available limit to say 65535
user@ubuntu:~$ sudo vim /etc/sysctl.conf
# add the following line to it
fs.file-max = 65535
# run this to refresh with new config
user@ubuntu:~$ sudo sysctl -p
# edit the following file
user@ubuntu:~$ sudo vim /etc/security/limits.conf
# add following lines to it
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535
# edit the following file
user@ubuntu:~$ sudo vim /etc/pam.d/common-session
# add this line to it
session required pam_limits.so
# logout and login and try the following command
user@ubuntu:~$ ulimit -n
65535