Eric Guo's blog.cloud-mes.com

in HTML5, JavaScript, Ruby & Rails, Python, and Cloud MES!

Deploy TARO Documents to the 4 GB Memory Server

Permalink

The official taro document build setting NODE_OPTIONS=--max-old-space-size=5120 in packages.json, but I would link to deploy a TARO documents to my 4 GB memory server, so here is how to.

Change NODE_OPTIONS settings

Change to NODE_OPTIONS=--max-old-space-size=2500 is reasonable in a 4GB memory server, but that’s far from enough.

Enable the swap

sudo fallocate -l 1G /swapfile
# or sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# To make it permanent
sudo echo '/swapfile swap swap defaults 0 0' >> /etc/fstab

Stop more services while building

sudo systemctl stop postgresql-12
sudo systemctl stop memcached
sudo systemctl stop nginx
sudo systemctl stop docker

It can be restart after reboot.

Install lib vips

The @docusaurus/core like 2.0.0-beta.1 require vips library, so need install vips at CentOS 7

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi
sudo yum install vips vips-devel vips-tools

Deploy New Rails 6 Application in Ubuntu 20.04

Permalink

Create new user

adduser cybros_vendor
sudo su - cybros_vendor
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 "cybros_vendor ALL=(ALL) NOPASSWD:ALL" > 80-cybros_vendor-user

Install nginx

sudo apt-get install nginx

It’s also possible to enable TLS 1.1/1.2 due to Ubuntu 20.04 not support by default.

/etc/nginx/nginx.conf
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
# seclevel for TLS 1.0 and 1.1
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:@SECLEVEL=1";

Install node.js 15 and yarn 1.x

Using nodesource distribution

curl -fsSL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt-get install gcc g++ make git
sudo apt-get install -y nodejs
## To install the Yarn package manager
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
sudo apt-get update && sudo apt-get install yarn

Install rbenv and Ruby 3.0.1

sudo apt install rbenv
sudo su - cybros_vendor
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror
rbenv install 3.0.1
rbenv global 3.0.1
echo "gem: --no-document" > ~/.gemrc
eval "$(rbenv init -)" >> ~/.bash_profile # or past the `rbenv init -`
rbenv shell 3.0.1

Install MySQL Client

sudo apt-get install gnupg2
wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb
sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb
sudo percona-release setup ps80
sudo apt-get install percona-server-client
sudo apt-get install libmysqlclient-dev

Create MySQL DB user

mysql -u root -p
CREATE DATABASE cybros_vendor character set UTF8mb4 collate utf8mb4_bin;
CREATE USER 'cybros_vendor'@'%' IDENTIFIED BY 'cybros_vendor_password';
GRANT ALL ON cybros_vendor.* TO 'cybros_vendor'@'%';
FLUSH PRIVILEGES;

Link rbenv to make capistrano works

mkdir -p ~/.rbenv/bin
cd ~/.rbenv/bin
ln -s /usr/bin/rbenv rbenv

Install Oracle Instant Client

Download Version 19.11.0.0.0 and following ruby-oci8 document

sudo mkdir /opt/oracle
sudo unzip instantclient-basic-linux.x64-19.11.0.0.0dbru.zip -d /opt/oracle
sudo unzip instantclient-sqlplus-linux.x64-19.11.0.0.0dbru.zip -d /opt/oracle/
sudo unzip instantclient-sdk-linux.x64-19.11.0.0.0dbru.zip -d /opt/oracle/
cd /usr/local/bin
sudo ln -s /opt/oracle/instantclient_19_11/sqlplus sqlplus
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_11
gem install ruby-oci8
Append tolink
TNS_ADMIN=/opt/oracle/instantclient_19_11/network/admin
LD_LIBRARY_PATH=/opt/oracle/instantclient_19_11
NLS_LANG=AMERICAN_AMERICA.AL32UTF8

Also need setting in systemd/system/puma_service or side_service

Environment="TNS_ADMIN=/opt/oracle/instantclient_19_11/network/admin"
Environment="LD_LIBRARY_PATH=/opt/oracle/instantclient_19_11"
Environment="NLS_LANG=AMERICAN_AMERICA.AL32UTF8"

Deploy Coreui 4 Beta Demo Site to Aliyun OSS Nginx Host

Permalink

Due to Core UI 4 still no demo site, but I already want to using it, so I built a site myself.

Add a dedicated user

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

Prepare deploy folder

cd /var/www
mkdir coreui4_demo
chown coreui4_demo:coreui4_demo coreui4_demo

Change code to deploy

See cn_site branch for detail modifies.

Do the real deploy

bundle exec cap production deploy

New nginx conf

Sample nginx configure file
server {
server_name coreui.redwoodjs.cn;
index index.html;
root /var/www/coreui4_demo/current/dist;
location / {
try_files $uri $uri/ /index.html;
access_log /var/www/coreui4_demo/shared/log/nginx.access.log;
error_log /var/www/coreui4_demo/shared/log/nginx.error.log;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.wefocusin.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.wefocusin.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = coreui.redwoodjs.cn) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name coreui.redwoodjs.cn;
return 404; # managed by Certbot
}

Triditional Mysqldump Based MySQL DB Migration Hints

Permalink

Dump based on the SQL not fast, but many system doesn’t need either, and the simplicity many times shining instead of faster.

Dump the DB out

mysqldump -u root -p --all-databases | gzip > thape_bidb_all.sql.gz # input password

It’s the slowest part, so maybe Ctrl+Z and bg and disown -h %1 and having a good sleep.

Transfer DB

scp thape_bidb_all.sql.gz target_server:.

Import DB

unzip thape_bidb_all.sql.gz
mysql -u root -p
source thape_bidb_all.sql
\q

Make analyze and optimize

mysqlcheck -u root -p --auto-repair --optimize --all-databases

Oritinal source

Import and Export Mysql DB in Gzip Way

Permalink

Export MySQL in gzip format

mysqldump -u <YOUR USERNAME> -p<PASSWORD> <YOUR DBNAME> | gzip > mysql_cybros_db_`date +%Y%m%d%H%M`.sql.gz

Import directly in gzip format

mysql -u root
DROP DATABASE thape_cybros_dev;
CREATE DATABASE thape_cybros_dev character set UTF8mb4 collate utf8mb4_bin;
\q
# gunzip < mysql_cybros_db.sql.gz | mysql -u root -pPASSWORD thape_cybros_dev
gunzip < mysql_cybros_db.sql.gz | mysql -u root thape_cybros_dev

Check SSD Writen Amount Using Smartctl

Permalink

brew install smartmontools
sudo smartctl -a /dev/disk0
# Percentage Used: 6%
# Data Units Read: 67,399,384 [34.5 TB]
# Data Units Written: 53,574,524 [27.4 TB]

So my 4 years MBP 2016 used 6% of the SSD life time.