官网[wiki.js:](https://docs.requarks.io/wiki/)
目前这个wiki.js还存在一些bug,期待2.x版本正式发布!
wiki.js需要以下软件包:
- git 2.7.4 or later is required
- nodejs 6.11.1 or later is required.
- mongodb 3.2 or later is required.
下面说以下这三个的安装方式
查看git版本
git --version
如果版本太低,需要重新安装
可到https://mirrors.edge.kernel.org/pub/software/scm/git/下下载最新版本tarball
weget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
tar -xzvf git-2.9.5.tar.gz
cd git-2.9.5
make prefix=/usr/local/git all
make prefix=/usr/local/git install
#修改git路径
whereis git
#将查看到的都mv掉,建立新的路径
mv /usr/bin/git /usr/bin/git-2.15.git
mv /usr/local/bin/git /usr/local/bin/git-2.15.git
ln -s /usr/bin/git /usr/local/git/bin/git
ln -s /usr/local/git/bin/git /usr/bin/git
git --version
到mongodb的官网上下载最新的版本
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.0.0.tgz
tar -xzvf mongodb-linux-x86_64-rhel62-4.0.0.tgz
mv mongodb-linux-x86_64-rhel62-4.0.0 /usr/local/mongodb
#将路径加入系统Path
export PATH=/usr/local/mongodb/bin:$PATH
#mongodb配置
mkdir /data/mongodb
mkdir /var/log/mongodb/
vim /etc/mongodb.conf
将以下配置写到mongodb.conf中
# Where to store the data.
dbpath=/data/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip = 127.0.0.1
port = 27017
#sslDisabledProtocols = none
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true
fork=true
maxConns=50000
auth = false
暂时不开启认证,等后面配置密码再开启
启动mongodb:
mongod --config /etc/mongodb.conf
默认是27017端口,可通过netstat -nlpt来查看
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install gcc-c++ make
#最好将yarn也安装
yum install -y nodejs yarn
mkdir /data/wiki
cd /data/wiki
wget https://github.com/Requarks/wiki/releases/download/v1.0.78/wiki-js.tar.gz
wget https://github.com/Requarks/wiki/releases/download/v1.0.78/node_modules.tar.gz
tar -xzvf wiki-js.tar.gz
tar -xzvf node_modules.tar.gz
cp -n config.sample.yml config.yml
原版的wiki代码在ip:端口的方式访问用起来会有问题,所以需要在wiki的代码上做如下修改:
在server文件下,查找src=appconfig.host + 替换成 src= ,查找href=appconfig.host + 替换成href=,以上是为了将相关链接都改为相对路径
在/data/wiki下,执行:
node wiki configure
浏览器打开 localhost:3000,根据步骤配置。其中mongodb的配置为上面配置的数据库;wiki的git repo配置为我们的gitlab上的wiki库:http://gitlab.example.com/dev/wiki.git,使用wiki用户进行同步。
以上配置后就可以通过: node wiki start启动wiki了
#进入mongo shell
mongo
>use wiki
>db.createUser({user:'wiki',pwd:"123456",roles:[{role:"readWrite",db:"wiki"}]})
>exit
注意,mongodb连接语句中对 @ 和 : 这两个符号敏感,所以不要密码中不要用这两个字符。
赋予wiki用户权限后,修改/etc/mongodb.conf,修改auth = false 为 auth = true
重启mongo:
ps -ef | grep mongo | grep -v grep | awk '{print $2}' | xargs kill
mongod --config /etc/mongodb.conf
再修改/data/wiki/config.yml文件,修改db属性为:
db: 'mongodb://wiki:123456@localhost:27017/wiki'
重启wiki
cd /data/wiki
node wiki restart
我们启用nginx对wiki进行代理,wiki的域名暂为: wiki.example.com
在/usr/local/nginx/conf/vhost/下,创建文件wiki.conf,添加配置:
server {
listen 80;
server_name wiki.example.com;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://192.168.59.128:8556;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_next_upstream error timeout http_502 http_503 http_504;
}
access_log /usr/local/nginx/logs/wiki.log;
error_log /usr/local/nginx/logs/wiki.log;
}
重启nginx:
/usr/local/nginx/sbin/nginx -s reload
因wiki原代码在页面访问时对域名不友好,需修改wiki源代码:
domain : 'http://wiki.example.com'
其中wiki.example.com为我们自己wiki的域名,与nginx配置中的域名一致。
重启wiki,在浏览器输入wiki.example.com进行访问
以上,介绍!
config.yml在node wiki configure进行配置后生成,可以通过修改这个文件并重启wiki来更改配置。当前配置模板:
title: wiki
host: 'http://192.168.59.128
port: 8556
domain : 'http://wiki.example.com'
paths:
repo: ./repo
data: ./data
uploads:
maxImageFileSize: 3
maxOtherFileSize: 100
lang: zh
langRtl: false
public: false
auth:
defaultReadAccess: false
local:
enabled: true
google:
enabled: true
clientId: GOOGLE_CLIENT_ID
clientSecret: GOOGLE_CLIENT_SECRET
microsoft:
enabled: true
clientId: MS_APP_ID
clientSecret: MS_APP_SECRET
facebook:
enabled: false
clientId: FACEBOOK_APP_ID
clientSecret: FACEBOOK_APP_SECRET
github:
enabled: false
clientId: GITHUB_CLIENT_ID
clientSecret: GITHUB_CLIENT_SECRET
slack:
enabled: false
clientId: SLACK_CLIENT_ID
clientSecret: SLACK_CLIENT_SECRET
ldap:
enabled: false
url: 'ldap://serverhost:389'
bindDn: cn='root'
bindCredentials: BIND_PASSWORD
searchBase: 'o=users,o=example.com'
searchFilter: '(uid={{username}})'
tlsEnabled: false
tlsCertPath: 'C:\example\root_ca_cert.crt'
azure:
enabled: false
clientId: APP_ID
clientSecret: APP_SECRET_KEY
resource: 00000002-0000-0000-c000-000000000000
tenant: YOUR_TENANT.onmicrosoft.com
oauth2:
enabled: false
clientId: OAUTH2_CLIENT_ID
clientSecret: OAUTH2_CLIENT_SECRET
authorizationURL: OAUTH2_AUTH_URL
tokenURL: OAUTH2_TOKEN_URL
sessionSecret: 89a845b448c498e23c4f46698255717bff6f718fd3e62c4f149494ee05da19cb
db: 'mongodb://wiki:123456@localhost:27017/wiki'
git:
url: 'http://gitlab.example.com/dev/wiki.git'
branch: master
auth:
type: basic
username: wiki
password: 123456@example.com
privateKey: /etc/wiki/keys/git.pem
sslVerify: true
showUserEmail: true
serverEmail: linxw@example.com
features:
linebreaks: true
mathjax: true
externalLogging:
bugsnag: false
loggly: false
papertrail: false
rollbar: false
sentry: false
theme:
primary: indigo
alt: blue-grey
viewSource: all
footer: blue-grey
code:
dark: true
colorize: true
#!/bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mongodb
# Description: mongo db server
### END INIT INFO
EXE_FILE=/usr/local/mongodb/bin/mongod
CONFIG_FILE=/etc/mongodb.conf
MONGOPID=`ps -ef| grep mongodb.conf| grep -v grep| awk '{print $2}'`
test -x $EXE_FILE || exit 0
case "$1" in
start)
echo "Starting MongoDB server"
$EXE_FILE --config $CONFIG_FILE
echo "mongoDB started"
;;
stop)
echo "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
echo "MongoDB stopped"
;;
status)
ps -ef| grep mongodb.conf | grep -v grep
;;
restart)
echo "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
echo "Starting MongoDB server"
$EXE_FILE --config $CONFIG_FILE
echo "MongoDB restarted"
;;
*)
echo "Usage: /etc/init.d/mongodb {start|stop|status}"
exit 1
esac
exit 0