自建Leanote云笔记
leanote 笔记    2020-08-10 08:02:49    5    0    0
caidao   leanote 笔记



1、安装MongoDB
Leanote 依赖 MongoDB 作为数据存储

运行依赖
yum install libcurl openssl openssh-clients numactl

MongoDB基本优化
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

创建用户与数据目录
/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

创建配置文件
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
#限制缓存(默认是物理内存的一半,按自己当前环境设置)
wiredTigerCacheSizeGB=1
#auth=true
#rest=true
EOF

配置环境变量并生效
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

配置权限并设置开机启动
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
配置账号密码
启动服务:
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数据库管理权限

停止服务:
service mongod stop

设置开启认证:
sed -i 's@#auth=true@auth=true@' /usr/local/mongodb/mongod.conf

启动服务器生效:
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
测试认证访问
mongo 127.0.0.1:27018/admin -unote -pnoteAdmin

2、安装 Leanote(源码或二进制)
官方源码站点:
https://github.com/leanote/leanote

2.1 源码安装
2.1.1安装Golang(如果源码编译需要此步骤)
因为leanote是由go语言编写,所以安装源码版本的话需要先搭建go语言的编译环境
Golang官网:
https://golang.google.cn/

Golang二进制包下载链接:
wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz

创建相关目录
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

验证是否安装成功
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将用于运行的命令Leanote
go install github.com/revel/cmd/revel

说明:Leanote的源码在 /usr/local/gopackage/src/github.com/leanote/leanote下

方法2
也可以使用go get下载Leanote程序包。正如go get将调用git和mercurial命令一样,您需要先安装它们。
安装git
yum install git-core mercurial openssh-server openssh-client

然后提取Revel,Leanote以及相关的依赖关系:

go get github.com/revel/cmd/revel
go get github.com/leanote/leanote/app
说明:下载这些文件可能需要一段时间,请耐心等待。的源代码Leanote存储在中/usr/local/gopackage/src/github.com/leanote/leanote

2.2、二进制安装(推荐使用)
官方安装步骤:
https://github.com/leanote/leanote/wiki/leanote-binary-installation-on-Mac-and-Linux-(En)

2.2.1获取二进制包
二进制包下载地址:
http://leanote.org/#download

选择自己对于系统版本:
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在下创建目录/usr/local/

3、初始化数据(根据自己情况配置)
3.1源码配置文件路径
修改连接数据库配置
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导入Leanote初始数据
leanote 初始数据在/usr/local/gopackage/src/github.com/leanote/leanote/mongodb_backup/leanote_install_data/
导入数据

mongorestore -h localhost:27018 -uroot -pabc123 -d leanote --dir /usr/local/gopackage/src/github.com/leanote/leanote/mongodb_backup/leanote_install_data/
3.2 二进制配置文件路径
修改连接数据库配置
/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
二进制数据初始数据路径以及导入初始化数据
/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、运行Leanote并访问
源码安装启动 Leanote 服务
nohup revel run github.com/leanote/leanote >> /var/log/leanote.log 2>&1 &
打开浏览器访问(我这里内网做了域名解析服务): http://test7.shuai.cn:9000

二进制安装启动 Leanote 服务
nohup /bin/bash /usr/local/leanote/bin/run.sh >> /var/log/leanote.log 2>&1 &
停止服务器
jobs 查看后台执行任务
kill %1 停止编号1的任务

jobnum=`jobs | grep "revel run github.com/leanote/leanote" | awk -F"]" '{print $1}'|awk -F"[" '{print $2}'`;kill %$jobnum
jobs
初始users表有两个帐户:
管理Leanote的管理员
username: admin
password: abc123
只是为了示范
username: demo@leanote.com
password: demo@leanote.com
image.png
5、导出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

选择自己对于系统版本:
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官网可以下载相应客户端
https://leanote.com/index#

image.png
不管哪种方式
在登录时选择登录自建服务(或自定义的服务器),填入自己的地址

6、常见问题解答
https://github.com/leanote/leanote/wiki/QA

上一篇: Decentraland登陆指南

下一篇: bootstrap_darkroom修改

5 人读过
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论
文档导航