Skip to content

Instantly share code, notes, and snippets.

@Sophiliya
Created December 10, 2019 05:32
Show Gist options
  • Save Sophiliya/71042a9a476c126cd9f9350d584fb9cb to your computer and use it in GitHub Desktop.
Save Sophiliya/71042a9a476c126cd9f9350d584fb9cb to your computer and use it in GitHub Desktop.

Sanjar's gist:

https://gist.github.com/the-sanjar/0f755693cd987fc85605119bc5b6679d

Configure staging server

https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04

log in as the root user:

ssh [email protected]

create new user (set password):

adduser deployer

as root, add your new user to the sudo group:

gpasswd -a deployer sudo

The next step in securing your server is to set up public key authentication for your new user.

Setting this up will increase the security of your server by requiring a private SSH key to log in.

If your local machine has the ssh-copy-id script installed, you can use it to install your public key to any user that you have login credentials for.

ssh-copy-id [email protected]

On the server, as the root user, enter the following command to switch to the new user:

su - deployer

Now that we have our new account, we can secure our server a little bit by modifying its SSH daemon configuration

(the program that allows us to log in remotely) to disallow remote SSH access to the root account.

Begin by opening the configuration file with your text editor as root:

nano /etc/ssh/sshd_config

Modify this line to “no” like this to disable root login:

PermitRootLogin no

Now that we have made our change, we need to restart the SSH service so that it will use our new configuration.

service ssh restart

########################################

https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/install_language_runtime.html

Install dependencies

sudo apt-get update sudo apt-get install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev nodejs libsqlite3-dev sqlite3

Install RVM:

sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 curl -sSL https://get.rvm.io | sudo bash -s stable sudo usermod -a -G rvm whoami

When you are done with all this, relogin to your server to activate RVM.

Install the Ruby version you want:

rvm install ruby-2.5.1 rvm --default use ruby-2.5.1 rvm use 2.5.1@sound-service --create

Install Bundler:

$ gem install bundler --no-rdoc --no-ri

If you are using Rails, then you must install Node.js.

This is because Rails's asset pipeline compiler requires a Javascript runtime. The Node.js version does not matter.

$ sudo apt-get install -y nodejs && sudo ln -sf /usr/bin/nodejs /usr/local/bin/node

Installing Passenger + Nginx on a Linux/Unix production server

https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/xenial/install_passenger.html

Step 1: install Passenger packages

These commands will install Passenger + Nginx through Phusion's APT repository.

If you already had Nginx installed, then these commands will upgrade Nginx to Phusion's version (with Passenger compiled in).

Install GPG key and add HTTP support for APT

sudo apt-get install -y dirmngr gnupg sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 sudo apt-get install -y apt-transport-https ca-certificates

Add an APT repository

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list' sudo apt-get update

Install Passenger + Nginx

sudo apt-get install -y nginx-extras passenger

Step 2: enable the Passenger Nginx module and restart Nginx

Edit /etc/nginx/nginx.conf and uncomment include /etc/nginx/passenger.conf; if it's commented.

If include /etc/nginx/passenger.conf; doesn't exist in the config, add it manually like in example:

http { include /etc/nginx/passenger.conf; ... }

When you are finished with this step, restart Nginx:

sudo service nginx restart

Step 3: check installation

After installation, please validate the install by running

Step 4: update regularly

Nginx updates, Passenger updates and system updates are delivered through the APT package manager regularly.

You should run the following command regularly to keep them up to date:

sudo apt-get update sudo apt-get upgrade

You do not need to restart Nginx or Passenger after an update, and you also do not need to modify any configuration files after an update.

That is all taken care of automatically for you by APT.

#######################################

PostgreSQL

Install Postgres

sudo apt-get update sudo apt-get install postgresql postgresql-contrib

create user as in production:

sudo -u postgres psql postgres=# create user sound_service_dba; postgres=# create database sound_service;

Install redis-server

sudo apt-get install redis-server

#######################################

Настройка Nginx

Open Nginx config

sudo nano /etc/nginx/nginx.conf

Add the following code in 'http' block

server { listen 80; server_name ; root /var/www/sound-service/current/public; passenger_enabled on; }

Then restart nginx

sudo service nginx restart

#######################################

Locally:

Настройка config/deploy/staging.rb

config/deploy/staging.rb: server '46.229.213.171', user: 'deployer', ssh_options: { user: 'deployer', # overrides user setting above keys: %w[~/.ssh/id_rsa], forward_agent: true, auth_methods: %w[publickey password] }

если при деплое будет ошибка доступа к репозиторию, нужно выполнить на локальной машине команду:

ssh-add ~/.ssh/id_rsa

#######################################

Если возникают проблемы:

ERROR: need to have libshout and shout/shout.h to compile this module

sudo apt-get install libshout3-dev

Install Yarn Packege Management On Ubuntu 16.04 | 18.04 | 18.10

Add Yarn APT Repository:

sudo apt update sudo apt install curl curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Next, run the commands below to add the repository:

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

run the commands below to install Yarn:

sudo apt update sudo apt install yarn

verify Yarn is Installed

yarn --version

PG::ConnectionBad: FATAL: Peer authentication failed for user "sound_service_dba"

Если необходимо, поменять 'peer' на 'md5' в конфиге: sudo nano /etc/postgresql/9.X/main/pg_hba.conf

чтоб найти файл pg_hba:

psql -t -P format=unaligned -c 'show hba_file';

Webpacker compilation failed:

Add staging to webpacker.yml as production.

Настроить time zone

Reinstalling postgres:

List All Postgres related packages:

dpkg -l | grep postgres

Remove all above listed:

sudo apt-get --purge remove postgresql postgresql-9.5 ... ... ...

Remove the following folders:

sudo rm -rf /var/lib/postgresql/ sudo rm -rf /var/log/postgresql/ sudo rm -rf /etc/postgresql/

Remove the postgres user:

sudo deluser postgres

Installing PostgreSQL 10 On Ubuntu 16.04:

Add PostgresSQL Repository to Ubuntu:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" > /etc/apt/sources.list.d/PostgreSQL.list'

Update and Install PostgreSQL:

sudo apt update sudo apt-get install postgresql-10

#######################################

Errors handling:

if rvm exit error status 2:

add to staging.rb: set :rvm_type, :system

to remove bundler if already installed:

rvm @global do gem uninstall bundler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment