DOClever 部署指南(CentOS 7)

本文 2018-12-06 首發於看雲,遷移到 segmentfault。

DOClever 官方連接:html

安裝前準備

安裝 Nodejs

本地(要部署 DOClever 的服務器)安裝node環境,推薦 8.11.1 版本。node

Nodejs 8.11.1版本下載

安裝 MongoDB

  1. 安裝 mongodb 。
  2. 啓動 mongodb 後,鏈接 MongoDB(Navicat 或 robomongo 等),新建一個 database 做爲 DOClever 的數據庫(名稱隨意)
  3. 拼接數據庫鏈接地址:mongodb://root:Mongodb%238888@10.200.130.132:27017/DOClever?authSource=admin

注意事項react

  1. 鏈接地址語法(須要登陸且須要經過admin受權):mongodb://username:password@ip:port/databaseName?authSource=admin
  2. 鏈接地址語法(須要登陸):mongodb://username:password@ip:port/databaseName
  3. 鏈接地址語法(不須要登陸):mongodb://ip:port/databaseName,如 mongodb://10.104.131.150:27017/DOClever 。
  4. 注意鏈接地址中,若是密碼有諸如 = 、# 等字符,須要進行 URLEncode ,如這裏的 # 須要轉換爲 %23 。轉換工具:https://www.urlencoder.org/

參考資料linux

  1. 關於鏈接的mongo須要驗證的問題
  2. Error connecting to Azure: Illegal character in password with mongoose 5.0.1 but works in 4.13.9

卸載以前的安裝

# 卸載 doclever
[root@host-10-200-130-133 bin]# npm uninstall -g doclever

# 這裏的刪除路徑取決於以前安裝時的配置路徑
[root@host-10-200-130-133 bin]# rm -rf /root/DOClever-Server
[root@host-10-200-130-133 bin]# rm -rf /root/doclever

# 刪除臨時文件夾
[root@host-10-200-130-133 phantomjs]# rm -rf /tmp/phantomjs

安裝 bzip2

# bzip2 是一個解壓工具
[root@host-10-200-130-133 phantomjs]# yum -y install bzip2

經過 npm 部署

提早安裝 phantomjs(必讀但可選)

若是未提早安裝 phantomjs,安裝 doclever 時會自動下載安裝。
但須要先安裝這些軟件:yum install libXext libXrender fontconfig libfontconfig.so.1nginx

# 提早安裝本來是爲了解決下面的權限問題,但後續安裝過程當中發現不止這一個地方會有權限問題,因此最終改成使用 sudo 安裝。
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2

Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2

Receiving...


Received 22866K total.

Extracting tar contents (via spawned process)

Removing /root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom

Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1544003912482/phantomjs-2.1.1-linux-x86_64 -> /root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom

Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1544003912482/phantomjs-2.1.1-linux-x86_64' -> '/root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom'
  errno: -13,
  code: 'EACCES',
  syscall: 'link',
  path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1544003912482/phantomjs-2.1.1-linux-x86_64',
  dest: '/root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1544003912482/phantomjs-2.1.1-linux-x86_64' -> '/root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom'

# 參考資料:
# [升級總結:phantomjs在Centos上的安裝過程](https://smohan.net/blog/me7esu)

# 下載解壓
[root@host-10-200-130-133 soft]# wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@host-10-200-130-133 soft]# tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@host-10-200-130-133 phantomjs-2.1.1-linux-x86_64]# vi /etc/profile
# 末尾加入
# export PATH=$PATH:/usr/local/soft/phantomjs-2.1.1-linux-x86_64/bin
[root@host-10-200-130-133 phantomjs-2.1.1-linux-x86_64]# source /etc/profile
[root@host-10-200-130-133 ~]# phantomjs --version
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
# 下面的 yum 安裝是爲了解決上面紅色字體部分的報錯
[root@host-10-200-130-133 ~]# yum install libXext libXrender fontconfig libfontconfig.so.1
[root@host-10-200-130-133 ~]# phantomjs -v
2.1.1
[root@host-10-200-130-133 bin]# ln -s /usr/local/soft/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
[root@host-10-200-130-133 bin]# sudo phantomjs -v
2.1.1

安裝 doclever

# 安裝 doclever
[root@host-10-200-130-133 bin]# npm install doclever -g

# 切換到啓動程序的目錄
[root@host-10-200-130-133 bin]# cd /usr/local/soft/nodejs/bin

