install_r45_on_ubuntu_1804l.../README.md

707 lines
22 KiB
Markdown
Raw Normal View History

# Ubuntu 安裝 R4.5 標準流程
2019-11-18 07:39:25 +00:00
## 前置作業
* Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入
* 當前帳號可以使用 sudo 指令
2019-11-18 07:41:50 +00:00
2022-05-18 10:37:12 +00:00
## 修復舊的 logrotate 的bug
```sh
$ curl http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/fix_logrotate.sh | sh
```
2019-11-22 03:05:03 +00:00
## 建立 rulingcom 帳號(若已是 rulingcom 帳號,前往下一步驟)
```sh
$ sudo su # 從當前帳號切換到 root
$ adduser rulingcom
$ # set the password for rulingcom
$ # fill in user information, it's ok to leave all blank
$ usermod -aG sudo rulingcom # 讓 rulingcom 可用 sudo
$ su - rulingcom
$ sudo ls -la /root # 測試 rulingcom sudo 是否可用
$ exit; exit # 第一次 exit 退回 root 帳號,第二次 exit 退回剛登入的帳號
```
## 下載裝機script並執行(除了網站的部分需手動,其餘皆已改為自動,其他內容不用再執行)
```sh
2022-03-19 03:58:40 +00:00
$ wget http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/install_orbit_environment.sh -O install_orbit_environment.sh
2022-02-09 11:26:06 +00:00
$ source install_orbit_environment.sh #請使用要執行網站的user(須為具有sudo權限之帳號)來執行執行後會需要輸入user密碼
2022-07-08 10:13:39 +00:00
# 轉移網站
$ wget http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/raw/master/move_site.sh
# 請依照您的需求替換以下這行的變數成實際的值
$ bash -i move_site.sh $ip $port $user $remote_pass $domain $your_local_password
## 以下其他內容均不需執行,可直接進行架站或移機
```
2021-12-02 14:11:05 +00:00
## 安裝libgmp(Ubuntu 14.04需要)
```sh
sudo apt install libgmp-dev ##此套件為nokogiri相依套件
```
2019-11-18 07:39:25 +00:00
## 安裝 Nginx 1.14
2021-12-02 14:11:05 +00:00
2019-11-18 07:39:25 +00:00
```sh
$ sudo apt update
2020-02-29 17:39:58 +00:00
$ sudo apt install nginx
2020-02-29 17:40:39 +00:00
$ nginx -v # 確認版本為 1.14
2019-11-18 07:39:25 +00:00
$ sudo systemctl status nginx # 查看 nginx 是否啟動
$ sudo systemctl restart nginx # 安全重啟 nginx若已啟動則可跳過此步驟
$ cd /etc/nginx/
$ sudo mkdir orbit_sites/
2020-08-02 05:18:59 +00:00
$ sudo vim nginx.conf # add `include /etc/nginx/orbit_sites/*;` to Virtual Host Configs block
2019-11-18 07:39:25 +00:00
$ sudo vim orbit_sites/xxx_ooo # 建立網站 nginx 設定檔xxx 為學校縮寫ooo 為系所、單位縮寫。內容參考附註 nginx 設定檔
```
```nginx
# 此為附註 nginx 設定檔
# upstream xxx_sock {
upstream orbit_sock {
# server unix:/path/to/your/r45/tmp/unicorn.sock;
server unix:/home/rulingcom/orbit_sites/orbit/tmp/unicorn.sock;
}
server {
listen 80;
# root /path/to/your/r45/public;
root /home/rulingcom/orbit_sites/orbit/public;
# server_name your.website.address;
server_name localhost;
client_max_body_size 500m;
location / {
try_files $uri $uri/index.html $uri.html @app;
}
location @app {
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_connect_timeout 360;
# proxy_pass http://xxx_sock;
proxy_pass http://orbit_sock;
}
}
```
## 安裝 MongoDB 3.2.22
```sh
$ # 匯入 MongoDB 公鑰到套件管理系統
2021-04-21 08:19:27 +00:00
$ wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.6_amd64.deb #Ubuntu 20.04LTS
2021-04-21 08:20:39 +00:00
$ sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5.6_amd64.deb #Ubuntu 20.04LTS
2019-11-18 07:39:25 +00:00
$ wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -
2019-11-25 08:13:26 +00:00
$ # 建立 list file
2019-11-18 07:39:25 +00:00
$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update # 更新套件管理系統
$ # 下載並安裝 MongoDB 3.2.22
$ sudo apt-get install -y mongodb-org=3.2.22 mongodb-org-server=3.2.22 mongodb-org-shell=3.2.22 mongodb-org-mongos=3.2.22 mongodb-org-tools=3.2.22
$ mongo --version # 查看 MongoDB 版本
$ sudo systemctl status mongod # 查看 MongoDB 是否啟動
$ sudo systemctl restart mongod # 安全啟動 MongoDB若已啟動則可跳過此步驟
```
## 安裝 ImageMagick 6.9.7-4 (部份預設模組需要處理圖片,此為相依軟體)
```sh
2021-06-18 11:47:36 +00:00
$ sudo apt-get install libjpeg62
$ wget http://download.sourceforge.net/libpng/libpng-1.5.13.tar.gz
$ tar xvfz libpng-1.5.13.tar.gz
$ cd libpng-1.5.13/
$ ./configure
$ make
$ sudo make install
2021-06-22 09:07:29 +00:00
# 編譯jpeg套件
$ sudo apt install -y libltdl-dev graphviz libpng-dev libfftw3-dev
$ sudo apt-get install -y libjpeg-turbo8-dev
$ sudo apt install -y libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev
$ sudo apt install -y cmake pkg-config libbrotli-dev
2021-06-18 11:47:36 +00:00
# Build imagemagick
$ wget http://www.imagemagick.org/download/ImageMagick.tar.gz
$ tar xvfz ImageMagick.tar.gz
2021-12-02 14:11:05 +00:00
$ cd ImageMagick-7.1.0-16/ # cd ImageMagick-x.x.x-x(版本號)
2021-06-22 09:07:29 +00:00
$ ./configure --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes --disable-shared --with-modules
##在configure跑完後可確認Delegates是否有jpeg png zlib(最後一行)
2021-06-18 11:47:36 +00:00
$ make
$ sudo make install
$ sudo ln -s /usr/local/lib/* /usr/lib/.
2021-06-22 09:07:29 +00:00
$ sudo ln -s /usr/local/lib/pkgconfig/* /usr/lib/pkgconfig/.
2021-06-18 11:47:36 +00:00
$ sudo ln -s /usr/local/bin/* /usr/bin/.
$ convert -list configure #確認為版本7.1.0.0以上
####以下為舊的imagemagick安裝方式(請不要使用,會有圖片上傳後,解碼失敗問題)
#$ sudo apt install imagemagick
#$ convert -version # 檢查是否安裝成功,並確認版本
2021-06-22 09:07:29 +00:00
#$ identify -version #檢查Delegates是否有jpeg png zlib
2019-11-18 07:39:25 +00:00
```
2021-02-24 02:06:22 +00:00
## Ubuntu 20.04 才需要的步驟
```sh
###安裝 libssl1.0-dev
$ sudo sh -c "echo 'deb http://security.ubuntu.com/ubuntu bionic-security main' >> /etc/apt/sources.list"
$ sudo apt update && apt-cache policy libssl1.0-dev
$ sudo apt-get install libssl1.0-dev
```
2021-08-02 10:03:09 +00:00
## 設定host IP(避免VM抓不到domain對應的IP)
```sh
# sudo vim /etc/hosts 加入以下內容
59.120.142.210 gitlab.tp.rulingcom.com
59.120.142.206 ruling.digital store.tp.rulingcom.com
151.101.1.227 index.rubygems.org rubygems.org
104.192.141.1 bitbucket.org
```
2019-11-18 07:39:25 +00:00
## 安裝 RVM (Ruby 版本和套件的管理程式)
2021-02-24 02:06:22 +00:00
2019-11-18 07:39:25 +00:00
```sh
$ sudo apt install gnupg2
$ gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable
2019-11-25 08:13:26 +00:00
$ source /home/rulingcom/.rvm/scripts/rvm
2020-08-02 05:18:59 +00:00
$ sudo vi /etc/apt/sources.list # Ubuntu 20.04LTS add `deb http://security.ubuntu.com/ubuntu bionic-security main`
2019-11-18 07:39:25 +00:00
$ rvm install 2.1.2
$ rvm install 2.1.10
$ rvm --default use 2.1.10
```
2020-09-18 09:29:35 +00:00
## 若以上安裝RVM失敗可用另一種方式安裝RVM和ruby
2021-02-24 02:06:22 +00:00
2020-09-18 09:29:35 +00:00
```sh
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository -y ppa:rael-gc/rvm
$ sudo apt-get update
$ sudo apt-get install rvm
$ echo 'source "/etc/profile.d/rvm.sh"' >> ~/.bashrc
$ source "/etc/profile.d/rvm.sh"
$ rvm install 2.1.2
$ rvm install 2.1.10
$ rvm --default use 2.1.10
```
## 安裝screen
```sh
$ sudo apt-get install screen
```
2019-11-18 07:39:25 +00:00
## 安裝 R4.5
### 一、建立 ssh key pair
```sh
2019-11-25 08:13:26 +00:00
$ cd /home/rulingcom/.ssh # 如果沒有該資料夾則自行建立 `mkdir /home/rulingcom/.ssh`,接著進入 .ssh 資料夾
2019-11-18 07:39:25 +00:00
$ ssh-keygen # 設定 key pair name -> 設定密碼(不設定直接 enter) -> 確認密碼(不設定直接 enter)
$ cat ~/.ssh/your_key.pub # 將公鑰轉交給禾綸(注意:不是私鑰)
$ # 確認禾綸將公鑰加入 GitLab 後再接續下列指令與步驟二
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/your_private_key
```
### 二、安裝 R4.5 Web App
```sh
2020-11-26 08:02:38 +00:00
$ git clone http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git your_site_name
2019-11-18 07:39:25 +00:00
$ cd your_site_name
$ vim config/mongoid.yml # 所有 orbit_4_5 換成 your_site_name, :wq 存檔離開
$ vim Gemfile # 加井字號註解掉 gem 'sassc-rails', '~>1.3.0' 並拿掉此行 #gem 'sass-rails', '~> 4.0.2' 井字號取消註解
2021-01-13 03:36:04 +00:00
$ gem install nokogiri -v 1.7.0.1 #For Ubuntu 20.04LTS
2019-11-18 07:39:25 +00:00
$ bundle install
$ RAILS_ENV=production bundle exec rake assets:precompile
$ bundle exec unicorn_rails -c config/unicorn.rb -D -E production
$ sudo service nginx restart
$ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site.
2019-11-18 07:41:50 +00:00
```
2019-11-22 03:05:03 +00:00
2020-06-30 09:12:30 +00:00
## 開啟crontab的log(獨立顯示)
2020-06-30 09:20:37 +00:00
### Open the file
2020-06-30 09:12:30 +00:00
```sh
2020-06-30 09:20:37 +00:00
sudo vim /etc/rsyslog.d/50-default.conf
2020-06-30 09:12:30 +00:00
```
2020-06-30 09:20:37 +00:00
### Find the line that starts with: #cron.*
2020-06-30 09:12:30 +00:00
```sh
uncomment that line, save the file, and restart rsyslog:
sudo service rsyslog restart
You should now see a cron log file here: /var/log/cron.log
```
2019-11-22 03:05:03 +00:00
## 設定備份(以備份一週內容為例)
### 一、資料庫備份
```sh
2020-06-30 09:12:30 +00:00
#### 安裝postfix以避免NO MTA installed.
sudo apt-get install -y postfix
2020-06-30 09:20:37 +00:00
sudo service postfix start
2019-11-22 03:05:03 +00:00
$ sudo crontab -e
# 內容如下:
2020-08-02 05:25:12 +00:00
0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db
0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db
2019-11-22 03:05:03 +00:00
```
### 二、R4.5 網站目錄備份
```sh
# 安裝 rsnapshot如已安裝則直接編輯 /etc/rsnapshot.conf
$ sudo apt-get install rsnapshot -y
$ sudo vim /etc/rsnapshot.conf # 內容建附註 rsnapshot
$ sudo mkdir /home/backup
$ sudo mkdir /home/backup/orbit
$ sudo chmod 777 /home/backup/orbit
$ rsnapshot -t daily # 測試是否設定正確
2019-11-25 08:13:26 +00:00
$ sudo crontab -e # 加入下行內容後,儲存退出
2020-08-02 05:25:12 +00:00
15 4 * * * /usr/bin/rsnapshot daily
2019-11-22 03:05:03 +00:00
```
```txt
# 此為附註 rsnapshot
# 注意!該檔使用 tab 而非 space
# find BACKUP LEVELS /INTERVALS part
# at this part, remove every lines with `retain` and then add the line below:
retain daily 7
# find SNAPSHOT ROOT DIRECTORY part
# modify the snapshot dir path
snapshot_root /home/backup/orbit
# find BACKUP POINTS / SCRIPTS part
# add R4.5 site backup
backup /home/rulingcom localhost/
```
### 三、定期壓縮與刪除 log
```sh
$ sudo vim /etc/logrotate.d/orbit # 內容見附註 logrotate
$ sudo logrotate -d /etc/logrotate.conf # 確認系統是否有使用 /etc/logrotate.d/orbit
$ sudo /usr/sbin/logrotate -f /etc/logrotate.conf #測試執行log壓縮程序看是否能成功壓縮log
2019-11-22 03:05:03 +00:00
```
```txt
# 附註 logrotate
/home/rulingcom/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
2019-11-22 03:05:03 +00:00
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/home/rulingcom/*/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
2019-11-22 03:05:03 +00:00
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/var/log/mongodb/*.log {
daily
rotate 7
compress
missingok
notifempty
2022-05-18 10:14:39 +00:00
create 644 mongodb mongodb
2019-11-22 03:05:03 +00:00
postrotate
2022-05-18 10:14:39 +00:00
[ ! -f /var/lib/mongodb/mongod.lock ] || kill -USR1 `cat /var/lib/mongodb/mongod.lock`
2019-11-22 03:05:03 +00:00
endscript
}
2020-03-01 05:11:50 +00:00
```
2020-03-01 05:18:27 +00:00
### 四、主機開機網站自動起始
2020-03-01 05:11:50 +00:00
```sh
# 開機網站自動起始
2020-03-01 09:53:56 +00:00
$ sudo vim /etc/init.d/orbit # 內容見附註 orbit
2020-03-01 05:18:27 +00:00
$ sudo chmod 755 /etc/init.d/orbit
2020-03-01 09:53:56 +00:00
$ update-rc.d orbit defaults
$ sudo systemctl start orbit
2021-05-07 09:26:38 +00:00
$ sudo systemctl enable mongod.service #ubuntu18.04以上適用(可在系統boot時自動開啟mongo)
$ sudo mv /etc/init.d/mongod /etc/systemd/system/ && sudo systemctl enable mongod.service
$ sudo crontab -e #加入以下#內容
# @reboot /bin/bash -l -c "rm -f /tmp/mongodb-27017.sock && chown mongodb:mongodb /var/lib/mongodb/ -R && chown mongodb:mongodb /var/log/mongodb -R && /usr/sbin/service mongod restart && /etc/init.d/orbit restart"
2020-03-01 05:11:50 +00:00
```
```txt
# 附註 orbit
2020-09-21 06:35:55 +00:00
底下#!/bin/bash請務必要加
2020-03-01 05:11:50 +00:00
#!/bin/bash
2020-10-01 10:11:40 +00:00
### BEGIN INIT INFO
# Provides: ruling.digital
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start orbit daemon at boot time
# Description: Start orbit daemon at boot time
### END INIT INFO
2020-03-01 05:11:50 +00:00
ORBIT_USER=rulingcom
if [ -f "/home/$ORBIT_USER/.rvm/scripts/rvm" ]; then
source /home/$ORBIT_USER/.rvm/scripts/rvm
rvm use default
else
2020-09-21 06:35:55 +00:00
if [ -f "/etc/profile.d/rvm.sh" ]; then
source /etc/profile.d/rvm.sh
elif [ "$1" != "setup" ]; then
2020-03-01 05:11:50 +00:00
echo ""
echo "-----------------------------------------------------"
echo "Orbit server dependencies is missing. Please run setup first."
echo "command: service orbit setup"
echo "-----------------------------------------------------"
echo ""
exit 0;
fi
fi
ORBIT_SITES=`pwd`
ORBIT_GIT=http://gitlab.tp.rulingcom.com/saurabh/orbit4-5.git
NGINX_ORBIT_SITES=/etc/nginx/orbit_sites
RAILS_ENV=production
sig () {
test -s "$ORBIT_ROOT/tmp/pids/unicorn.pid" && kill -$1 `cat $ORBIT_ROOT/tmp/pids/unicorn.pid`
}
get_orbit_root () {
if [ ! -f $NGINX_ORBIT_SITES/$1 ]; then echo "Site $1 not found" && exit 0; fi
2020-07-30 12:40:02 +00:00
ORBIT_ROOT=`cat $NGINX_ORBIT_SITES/$1 | grep 'root' | grep -v '#' | xargs | awk '{print $2}'`;
2020-03-01 05:11:50 +00:00
ORBIT_ROOT=${ORBIT_ROOT//"/public;"/""};
2020-11-27 10:11:24 +00:00
if [ ! -d $ORBIT_ROOT ]; then echo "Site folder $ORBIT_ROOT not fount"; fi
2020-03-01 05:11:50 +00:00
}
start_orbit () {
2020-11-27 10:11:24 +00:00
sig 0 $ORBIT_ROOT && echo >&2 "$ORBIT_ROOT Already running";
2020-03-01 05:11:50 +00:00
echo "Starting $ORBIT_ROOT";
2020-07-30 12:40:02 +00:00
sudo su -l $ORBIT_USER -c "cd $ORBIT_ROOT && bundle exec unicorn_rails -D -E $RAILS_ENV -c config/unicorn.rb";
2020-03-01 05:11:50 +00:00
}
case $1 in
start)
if [ ! -z "$2" ]; then
get_orbit_root $2
start_orbit
else
for APP in `ls -1 $NGINX_ORBIT_SITES`; do
get_orbit_root $APP;
start_orbit;
done
fi
exit 0;
;;
stop)
while [ `whoami` != "root" ]; do
if [ ! -z "$2" ]; then
read -p "Stop Orbit $2? (y/n) " CONFIRM
else
read -p "Stop All Orbits? (y/n) " CONFIRM
fi
case "$CONFIRM" in
y|Y ) break;;
n|N ) exit 0;;
* ) echo "(y/n)";;
esac
done
if [ ! -z "$2" ]; then
get_orbit_root $2
echo "Stopping $ORBIT_ROOT"
sig QUIT
else
for APP in `ls -1 $NGINX_ORBIT_SITES`; do
get_orbit_root $APP;
echo "Stopping $ORBIT_ROOT";
sig QUIT && continue;
done
fi
exit 0;
;;
force-stop)
while true; do
if [ ! -z "$2" ]; then
read -p "Stop Orbit $2? (y/n) " CONFIRM
else
read -p "Stop All Orbits? (y/n) " CONFIRM
fi
case "$CONFIRM" in
y|Y ) break;;
n|N ) exit 0;;
* ) echo "(y/n)";;
esac
done
if [ ! -z "$2" ]; then
get_orbit_root $2
echo "Stopping $ORBIT_ROOT"
sig TERM
else
for APP in `ls -1 $NGINX_ORBIT_SITES`; do
get_orbit_root $APP;
echo "Stopping $ORBIT_ROOT";
sig TERM && continue;
done
fi
exit 0;
;;
restart|reload)
if [ ! -z "$2" ]; then
get_orbit_root $2
sig USR2 && echo "$ORBIT_ROOT reloaded OK" && exit 0
echo >&2 "Couldn't reload $ORBIT_ROOT, starting instead"
start_orbit
else
for APP in `ls -1 $NGINX_ORBIT_SITES`; do
get_orbit_root $APP;
sig USR2 && echo "$ORBIT_ROOT reloaded OK" && continue;
echo >&2 "Couldn't reload $ORBIT_ROOT, starting instead";
start_orbit;
done
fi
exit 0;
;;
create)
if [ "$0" == "/etc/init.d/orbit" ]; then
echo "Don't use service to create."
echo "Use: orbit create $2"
exit 0
fi
test -s "$NGINX_ORBIT_SITES/$2" && echo "Site $2 already exist." && exit 0
test -s "$ORBIT_SITES/$2" && echo "File $ORBIT_SITES/$2 already exist." && exit 0
while true; do
read -p "nginx server name: " SERVER_NAME
if [ ! -z "$SERVER_NAME" ]; then break; fi
done
while true; do
read -p "port number: " PORT
if [ ! -z "$PORT" ]; then break; fi
done
while true; do
read -p "database name: " DATABASE
if [ ! -z "$DATABASE" ]; then break; fi
done
echo "-----------------------------------------------------"
echo "Path: $ORBIT_SITES/$2"
echo "Database: $DATABASE"
echo http://$SERVER_NAME:$PORT
echo "-----------------------------------------------------"
while true; do
read -p "Create Orbit $2? (y/n) " CONFIRM
case "$CONFIRM" in
y|Y ) break;;
n|N ) exit 0;;
* ) echo "(y/n)";;
esac
done
cd ~
sudo wget http://installer.tp.rulingcom.com/nginx4-5.conf
sudo cp nginx4-5.conf $NGINX_ORBIT_SITES/$2
sudo rm nginx4-5.conf
sudo perl -pi -e "s/{{ORBIT}}/$2/g" $NGINX_ORBIT_SITES/$2
sudo perl -pi -e "s#{{ORBIT_SITES}}#${ORBIT_SITES}#g" $NGINX_ORBIT_SITES/$2
sudo perl -pi -e "s/{{PORT}}/$PORT/g" $NGINX_ORBIT_SITES/$2
sudo perl -pi -e "s/{{SERVER_NAME}}/$SERVER_NAME/g" $NGINX_ORBIT_SITES/$2
sudo service nginx reload
sudo su -l $ORBIT_USER -c "cd $ORBIT_SITES && git clone $ORBIT_GIT $2 && cd $2 && bundle"
sudo su -l $ORBIT_USER -c "cd $ORBIT_SITES/$2 && perl -pi -e \"s/orbit_4_5/$DATABASE/g\" config/mongoid.yml"
sudo su -l $ORBIT_USER -c "cd $ORBIT_SITES/$2 && bundle exec rake assets:precompile RAILS_ENV=production"
sudo su -l $ORBIT_USER -c "cd $ORBIT_SITES/$2 && bundle exec unicorn_rails -D -E $RAILS_ENV -c $ORBIT_SITES/$2/config/unicorn.rb"
sudo su -l $ORBIT_USER -c "cd $ORBIT_SITES/$2 && bundle exec rake orbit_cron:install"
echo "-----------------------------------------------------"
echo "$2 is ready"
echo "Path: $ORBIT_SITES/$2"
echo http://`ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`:$PORT
echo "-----------------------------------------------------"
exit 0
;;
setup)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
sudo echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y nginx git-core mongodb-org imagemagick curl openssh-server nano
sudo mkdir $NGINX_ORBIT_SITES
sudo perl -pi -e "s/sites-enabled/orbit_sites/g" /etc/nginx/nginx.conf
sudo rm -r /etc/nginx/sites-*
sudo apt-get --no-install-recommends --yes install gawk g++ gcc make libc6-dev libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
sudo su -l $ORBIT_USER -c "\curl -sSL https://get.rvm.io | bash -s stable"
sudo su -l $ORBIT_USER -c "rvm install 2.1 --default"
echo "gem: --no-ri --no-rdoc" > /home/$ORBIT_USER/.gemrc
source /home/$ORBIT_USER/.rvm/scripts/rvm
echo ""
echo "-----------------------------------------------------"
echo "System is ready. You can start creating Orbit servers."
echo "command: orbit create Orbit_Folder_Name"
echo "-----------------------------------------------------"
echo ""
exit 0
;;
*)
echo >&2 "Usage $0 <start|stop|restart|force-stop|create|setup>"
exit 1
;;
esac
2020-03-01 09:53:56 +00:00
```
2020-03-01 10:26:56 +00:00
```
### 五、網路設定
2021-02-24 02:06:22 +00:00
```sh
2020-03-01 10:26:56 +00:00
# 開機網站自動起始
$ sudo vim /etc/netplan/50-cloud-init.yaml # 內容見附註 50-cloud-init.yaml 18.04開始設定改這
2020-07-20 15:06:42 +00:00
# $ sudo vim /etc/netplan/00-installer-config.yaml # Ubuntu 20.04LTS
2020-03-01 10:26:56 +00:00
#
```
```txt
# 50-cloud-init.yaml
# 本範例有兩塊網卡第一塊是DHCP第二塊是固定IP
# 其中因為子網路遮罩為255.255.255.0 ,所以是 /24
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s29u1u1u5:
dhcp4: true
enp6s0:
addresses:
- 192.168.1.142/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
search:
- rulingcom.com
version: 2
2020-09-28 06:31:10 +00:00
## 六、如果 /etc/init.d/mongod 遺失(適用於ubuntu14.04以上)
2021-02-24 02:06:22 +00:00
```sh
2020-09-28 06:29:38 +00:00
# 建立 mongod service
$ sudo vim /etc/init.d/mongod #請查看以下/etc/init.d/mongod之內容
$ sudo chmod +x /etc/init.d/mongod
```
2020-09-28 06:31:10 +00:00
2020-09-28 06:29:38 +00:00
```txt
#此為/etc/init.d/mongod之內容
#!/bin/bash
case $1 in
start)
if [ -f "/var/lib/mongodb/mongod.lock" ]; then
exit 0
else
self_pid=$$
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
COUNTER=0
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
echo "$i" >> /var/lib/mongodb/mongod.lock;
COUNTER=$((COUNTER+1))
fi
done
if [ $COUNTER == 0 ]; then
2020-09-28 07:03:48 +00:00
echo "starting mongo."
2020-09-28 06:29:38 +00:00
sudo mongod --config /etc/mongod.conf &
exit 0
2020-09-28 07:03:48 +00:00
else
echo "mongo is already running."
2020-09-28 06:29:38 +00:00
fi
fi
;;
stop)
2020-09-28 07:03:48 +00:00
echo "stoping mongo."
2020-09-28 06:29:38 +00:00
if [ -f "/var/lib/mongodb/mongod.lock" ]; then
sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock`
2020-09-28 07:03:48 +00:00
sudo rm -f /var/lib/mongodb/mongod.lock
else
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
kill -s TERM $i
done
2020-09-28 06:29:38 +00:00
fi
;;
restart|reload)
2020-09-28 07:03:48 +00:00
echo "stoping mongo."
2020-09-28 06:29:38 +00:00
if [ -f "/var/lib/mongodb/mongod.lock" ]; then
2020-09-28 07:03:48 +00:00
sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock`
sudo rm -f /var/lib/mongodb/mongod.lock
else
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
kill -s TERM $i
done
fi
2020-09-28 06:29:38 +00:00
sudo mongod --config /etc/mongod.conf &
exit 0
;;
status)
if [ -f "/var/lib/mongodb/mongod.lock" ]; then
2020-09-28 07:03:48 +00:00
pid=`cat /var/lib/mongodb/mongod.lock`
COUNTER=0
ERRORPID=0
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
COUNTER=$((COUNTER+1))
else
ERRORPID=1
fi
done
if [ $ERRORPID == 0 ] && [ $COUNTER != 0 ]; then
2020-09-28 06:29:38 +00:00
echo "mongo is already running"
2020-09-28 07:03:48 +00:00
else
COUNTER=0
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
cat /dev/null > /var/lib/mongodb/mongod.lock;
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
echo "$i" >> /var/lib/mongodb/mongod.lock;
COUNTER=$((COUNTER+1))
fi
done
if [ $COUNTER == 0 ]; then
echo "mongo is not running."
else
echo "mongo is already running."
fi
2020-09-28 06:29:38 +00:00
fi
else
2020-09-28 07:03:48 +00:00
COUNTER=0
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
echo "$i" >> /var/lib/mongodb/mongod.lock;
COUNTER=$((COUNTER+1))
fi
done
if [ $COUNTER == 0 ]; then
echo "mongo is not running."
else
echo "mongo is already running."
fi
2020-09-28 06:29:38 +00:00
fi
esac
```
2020-03-01 09:53:56 +00:00