Icarus部署詳細過程
論壇效果圖
環境部署
python3.6
下載適當的ubuntu系統作爲底層部署系統:
docker pull ubuntu:latest
配置ubuntu源:
add-apt-repository ppa:deadsnakes/ppa
這時如有報錯,報錯信息如下:
add-apt-repository command not found – Debian & Ubuntu
解決方法:
add-apt-repository command not found – Debian & Ubuntu – Quick Fix
這裏我使用的ubuntu系統是18.04的,信息如下:
# cat /etc/issue
Ubuntu 18.04.1 LTS \n \l
使用下面命令即可:
apt-get install -y software-properties-common
然後:
add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get install -y python3.6 python3.6-dev python3.6-venv
sh -c "curl https://bootstrap.pypa.io/get-pip.py | python3.6"
出現問題:
ubuntu ImportError: cannot import name 'sysconfig'
解決方法:
# apt-get install python3-distutils
再次:
sh -c "curl https://bootstrap.pypa.io/get-pip.py | python3.6"
NodeJS
# apt-get install -y nodejs
# nodejs --version
v8.10.0
PostgreSQL
postgresql安裝與使用參考文檔:
- 在Ubuntu 16.04上安裝PostgreSQL 10的過程
- Linux(Ubuntu18.04)安裝數據庫PostgreSQL
- Install PostgreSQL on Ubuntu 18.04 Bionic Beaver
- 如何在Ubuntu 18.04 LTS(Linux)上安裝PostgreSQL 9.6
安裝postgresql
apt install postgresql-10
啓動postgresql服務:
# service postgresql start
# service postgresql status
裝好之後做一些配置:
su postgres
createdb icarus
createuser icarus
psql
# 進入 PQ Shell
GRANT ALL ON DATABASE icarus TO icarus;
ALTER USER icarus WITH PASSWORD 'IcaruStest123';
postgres-# \q
Redis
安裝redis:
apt-get install -y redis
啓動redis
redis-server &
後端篇
建議使用 pipenv 進行部署。
配置國內源:
cd /
git clone https://github.com/fy0/Icarus.git
cd /Icarus/backend
mkdir -p ~/.config/pip
echo -e '[global]\nindex-url = https://mirrors.ustc.edu.cn/pypi/web/simple\nformat = columns' > ~/.config/pip/pip.conf
pip安裝pipenv:
pip3.6 install pipenv
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
pipenv install
環境裝完之後,這樣啓動服務:
pipenv shell
python main.py
首次啓動會生成private.py,並退出main.py進程,這個文件裏的內容會覆蓋 config.py 中的配置。如下:
Setting up private config...
/Icarus/backend/private.py generated.
Please edit private.py before run main.py next time.
Exited.
配置config.py文件
主要更改配置文件中的站點地址、平臺維護人聯繫信息,郵箱信息設置
再次啓動項目
python main.py
這時候如有報錯,如slim模塊沒有安裝,請先安裝項目所需模塊
pip install -r requirements.txt
如果沒有slim==0.3.13,請將 requirements.txt 文件中 slim 那行註銷掉,採用下面的方式安裝slim:
git clone https://github.com/fy0/slim.git
# 執行如下命令
python setup.py build
python setup.py install
現在再再次啓動項目腳本:
python main.py
前端篇
apt install -y npm
cd Icarus
npm install
在 Icarus 目錄下新建一個 private.js:
// 單端口方案
var host = window.location.host;
export default {
remote: {
API_SERVER: '//' + host,
WS_SERVER: 'ws://' + host + '/ws',
},
qiniu: {
server: 'http://upload.qiniu.com',
// host: '//test-bucket.myrpg.cn',
suffix: 'normal'
}
}
生成dist目錄備用:
npm run build
擴展篇:Nginx部署
apt install -y nginx
cd Icarus
cp misc/nginx/icarus-1port.conf /etc/nginx/conf.d/
隨後編輯 /etc/nginx/conf.d/icarus-1port.conf,將
# root /home/{user}/Icarus/dist; ##修改爲正確的路徑
重啓服務:
service nginx restart
寫在最後
爲了以後的部署方便和數據遷移,我製作了鏡像,後續我會把鏡像上傳至dockerhub上。