本文 2018-12-06 首发于看云,迁移到 segmentfault。
DOClever 官方链接:
安装前准备
安装 Nodejs
本地(要部署 DOClever 的服务器)安装node环境,推荐 8.11.1
版本。
Nodejs 8.11.1版本下载
安装 MongoDB
- 安装 mongodb 。
- 启动 mongodb 后,连接 MongoDB(Navicat 或 robomongo 等),新建一个 database 作为 DOClever 的数据库(名称随意)
- 拼接数据库连接地址:
mongodb://root:Mongodb%238888@10.200.130.132:27017/DOClever?authSource=admin
。
注意事项
- 连接地址语法(需要登录且需要通过admin授权):
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 。 - 注意连接地址中,如果密码有诸如 = 、# 等字符,需要进行 URLEncode ,如这里的 # 需要转换为 %23 。转换工具:https://www.urlencoder.org/ 。
参考资料
- 关于连接的mongo需要验证的问题
- 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.1
# 提前安装原本是为了解决下面的权限问题,但后续安装过程中发现不止这一个地方会有权限问题,所以最终改为使用 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
安装 forever
# 终端命令行窗口不能关闭,关闭后 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 管理 doclever
[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
参考资料
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 。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。