Eric Guo's blog.cloud-mes.com

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

Install Snell-server in CentOS 7

Permalink

Prepare the execution files & account

adduser snell
sudo su - snell
mkdir .ssh
chmod 700 .ssh
vi .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
wget https://github.com/surge-networks/snell/releases/download/v1.1.1/snell-server-v1.1.1-linux-amd64.zip
unzip snell-server-v1.1.1-linux-amd64.zip
mkdir snell
mv snell-server snell
rm snell-server-v1.1.1-linux-amd64.zip
cd snell
./snell-server # generate conf file

Configure the system auto start

vi /etc/systemd/system/snell.service
[Unit]
Description=Snell Proxy Service
After=network.target
[Service]
Type=simple
User=snell
Group=snell
LimitNOFILE=32768
ExecStart=/home/snell/snell/snell-server -c /home/snell/snell/snell-server.conf
[Install]
WantedBy=multi-user.target

Restart or run below

systemctl daemon-reload
systemctl start snell
systemctl restart snell
systemctl enable snell
cat /home/snell/snell/snell-server.conf

Ubuntu 18.04 Ruby on Rails Installation Log

Permalink

Enable the Firewall

ufw app list
ufw allow ssh
ufw enable
ufw status

Install node.js

apt install nodejs
apt install npm
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt-get install -y nodejs
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn

Install rbenv

apt update
apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
apt install git
logout # as ubuntu
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
type rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror
rbenv install -l

Install ruby 2.6.5

rbenv install 2.6.5
rbenv global 2.6.5
echo "gem: --no-document" > ~/.gemrc
gem install bundler
gem install rails
rbenv rehash

Install postgresql

apt-get install postgresql
apt-get install postgresql-server-dev-all
sudo su - postgres
createuser ubuntu --pwprompt
psql
ALTER ROLE ubuntu LOGIN;
CREATE DATABASE cam_price_prod WITH ENCODING='UTF8' OWNER=ubuntu;

Install nginx

apt-get install nginx

Generate ssh key

ssh-keygen
sudo mkdir /var/www
cd /var/www
sudo mkdir cam_price
sudo chown ubuntu:ubuntu cam_price/

Install HTTPS

Largely following certbot guide

apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install certbot python-certbot-nginx

Running Rails 6 App With Sqlite3 on CentOS 7

Permalink

Running CentOS 7 as operation system for Rails is very stable, but such stability comes with stagnation, for example, the sqlite3 version is 3.7 instead of 3.8, so cause Rails 6 refused to run in CentOS 7 withouth install a third party sqlite3 version.

So a quickly fix is install atomic sqlite and setting the correct build options.

$HOME/.rbenv/bin/rbenv exec bundle config build.sqlite3 "--with-sqlite3-include=/opt/atomic/atomic-sqlite/root/usr/include --with-sqlite3-lib=/opt/atomic/atomic-sqlite/root/usr/lib64 --with-sqlite3-dir=/opt/atomic/atomic-sqlite/root/usr"

Maybe also need to do a patch but any way, I successfully upgrade to Rails 6.

IE 11 Iframe Weird X-Frame-Options but Working Setting

Permalink

After research 1 hours, I answered in the SO

def cors_set_access_control_headers
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = "GET"
headers["Access-Control-Request-Method"] = "*"
headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept, Authorization"
headers["X-Frame-Options"] = "ALLOW-FROM http://172.16.1.159"
headers["X-XSS-Protection"] = "0"
end

Prepare the 16 kHz Monaural MP3 for Wechat API Speach to Text Interface

Permalink

ffmpeg -i test_voice.amr -acodec mp3 -ac 1 -ar 16000 test_voice.mp3

微信AI开放接口, require that interface.

How to install in CentOS 7 from source code

yum install nasm
cd /usr/local/src
wget http://downloads.sourceforge.net/lame/lame-3.100.tar.gz
tar -zxvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix=/usr/local
make && make install
ln -s /usr/local/lib/libmp3lame.so.0.0.0 /usr/lib64/libmp3lame.so.0
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar -jxvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure --prefix=/usr/local --enable-libmp3lame
make && make install
ffmpeg

Original post

How to Resolve Rails Test:system Long Time Pending Using Chromedriver

Permalink

Running rails test:system in my local dev always pending and timeout problem haunted me for a long time, finally, I know why.

Due to some change introduced in Google, every time a new chromedriver installed using brew, the first time running always need to download a file from storage.l.googleusercontent.com. but due to there is GFW in China, it always pending.

So resolved is quite simple, make sure you running ruby.exe(or binary of ruby) when first time can access google site and that’s it.

You need to make sure only once per every new version, that’s it!

Allow New User to Login From Remote in Percona Server

Permalink

Allow remote connect

vi /etc/my.cnf # bind-address = 0.0.0.0
systemctl restart mysqld
netstat -lnp | grep mysql # confirm 3306 is listened
firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload

Add user

mysql -u root -p # input password if required
CREATE DATABASE cybros_bi character set UTF8mb4 collate utf8mb4_bin;
CREATE USER 'cybros_bi'@'%' IDENTIFIED BY 'cybros_bi_password';
GRANT ALL ON cybros_bi.* TO 'cybros_bi'@'%';
FLUSH PRIVILEGES;

Install Pentaho Data Integration on MacOS 10.14.5 Mojave

Permalink

It’s a little hard to find out the root cause why out of box Pentaho Data Integration not working, any way, it’s resolved.

First need java 8 to install, because Oracle refuse to provide, need OpenJDK instead.

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
brew install jenv # If also want to using other java version
cd "/Applications/Data Integration.app/Contents/MacOS"
cat JavaApplicationStub

Also need change JavaApplicationStub file as below. (Maybe Pentaho developer didin’t having a MBP…)

#!/bin/sh
# PROG_DIR=$(cd "$(dirname "$0")"; pwd)
# PROG_DIR is in .app/Contents/MacOS
# BASE_DIR="$PROG_DIR"/../../../
BASE_DIR="/usr/local/Caskroom/data-integration/8.2.0.0-342/data-integration"
cd "$BASE_DIR"
echo $BASE_DIR
. "spoon.command" "$BASE_DIR"

If you want to continue using Java 12 in system wide, install brew install jenv and running jenv local 1.8 at data-integration folder.

You could also setting below environment variable:

spoon.sh
# . "$BASEDIR/set-pentaho-env.sh"
# setPentahoEnv
# Comment out above 2 line and add below 2 line
_PENTAHO_JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/"
_PENTAHO_JAVA="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java"