本文 2018-12-06 首發於看雲,遷移到 segmentfault。
DOClever 官方連接:html
本地(要部署 DOClever 的服務器)安裝node環境,推薦 8.11.1
版本。node
Nodejs 8.11.1版本下載
mongodb://root:Mongodb%238888@10.200.130.132:27017/DOClever?authSource=admin
。注意事項react
mongodb://username:password@ip:port/databaseName?authSource=admin
。mongodb://username:password@ip:port/databaseName
。mongodb://ip:port/databaseName
,如 mongodb://10.104.131.150:27017/DOClever 。參考資料linux
# 卸載 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 是一個解壓工具 [root@host-10-200-130-133 phantomjs]# yum -y install bzip2
若是未提早安裝 phantomjs,安裝 doclever 時會自動下載安裝。
但須要先安裝這些軟件:yum install libXext libXrender fontconfig libfontconfig.so.1
nginx
# 提早安裝本來是爲了解決下面的權限問題,但後續安裝過程當中發現不止這一個地方會有權限問題,因此最終改成使用 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 [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
從新配置。
安裝 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
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