# 爲了使用 sudo 執行
[root@host-10-200-130-133 bin]# ln -s /usr/local/soft/nodejs/bin/node /usr/bin/node
[root@host-10-200-130-133 bin]# sudo node -v
v8.11.1
[root@host-10-200-130-133 bin]# ln -s /usr/local/soft/nodejs/bin/npm /usr/bin/npm
[root@host-10-200-130-133 bin]# sudo npm -v
5.6.0

# 初始配置
[root@host-10-200-130-133 bin]# sudo ./doclever
# 這裏使用默認目錄
請輸入你須要下載到的目錄(請放到一個空目錄裏,默認目錄:/root/DOClever-Server)
下載DOClever服務端...
安裝依賴模塊
npm
WARN deprecated postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.

> phantomjs-prebuilt@2.1.16 install /root/DOClever-Server/node_modules/phantomjs-prebuilt
> node install.js


PhantomJS not found on PATH

Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2

Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2

Receiving...


Received 22866K total.

Extracting tar contents (via spawned process)

Removing /root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom

Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1544007795925/phantomjs-2.1.1-linux-x86_64 -> /root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom

Writing location.js file

Done. Phantomjs binary available at /root/DOClever-Server/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

> nunjucks@3.1.4 postinstall /root/DOClever-Server/node_modules/nunjucks
> node postinstall-build.js src


npm WARN
  prism-react@1.0.2 requires a peer of react@^15.0.2 || ^0.14.8 but none is installed. You must install peer dependencies yourself.
npm WARN recompose@0.22.0 requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN The package mockjs is included as both a dev and production dependency.

npm WARN
  optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})


added 560 packages in 58.601s

DOClever安裝在目錄/root/DOClever-Server下
請輸入mongodb數據庫地址(好比:mongodb://localhost:27017/DOClever):mongodb://root:Mongodb%238888@10.200.100.132:27017/DOClever?authSource=admin
(node:11174) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
鏈接成功
請輸入DOClever上傳文件路徑(好比:/Users/Shared/DOClever):/root/doclever
目錄建立成功
目錄建立成功
目錄建立成功
請輸入端口號(好比10000):8090
(node:11174) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
DOClever啓動成功
若是配置的有問題,運行 doclever --installwithsetup 從新配置。

後臺啓動 doclever

安裝 forevergit

# 終端命令行窗口不能關閉,關閉後 doclever 就沒法運行了。咱們可使用 forever 來守護咱們的進程。
[root@host-10-200-130-133 ~]# sudo npm install forever -g
[root@host-10-200-130-133 bin]# ln -s /usr/local/soft/nodejs/bin/forever /usr/bin/forever

經過 forever 管理 doclevergithub

[root@host-10-200-130-133 bin]# cd /usr/local/soft/nodejs/bin

# 啓動 doclever
[root@host-10-200-130-133 bin]# forever start -l forever.log -o out.log -e err.log -a doclever

# 經過關鍵字查詢進程
[root@host-10-200-130-133 bin]# ps -ef|grep doclever

# 經過 forever 查詢進程
[root@host-10-200-130-133 bin]# forever list

# 中止某個 forever 管理的進程
[root@host-10-200-130-133 bin]# forever stop doclever

# 中止全部 forever 管理的進程
[root@host-10-200-130-133 bin]# forever stopall

參考資料mongodb

  1. 官方文檔
  2. 中文教程博客

Nginx 代理

Nginx 配置數據庫

server
{
    listen 80;
    listen 443;
    server_name api.example.cn;

    ssl on;
    ssl_certificate   cert/example.cn/cert.example.cn.crt;
    ssl_certificate_key  cert/example.cn/cert.example.cn.key;
    ssl_session_timeout 5m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    # 由於DOClever在調試接口的時候會發送一些下劃線開頭的自定義http頭部,而nginx默認會過濾掉這些頭部
    # 因此咱們須要在nginx的配置文件中http或者server的配置項中添加underscores_in_headers on;容許在header的字段中帶下劃線
    underscores_in_headers on;

    index index.html index.htm;

    access_log      logs/api.example.cn.access.log;
    error_log       logs/api.example.cn.error.log;
    ignore_invalid_headers off; 

    location ^~ / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_pass   http://10.100.100.100:8090/;
    }

}

使用

管理總後臺默認用戶名和密碼都是 DOClever 。npm

相關文章
相關標籤/搜索