Eric Guo's blog.cloud-mes.com

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

Migrate Capistrano3-puma to Using SystemD Mode and Puma 5.0

Permalink

Source code change

Puma 5.0 removed eaemonization without replacement and finally capistrano3-puma start using systemd to manage the puma server and here is need to do to upgrade puma 4 to puma 5.

Capfile
require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx
+install_plugin Capistrano::Puma::Systemd

Enable deployer user sudo.

sudo su -
cd /etc/sudoers.d/
echo 'deployer ALL=(ALL) NOPASSWD:ALL' > 80-deployer-user
visudo # refresh only

Enable systemd puma.service

sudo mv /etc/systemd/system/puma.service /etc/systemd/system/puma_prod.service
# $get home folder like /home/deployer
cd && pwd
# replace $home with /home/deployer
sudo vi /etc/systemd/system/puma_prod.service
sudo systemctl daemon-reload
sudo systemctl enable puma_prod

NLS_LANG setting for systemd

Modify systemd.conf at /etc/systemd/system.conf

system.conf
DefaultEnvironment="NLS_LANG='AMERICAN_AMERICA.AL32UTF8'"

Export the CSV Directly in Postgresql Psql

Permalink

Export the data from SQL

psql -d postgres
\copy (SELECT vote_options.title, vote_options.vote_index, vote_options.user_votes_count, (DENSE_RANK() OVER(ORDER BY user_votes_count DESC ) ) as rank FROM "vote_options" WHERE "vote_options"."vote_id" = 1 ORDER BY "rank") to 'vote_rank.csv' with csv

Install PostgreSQL 13 and Correct Ruby Pg Gem Support

Permalink

Install postgresql13

Installation is similar to postgresql12.

# postgresql v12.3+ require LLVM-toolset-7-clang
sudo yum install centos-release-scl-rh
sudo yum install llvm-toolset-7-clang
# following https://www.postgresql.org/download/linux/redhat/
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql13-server
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
# Checking DB status
sudo systemctl status postgresql-13.service

Install pg gem correctly

bundle config build.pg --with-pg-config=/usr/pgsql-13/bin/pg_config
bundle install

Install ImageMagick 7.0.10 on CentOS 7.8

Permalink

Go official imageMagick website to download

sudo su -
wget https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-libs-7.0.10-30.x86_64.rpm
wget https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-7.0.10-30.x86_64.rpm
yum install libraqm
yum install fftw
yum install libwebp
rpm -Uvh ImageMagick-libs-7.0.10-30.x86_64.rpm
yum remove ImageMagick # if 6.9.10.68 exist
rpm -Uvh ImageMagick-7.0.10-30.x86_64.rpm

Install Ruby 2.2.10 in New macOS 10.15 and Linux

Permalink

RUBY_CONFIGURE_OPTS=--disable-werror rbenv install 2.2.10

See doc if require.

If in Linux:

sudo apt install gcc-6 g++-6
wget https://github.com/openssl/openssl/archive/OpenSSL_1_0_2j.tar.gz
tar xzf OpenSSL_1_0_2j.tar.gz
cd openssl-OpenSSL_1_0_2j
./config --prefix=/opt/openssl/1.0.2j
make depend
make -j$(nproc)
sudo make install
CC=$(which gcc-6) CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl/1.0.2j" rbenv install 2.2.10

Extend the Disk Size in CentOS Which Running in VMware

Permalink

Largely copy from Linux Techi

Check whether free space is available space in the volume group

[root@localhost dev]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 28896 / <112.88 GiB
Free PE / Size 22047 / 86.12 GiB
VG UUID cUFFyw-wCaq-Ym07-TzQY-mii3-y8Xo-IdQRmn

lvextend command to increase the size

[root@localhost ~]# lvextend -L +80G /dev/mapper/centos-root
Size of logical volume centos/root changed from 100.00 GiB (25600 extents) to 180.00 GiB (46080 extents).
Logical volume centos/root successfully resized.

Run the resize2fs command

[root@localhost ~]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mapper/centos-root
找不到有效的文件系统超级块.

Resolve error due to root is xfs

[root@localhost ~]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Mon Dec 23 14:28:29 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=48xxxx48-xxxx-xxxx-xxxx-xxxxxxxxxxxx /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=8, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 26214400 to 47185920

Presenting Code With Syntax-highlight in Keynote Using Command Tool Highlight

Permalink

Just one line

pbpaste | highlight --syntax=rb -O rtf | pbcopy
pbpaste | highlight --syntax=html -O rtf | pbcopy
pbpaste | highlight --syntax=scss -O rtf | pbcopy
pbpaste | highlight --syntax=jsx -O rtf | pbcopy
pbpaste | python -m json.tool | highlight --syntax=json -O rtf | pbcopy

Click to see more language highlight supported.

Note: install highlight first using brew install highlight, original link