Eric Guo's blog.cloud-mes.com

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Deploy Rails 7.0 in a New Aliyun Ubuntu 22.04 Server

Permalink

Another brand new Ubuntu 22.04 server and another installation log.

Install as root

Install htop and atop

apt-get install htop atop

Install nginx

apt-get install nginx
nginx -v # here is nginx 1.18.0

Install node.js v20

Using nodesource distribution

apt-get install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
apt-get install -y nodejs
nodejs --version # here is nodejs v20.16.0

Install Rust

apt install rustc
rustc --version # here is rustc 1.75.0

Install Yarn

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
yarn --version # here is yarn 1.22.22

Install PostgreSQL 16

Reference

Add PostgreSQL Repository

apt install gnupg2 wget
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
sudo apt update

Install PostgreSQL 16

sudo apt install postgresql-16 postgresql-contrib-16 libpq-dev

Make sure PG16 works

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo -u postgres psql # here is 16.3 (Ubuntu 16.3-1.pgdg22.04+1)

Create user and DB

sudo su - postgres
createuser sdassi_user
psql
ALTER ROLE sdassi_user LOGIN;
CREATE DATABASE sdassi_wefocusin_db WITH ENCODING='UTF8' OWNER=sdassi_user;
logout

Install Redis 7

Reference

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

Install as user

Create new user

adduser sdassi_user
sudo su - sdassi_user
mkdir .ssh
chmod 700 .ssh
vi .ssh/authorized_keys # and paste your public key
chmod 600 .ssh/authorized_keys

Enable new user as sudo

sudo su -
cd /etc/sudoers.d/
echo "sdassi_user ALL=(ALL) NOPASSWD:ALL" > 85-sdassi-user

Install rbenv and Ruby 3.3.4

sudo apt-get install libyaml-dev
sudo apt install rbenv
sudo su - sdassi_user
mkdir -p "$(rbenv root)"/plugins
git clone https://git.thape.com.cn/rails/ruby-build.git "$(rbenv root)"/plugins/ruby-build
git clone https://git.thape.com.cn/rails/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror
rbenv install 3.3.4
rbenv global 3.3.4
echo "gem: --no-document" > ~/.gemrc
eval "$(rbenv init -)" >> ~/.bash_profile # or past the `rbenv init -`
rbenv shell 3.3.4
ruby --version --yjit # here is ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [x86_64-linux]

create deploy folder

cd /var/www
sudo mkdir sdassi_oa
sudo chown sdassi_user:sdassi_user sdassi_oa/

The extra file for capistrano

The puma file which will lauch puma via system service.

/var/www/sdassi_oa/shared/puma.rb
#!/usr/bin/env puma
directory '/var/www/sdassi_oa/current'
rackup "/var/www/sdassi_oa/current/config.ru"
environment 'production'
tag ''
pidfile "/var/www/sdassi_oa/shared/tmp/pids/puma.pid"
state_path "/var/www/sdassi_oa/shared/tmp/pids/puma.state"
stdout_redirect '/var/www/sdassi_oa/shared/log/puma_access.log', '/var/www/sdassi_oa/shared/log/puma_error.log', true
threads 0,16
bind 'unix:///var/www/sdassi_oa/shared/tmp/sockets/puma.sock'
workers 0
restart_command 'bundle exec puma'
prune_bundler
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = ""
end

Comments