1百揭、安裝MongoDB
Leanote 依賴 MongoDB 作為數(shù)據(jù)存儲
運(yùn)行依賴
yum install libcurl openssl openssh-clients numactl
MongoDB基本優(yōu)化
echo "echo never > /sys/kernel/mm/transparent_hugepage/defrag" >>/etc/rc.local
echo "vm.swappiness=0" >>/etc/sysctl.conf
echo "mongod soft nofile 64000" >>/etc/security/limits.conf
echo "mongod hard nofile 64000" >>/etc/security/limits.conf
echo "mongod soft nproc 32000" >>/etc/security/limits.conf
echo "mongod hard nproc 32000" >>/etc/security/limits.conf
下載MongoDB
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.6.tgz
創(chuàng)建用戶與數(shù)據(jù)目錄
/usr/sbin/groupadd -r mongod
/usr/sbin/useradd -M -r -g mongod -s /bin/false mongod
mkdir -p /data/mongodb/{data,logs,script,backup,tmp,pid}
解壓安裝
tar -zxvf mongodb-linux-x86_64-rhel70-3.6.6.tgz -C /usr/local/
ln -sv /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/ /usr/local/mongodb
創(chuàng)建配置文件
cat > /usr/local/mongodb/mongod.conf << EOF
logpath=/data/mongodb/logs/mongodb.log
logappend=true
fork=true
port=27018
bind_ip=0.0.0.0
dbpath=/data/mongodb/data
directoryperdb=true
pidfilepath=/data/mongodb/pid/mongo.pid
#限制緩存(默認(rèn)是物理內(nèi)存的一半,按自己當(dāng)前環(huán)境設(shè)置)
wiredTigerCacheSizeGB=1
#auth=true
#rest=true
EOF
配置環(huán)境變量并生效
echo 'export PATH=$PATH:/usr/local/mongodb/bin' >>/etc/profile
source /etc/profile
配置啟動腳本
cat /etc/init.d/mongod
#!/bin/bash
# mongod - Startup script for mongod
# chkconfig: 35 85 15
# description: Mongo is a scalable, document-oriented database.
# processname: mongod
# config: /usr/local/mongodb/mongod.conf
# pidfile: /data/mongodb/pid/mongo.pid
. /etc/rc.d/init.d/functions
# things from mongod.conf get there by mongod reading it
CONFIGFILE="/usr/local/mongodb/mongod.conf"
OPTIONS=" -f $CONFIGFILE"
SYSCONFIG="/etc/sysconfig/mongod"
DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"`
PIDFILE=`awk -F= '/^pidfilepath=/{print $2}' "$CONFIGFILE"`
mongod="/usr/local/mongodb/bin/mongod"
MONGO_USER=mongod
MONGO_GROUP=mongod
if [ -f "$SYSCONFIG" ]; then
. "$SYSCONFIG"
fi
# Handle NUMA access to CPUs (SERVER-3574)
# This verifies the existence of numactl as well as testing that the command works
NUMACTL_ARGS="--interleave=all"
if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
then
NUMACTL="numactl $NUMACTL_ARGS"
else
NUMACTL=""
fi
start()
{
echo -n $"Starting mongod: "
daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
}
stop()
{
echo -n $"Stopping mongod: "
killproc -p "$PIDFILE" -d 300 $mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
}
restart () {
stop
start
}
ulimit -n 655350
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/mongod ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL
配置權(quán)限并設(shè)置開機(jī)啟動
chown -R mongod.mongod /usr/local/mongodb/
chmod g+s /usr/local/mongodb/
chown -R mongod.mongod /data/mongodb/
chmod g+s /data/mongodb/
chmod +x /etc/init.d/mongod
chkconfig --add mongod
chkconfig mongod on
配置賬號密碼
啟動服務(wù):
service mongod start
mongo 127.0.0.1:27018
>use admin
>db.createUser({ user: "note", pwd: "noteAdmin", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })
>db.grantRolesToUser( "note", [ { role: "root", db: "admin" } ])
>use leanote
>db.createUser({ user: 'root', pwd: 'abc123', roles: [{ role: 'dbOwner', db: 'leanote'}] })
說明:admin為超級管理員,leanote只是leanote數(shù)據(jù)庫管理權(quán)限
停止服務(wù):
service mongod stop
設(shè)置開啟認(rèn)證:
sed -i 's@#auth=true@auth=true@' /usr/local/mongodb/mongod.conf
啟動服務(wù)器生效:
service mongod start
配置日志分割
cat /usr/local/mongodb/logRotate.sh
#!/bin/bash
#Rotate the MongoDB logs to prevent a single logfile from consuming too much disk space.
app=mongod
mongodPath=/usr/local/mongodb/bin/
pidArray=$(pidof $mongodPath/$app)
for pid in $pidArray;do
if [ $pid ]
then
kill -SIGUSR1 $pid
fi
done
exit
chmod +x /usr/local/mongodb/logRotate.sh
echo "59 23 * * 5 root /usr/local/mongodb/logRotate.sh" >/etc/crontab
測試認(rèn)證訪問
mongo 127.0.0.1:27018/admin -unote -pnoteAdmin
2厌秒、安裝 Leanote(源碼或二進(jìn)制)
官方源碼站點(diǎn):
https://github.com/leanote/leanote
2.1 源碼安裝
2.1.1安裝Golang(如果源碼編譯需要此步驟)
因?yàn)閘eanote是由go語言編寫勉抓,所以安裝源碼版本的話需要先搭建go語言的編譯環(huán)境
Golang官網(wǎng):
https://golang.google.cn/
Golang二進(jìn)制包下載鏈接:
wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
創(chuàng)建相關(guān)目錄
mkdir -pv /usr/local/gopackage
解壓文件
tar -C /usr/local/ -xzf go1.13.5.linux-amd64.tar.gz
添加全局變量并生效
cat >> /etc/profile <<EOF
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopackage
export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
EOF
source /etc/profile
驗(yàn)證是否安裝成功
go version
2.1.2獲取Revel和 Leanote 源碼
官方安裝步驟:
https://github.com/leanote/leanote/wiki/Leanote-source-installation-on-Mac-and-Linux-(En)
方法1(官方推薦)
下載leante-all-master.zip。將其解壓縮到任何文件夾并將src目錄移動到/usr/local/gopackage
wget https://github.com/leanote/leanote-all/archive/master.zip
unzip master.zip
cp -r leanote-all-master/src /usr/local/gopackage
使用以下命令生成revel將用于運(yùn)行的命令Leanote
go install github.com/revel/cmd/revel
說明:Leanote的源碼在 /usr/local/gopackage/src/github.com/leanote/leanote下
方法2
也可以使用go get下載Leanote程序包。正如go get將調(diào)用git和mercurial命令一樣澎羞,您需要先安裝它們。
安裝git
yum install git-core mercurial openssh-server openssh-client
然后提取Revel敛苇,Leanote以及相關(guān)的依賴關(guān)系:
go get github.com/revel/cmd/revel
go get github.com/leanote/leanote/app
說明:下載這些文件可能需要一段時(shí)間妆绞,請耐心等待。的源代碼Leanote存儲在中/usr/local/gopackage/src/github.com/leanote/leanote
2.2枫攀、二進(jìn)制安裝(推薦使用)
官方安裝步驟:
https://github.com/leanote/leanote/wiki/leanote-binary-installation-on-Mac-and-Linux-(En)
2.2.1獲取二進(jìn)制包
二進(jìn)制包下載地址:
http://leanote.org/#download
選擇自己對于系統(tǒng)版本:
wget https://nchc.dl.sourceforge.net/project/leanote-bin/2.6.1/leanote-linux-amd64-v2.6.1.bin.tar.gz
將其保存在/usr/local/文件夾中括饶,請.zip使用以下命令將文件解壓縮到該文件夾中:
cd /usr/local/
tar -C /usr/local/ -xzf leanote-linux-amd64-v2.6.1.bin.tar.gz
這將Leanote在下創(chuàng)建目錄/usr/local/
3、初始化數(shù)據(jù)(根據(jù)自己情況配置)
3.1源碼配置文件路徑
修改連接數(shù)據(jù)庫配置
db.username和db.password的配置文件mongodb
編輯文件
# mongdb
db.host=127.0.0.1
db.port=27018
db.dbname=leanote # required
db.username=root # if not exists, please leave it blank
db.password=abc123 # if not exists, please leave it blank
Mongodb導(dǎo)入Leanote初始數(shù)據(jù)
leanote 初始數(shù)據(jù)在/usr/local/gopackage/src/github.com/leanote/leanote/mongodb_backup/leanote_install_data/
導(dǎo)入數(shù)據(jù)
mongorestore -h localhost:27018 -uroot -pabc123 -d leanote --dir /usr/local/gopackage/src/github.com/leanote/leanote/mongodb_backup/leanote_install_data/
3.2 二進(jìn)制配置文件路徑
修改連接數(shù)據(jù)庫配置
/usr/local/leanote/conf/app.conf
# mongdb
db.host=127.0.0.1
db.port=27018
db.dbname=leanote # required
db.username=root # if not exists, please leave it blank
db.password=abc123 # if not exists, please leave it blank
二進(jìn)制數(shù)據(jù)初始數(shù)據(jù)路徑以及導(dǎo)入初始化數(shù)據(jù)
/usr/local/leanote/mongodb_backup/leanote_install_data/
mongorestore -h localhost:27018 -uroot -pabc123 -d leanote --dir /usr/local/leanote/mongodb_backup/leanote_install_data/
4来涨、運(yùn)行Leanote并訪問
源碼安裝啟動 Leanote 服務(wù)
nohup revel run github.com/leanote/leanote >> /var/log/leanote.log 2>&1 &
打開瀏覽器訪問(我這里內(nèi)網(wǎng)做了域名解析服務(wù)): http://test7.shuai.cn:9000
二進(jìn)制安裝啟動 Leanote 服務(wù)
nohup /bin/bash /usr/local/leanote/bin/run.sh >> /var/log/leanote.log 2>&1 &
停止服務(wù)器
jobs 查看后臺執(zhí)行任務(wù)
kill %1 停止編號1的任務(wù)
jobnum=`jobs | grep "revel run github.com/leanote/leanote" | awk -F"]" '{print $1}'|awk -F"[" '{print $2}'`;kill %$jobnum
jobs
初始users表有兩個(gè)帳戶:
管理Leanote的管理員
username: admin
password: abc123
只是為了示范
username: demo@leanote.com
password: demo@leanote.com
5图焰、導(dǎo)出PDF配置 wkhtmltopdf
安裝wkhtmltopdf的依賴包:
yum install -y fontconfig libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi libpng libjpeg
安裝包下載地址:
https://wkhtmltopdf.org/downloads.html
選擇自己對于系統(tǒng)版本:
wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm
安裝wkhtmltopdf:
rpm -ivh wkhtmltox-0.12.5-1.centos7.x86_64.rpm
6、在PC端和Android端使用
到Leanote官網(wǎng)可以下載相應(yīng)客戶端
https://leanote.com/index#
不管哪種方式
在登錄時(shí)選擇登錄自建服務(wù)(或自定義的服務(wù)器)蹦掐,填入自己的地址
6技羔、常見問題解答
https://github.com/leanote/leanote/wiki/QA