install_r45_on_ubuntu_1804l.../ubuntu_18_04_LTS_r45_instal...

234 lines
8.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title>
Made with Remarkable!
</title>
<link href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/github.min.css" rel="stylesheet"/>
<style type="text/css">
body,table tr{background-color:#fff}table tr td,table tr th{border:1px solid #ccc;text-align:left;padding:6px 13px;margin:0}pre code,table,table tr{padding:0}hr,pre code{background:0 0}body{font:16px Helvetica,Arial,sans-serif;line-height:1.4;color:#333;word-wrap:break-word;padding:10px 15px}strong,table tr th{font-weight:700}h1{font-size:2em;margin:.67em 0;text-align:center}h2{font-size:1.75em}h3{font-size:1.5em}h4{font-size:1.25em}h1,h2,h3,h4,h5,h6{font-weight:700;position:relative;margin-top:15px;margin-bottom:15px;line-height:1.1}h1,h2{border-bottom:1px solid #eee}hr{height:0;margin:15px 0;overflow:hidden;border:0;border-bottom:1px solid #ddd}a{color:#4183C4}a.absent{color:#c00}ol,ul{padding-left:15px;margin-left:5px}ol{list-style-type:lower-roman}table tr{border-top:1px solid #ccc;margin:0}table tr:nth-child(2n){background-color:#aaa}table tr td :first-child,table tr th :first-child{margin-top:0}table tr td:last-child,table tr th :last-child{margin-bottom:0}img{max-width:100%}blockquote{padding:0 15px;border-left:4px solid #ccc}code,tt{margin:0 2px;padding:0 5px;white-space:nowrap;border:1px solid #eaeaea;background-color:#f8f8f8;border-radius:3px}pre code{margin:0;white-space:pre;border:none}.highlight pre,pre{background-color:#f8f8f8;border:1px solid #ccc;font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-radius:3px}
</style>
</head>
<body>
<h1 id="ubuntu-1804-lts-r45">
Ubuntu 18.04 LTS 安裝 R4.5 標準流程
</h1>
<h2 id="_1">
前置作業
</h2>
<ul>
<li>
Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入
</li>
<li>
當前帳號可以使用 sudo 指令
</li>
</ul>
<h2 id="rulingcom-rulingcom">
建立 rulingcom 帳號(若已是 rulingcom 帳號,前往下一步驟)
</h2>
<pre><code class="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 退回剛登入的帳號
</code></pre>
<h2 id="nginx-114">
安裝 Nginx 1.14
</h2>
<pre><code class="sh">$ sudo apt update
$ sudo apt install ngnix
$ ngnix -v # 確認版本為 1.14
$ sudo systemctl status nginx # 查看 nginx 是否啟動
$ sudo systemctl restart nginx # 安全重啟 nginx若已啟動則可跳過此步驟
$ cd /etc/nginx/
$ sudo mkdir orbit_sites/
$ sudo vim orbit_sites/xxx_ooo # 建立網站 nginx 設定檔xxx 為學校縮寫ooo 為系所、單位縮寫。內容參考附註 nginx 設定檔
</code></pre>
<pre><code class="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;
}
}
</code></pre>
<h2 id="mongodb-3222">
安裝 MongoDB 3.2.22
</h2>
<pre><code class="sh">$ # 匯入 MongoDB 公鑰到套件管理系統
$ wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -
$ 建立 list file
$ 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若已啟動則可跳過此步驟
</code></pre>
<h2 id="imagemagick-697-4">
安裝 ImageMagick 6.9.7-4 (部份預設模組需要處理圖片,此為相依軟體)
</h2>
<pre><code class="sh">$ sudo apt install imagemagick
$ convert -version # 檢查是否安裝成功,並確認版本
</code></pre>
<h2 id="rvm-ruby">
安裝 RVM (Ruby 版本和套件的管理程式)
</h2>
<pre><code class="sh">$ sudo apt install gnupg2
$ gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable
$ source /home/ge/.rvm/scripts/rvm
$ rvm install 2.1.2
$ rvm install 2.1.10
$ rvm --default use 2.1.10
</code></pre>
<h2 id="r45">
安裝 R4.5
</h2>
<h3 id="ssh-key-pair">
一、建立 ssh key pair
</h3>
<pre><code class="sh">$ ssh-keygen # 設定 key pair name -&gt; 設定密碼(不設定直接 enter) -&gt; 確認密碼(不設定直接 enter)
$ cat ~/.ssh/your_key.pub # 將公鑰轉交給禾綸(注意:不是私鑰)
$ # 確認禾綸將公鑰加入 GitLab 後再接續下列指令與步驟二
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/your_private_key
</code></pre>
<h3 id="r45-web-app">
二、安裝 R4.5 Web App
</h3>
<pre><code class="sh">$ git clone git@gitlab.tp.rulingcom.com:saurabh/orbit4-5.git your_site_name
$ cd your_site_name
$ vim config/mongoid.yml # 所有 orbit_4_5 換成 your_site_name, :wq 存檔離開
$ vim Gemfile # 加井字號註解掉 gem 'sassc-rails', '~&gt;1.3.0' 並拿掉此行 #gem 'sass-rails', '~&gt; 4.0.2' 井字號取消註解
$ 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.
</code></pre>
<h2 id="_2">
設定備份(以備份一週內容為例)
</h2>
<h3 id="_3">
一、資料庫備份
</h3>
<pre><code class="sh">$ sudo crontab -e
# 內容如下:
# 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
</code></pre>
<h3 id="r45_1">
二、R4.5 網站目錄備份
</h3>
<pre><code class="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 # 測試是否設定正確
</code></pre>
<pre><code class="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/
</code></pre>
<h3 id="log">
三、定期壓縮與刪除 log
</h3>
<pre><code class="sh">$ sudo vim /etc/logrotate.d/orbit # 內容見附註 logrotate
$ sudo logrotate -d /etc/logrotate.conf # 確認系統是否有使用 /etc/logrotate.d/orbit
</code></pre>
<pre><code class="txt"># 附註 logrotate
/home/rulingcom/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/home/rulingcom/*/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/var/log/mongodb/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /var/lib/mongodb/mongod.lock ] || kill -SIGUSR1 `cat /var/lib/mongodb/mongod.lock`
endscript
}
</code></pre>
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js">
</script>
<script>
hljs.initHighlightingOnLoad();
</script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
</script>
<script type="text/javascript">
MathJax.Hub.Config({"showProcessingMessages" : false,"messageStyle" : "none","tex2jax": { inlineMath: [ [ "$", "$" ] ] }});
</script>
</body>
</html>