本文 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