Last active
August 30, 2018 10:24
-
-
Save bkawk/a088d0df1a5f7fd13e8aad1994c930c3 to your computer and use it in GitHub Desktop.
api server setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONNECT & UPDATE | |
========================= | |
ssh [email protected] | |
sudo apt-get update | |
UPDATE NODE | |
========================= | |
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
MAKE DIRECTORIES | |
========================= | |
cd ../ | |
cd var | |
mkdir repo | |
mkdir www | |
Cd repo | |
Mkdir api0.git | |
Mkdir api1.git | |
INITIALISE GIT | |
========================= | |
cd api0.git | |
git init --bare | |
cd ../ | |
cd api1.git | |
git init --bare | |
cd ../ | |
CONFIGURE GIT | |
========================= | |
cd api0.git | |
cd hooks | |
cat > post-receive | |
#!/bin/sh | |
git --work-tree=/var/www/api0.swarm.city --git-dir=/var/repo/api0.git checkout -f | |
cd /var/www/api0.swarm.city && npm install | |
chmod +x post-receive | |
cd../../ | |
cd api1.git | |
cd hooks | |
cat > post-receive | |
#!/bin/sh | |
git --work-tree=/var/www/api1.swarm.city --git-dir=/var/repo/api1.git checkout -f | |
cd /var/www/api1.swarm.city && npm install | |
chmod +x post-receive | |
SETUP GIT KRAKEN | |
========================= | |
In git kraken add these as remotes, then in local right mouse and select "Set Upstream" | |
ssh://[email protected]/var/repo/api0.git | |
ssh://[email protected]/var/repo/api1.git | |
INSTALL NODE | |
========================= | |
cd ~ | |
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh | |
sudo bash nodesource_setup.sh | |
sudo apt-get install nodejs | |
sudo apt-get install build-essential | |
INSTALL PM2 | |
========================= | |
sudo npm install -g pm2 | |
cd /var/www/api0.swarm.city | |
pm2 start index.js -i max --watch | |
cd /var/www/api1.swarm.city | |
pm2 start index.js -i max --watch | |
Pm2 save | |
pm2 startup systemd | |
INSTALL NGINX | |
======================== | |
sudo apt-get install nginx | |
CONFIGURE NGINX | |
======================== | |
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/api0.swarm.city | |
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/api1.swarm.city | |
sudo nano /etc/nginx/sites-available/api0.swarm.city | |
sudo nano /etc/nginx/sites-available/api1.swarm.city | |
sudo ln -s /etc/nginx/sites-available/api0.swarm.city /etc/nginx/sites-enabled/ | |
sudo ln -s /etc/nginx/sites-available/api1.swarm.city /etc/nginx/sites-enabled/ | |
sudo nano /etc/nginx/nginx.conf | |
Uncomment erver_names_hash_bucket_size 64; | |
nano api0.swarm.city | |
nano api1.swarm.city | |
server { | |
listen 80; | |
listen [::]:80; | |
root /var/www/api1.swarm.city; | |
server_name api1.swarm.city; | |
location / { | |
proxy_pass http://localhost:4000; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
} | |
ADD SSH KEYS | |
======================== | |
cd ~/.ssh | |
nano authorized_keys | |
(Then add in the key you want to add) | |
nano /etc/ssh/sshd_config | |
Change PermitRootLogin yes to PermitRootLogin without-password | |
sudo systemctl reload sshd.service | |
SETUP INSTRUCTION | |
========================= | |
1) Clone the Repo SwarmCityApiMin to a new local folder | |
2) Pull the repo | |
2) Add two remotes called api0 and api1 with the push and pull urls | |
ssh://[email protected]/var/repo/api0.git | |
ssh://[email protected]/var/repo/api1.git | |
INSTALL SSL | |
======================== | |
sudo add-apt-repository ppa:certbot/certbot | |
sudo apt-get update | |
sudo apt-get install python-certbot-nginx | |
== FIREWALL | |
Sudo uff enable | |
sudo ufw allow 'Nginx Full' | |
sudo certbot --nginx -d api1.swarm.city | |
sudo certbot --nginx -d api0.swarm.city | |
(Provide email and agree along the way) | |
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/api1.swarm.city | |
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/api0.swarm.city | |
sudo certbot renew --dry-run | |
CONFIGURE COMPRESSION AND CACHE | |
==================================== | |
sudo nano /etc/nginx/nginx.conf | |
gzip_vary on; | |
gzip_min_length 1100; | |
gzip_buffers 4 32k; | |
gzip_types text/plain application/x-javascript text/xml text/css; | |
sudo systemctl restart nginx | |
INSTALL IPFS | |
==================================== | |
sudo apt-get update | |
sudo apt-get upgrade -y | |
wget https://dist.ipfs.io/go-ipfs/v0.4.9/go-ipfs_v0.4.9_linux-amd64.tar.gz | |
tar xvf go-ipfs_v0.4.9_linux-amd64.tar.gz | |
cd go-ipfs | |
sudo ./install.sh | |
ipfs version | |
ipfs init | |
peer identity: QmWvEzo4C7FVsrhcBHuZ2Ms1MCAY6X1wyQNTumKQtfYbmB | |
cd /lib/systemd/system/ | |
nano ipfs.service | |
[Unit] | |
Description=ipfs daemon | |
[Service] | |
ExecStart=/usr/local/bin/ipfs daemon | |
Restart=always | |
User=root | |
Group=root | |
[Install] | |
WantedBy=multi-user.target | |
systemctl daemon-reload | |
systemctl enable ipfs.service | |
systemctl start ipfs | |
journalctl -u ipfs -n20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment