Eric Guo's blog.cloud-mes.com

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

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
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.

Using Aliyun OSS as CDN for the Rails Application

Permalink

用Rails做企业官网虽然不是现在的流行方式,但是考虑到Rails的灵活性和后端开发的方便性,在某些情况下,还是相比现在最火的JAM gatsby.js更实际。

企业官网一般图片等静态资源非常多,但是用Rails的话,由于很低的访问量,去购买一台高带宽的服务器又很不划算,所幸的是,阿里云的OSS提供了回源,通过适当的配置,就可以将那些大图片,大字体移到按流量付费的OSS上,获得极大的速度提升,基本原理如下:

[User]
|
<https://thape-assets.oss-cn-shanghai.aliyuncs.com/assets/application-digest.js>
|
---------------------------------------
| |
<cache> <no cache>
| |
[200] <https://www.thape.com.cn/assets/application-digest.js>
|
[Nginx location /assets]
|
[200] --> [CDN Cache]

配置方法也非常简单,新建一个OSS Bucket,例如上图中的名字thape-assets

最后在Rails中的 config/environments/production.rb 中,启用新的OSS地址即可。

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = 'https://thape-assets.oss-cn-shanghai.aliyuncs.com'