Docs/Others/leanote安装配置.md
2022-10-18 16:59:37 +08:00

353 lines
8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

leanote安装配置
环境:
Centos 6.5 x86_64
所需软件:
go1.8.linux-amd64.tar.gz
mongodb-linux-x86_64-rhel62-3.4.4.tgz
leanote-all-master.zip
nginx-1.12.1.tar.gz
setuptools-36.2.7.zip
supervisor-3.3.3.tar.gz
一、安装go
1、解压
```
tar zxvf go1.8.linux-amd64.tar.gz -C /usr/local/
```
2、新建目录mygo放go的模块及编译后的文件
```
mkdir /usr/local/mygo
```
3、配置环境变量
```
vi /etc/profile
添加以下内容:
GOROOT=/usr/local/go
GOPATH=/usr/local/mygo
PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOROOT GOPATH PATH
```
使环境变量生效
```
source /etc/profile
```
4、验证
```
go version
```
二、安装revel
1、 解压leanote-all-master.zip
```
unzip leanote-all-master.zip
```
2、 把src文件放到/usr/local/mygo中
```
cp rf leanote-all-master/src /usr/local/mygo/
```
3、 安装
```
cd /usr/local/mygo/src && go install github.com/revel/cmd/revel
```
三、安装mongodb
1、解压并重命名解压目录
```
tar zxvf mongodb-linux-x86_64-rhel62-3.4.4.tgz -C /usr/local
mv /usr/local/mongodb-linux-x86_64-rhel62-3.4.4 /usr/local/mongodb
```
2、添加环境变量
```
vi /etc/profile
```
当前的环境配置如下:
```
GOROOT=/usr/local/go
GOPATH=/usr/local/mygo
MONGO=/usr/local/mongodb
PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$MONGO/bin
export GOROOT GOPATH PATH
```
使环境变量生效
```
source /etc/profile
```
3、新建数据存放目录
```
mkdir /usr/local/data
```
4、启动数据库
```
mongod --dbpath /usr/local/data
```
5、导入数据
```
mongorestore -h localhost -d leanote dir /usr/local/mygo/src/github.com/leanote/leanote/mongodb_backup/leanote_install_data
```
四、配置leanote
修改/usr/local/mygo/src/github.com/leanote/leanote/conf/app.conf
```
http.port=9000修改为http.port=8080
site.url=http://localhost:9000修改为site.url=http://10.188.12.133:8080
更改app.secret后面的字符串总长度保持不变
```
五、启动leanote
```
revel run github.com/leanote/leanote
```
六、访问
浏览器地址栏输入http://10.188.12.133:8080登录默认用户名admin密码abc123
现在密码zeroc.net
扩展
为leanote配置数据库用户密码
1、修改/usr/local/mygo/src/github.com/leanote/leanote/conf/app.conf
```
db.dbname=修改为db.username=ZeroC
db.password修改为db.password=toor
```
2、启动mongodb
```
mongod --dbpath /usr/local/data
```
3、登录mongodb另一个终端中
```
mongo
```
4、添加ZeroC用户>开头的为命令,##为注释#为shell命令,其他为返回值)
```
##切换到leanote数据库
>use leanote
switched to db leanote
##添加ZeroC用户密码为toor角色为readWrite
>db.createUser({user:"ZeroC",pwd:"toor",roles:["readWrite"]});
Successfully added user: { "user" : "ZeroC", "roles" : [ "readWrite" ] }
##停止mongo
>use admin;
>db.shutdownServer()
>exit
```
启动mongodb
```
mongod --dbpath /usr/local/data --auth
```
登录mongodb并切换到leanote数据库
```
##此时查看数据表会失败
>show collections;
2017-08-02T21:46:56.166+0800 E QUERY [thread1] Error: listCollections failed: {
"ok" : 0,
"errmsg" : "not authorized on leanote to execute command { listCollections: 1.0, filter: {} }",
"code" : 13,
"codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:805:1
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:817:19
DB.prototype.getCollectionNames@src/mongo/shell/db.js:828:16
shellHelper.show@src/mongo/shell/utils.js:762:9
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1
##认证
> db.auth("ZeroC","toor");
1
##再看表
>show collections;
albums
attachs
blog_comments
blog_likes
blog_singles
……
```
5、启动leanote
```
revel run github.com/leanote/leanote
```
修改admin的邮箱
1、登录mongodb
```
mongo
```
2、更新数据
```
##切换到leanote数据库
>use leanote;
switched to db leanote
##认证
> db.auth("ZeroC","toor");
1
##查看数据
>db.users.find({Username:"admin"})
##修改邮箱
>db.users.update({Username:"admin"},{$set:{Email:"vrocwang@gmail.com"}})
```
以后台方式启动mongodb
说明如果已经启动过mongodb那么需要清理掉数据文件不然启动会报错
为方便操作,把启动选项放进配置文件中
1、新建conflog目录
```
mkdir /usr/local/mongodb/{conf,log}
```
2、添加配置文件
```
cat /usr/local/mongodb/conf/mongodb.conf
dbpath=/usr/local/data
logpath=/usr/local/mongodb/log/log
pidfilepath=/usr/local/mongodb/conf/mongo.pid
## 为每一个数据库按照数据库名建立文件夹存放
directoryperdb=true
## 以追加的方式记录日志
logappend=true
## 绑定ip
bind_ip=127.0.0.1
## 端口
port=27017
## 日志文件的最大大小。单位为Mb默认为硬盘剩余空间的5%
oplogSize=1000
## 后台运行
fork=true
## 不预先分配存储
noprealloc=true
## 认证方式启动
auth=true
```
3、启动
```
mongod -f /usr/local/mongodb/conf/mongodb.conf
```
为admin添加用户
注意此处不要以认证方式启动不然无法操作admin数据库因为mongodb默认没有管理员用户无法认证
1、登录mongodb
```
mongo
```
2、切换到admin库
```
>use admin;
```
3、查看admin库中的表
```
> show collections;
system.users
system.version
```
4、查看用户(默认为空)
```
> db.system.users.find()
```
5、添加数据库管理员
```
>db.createUser({user:"admin",pwd:"toor",roles:["readWriteAnyDatabase","dbAdminAnyDatabase","clusterAdmin"]})
```
用supervisor管理leanote使leanote后台运行
supervisor是python的一个模块需要先安装setuptools
1、解压setuptools并安装
```
unzip setuptools-36.2.7.zip
cd setuptools-36.2.7
python setup.py install
```
2、解压supervisor并安装
```
tar zxvf supervisor-3.3.3.tar.gz
cd supervisor-3.3.3
python setup.py install
```
3、配置supervisor ##开头的行为说明
①新建目录
```
mkdir -p /usr/local/supervisor/logs
```
②生成配置文件echo_supervisord_conf 在/usr/bin中
```
echo_supervisord_conf > /usr/local/supervisor/supervisord.conf
```
③修改配置文件如下
```
[root@ZeroC supervisor]# sed -e "/^;/d" -e "/^$/d" supervisord.conf
[unix_http_server]
file=/usr/local/supervisor/supervisor.sock ; the path to the socket file
chmod=0700 ; socket file mode (default 0700)
[supervisord]
logfile=/usr/local/supervisor/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/usr/local/supervisor/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
minfds=1024 ; min. avail startup file descriptors; default 1024
minprocs=200 ; min. avail process descriptors;default 200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///usr/local/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /usr/local/supervisor/*.ini
④添加leanote的配置文件/usr/local/supervisor/leanote.ini内容如下
[program:leanote]
command=/usr/local/mygo/bin/revel run github.com/leanote/leanote
directory=/usr/local/mygo/src
autorstart=true
redirect_stderr=true
stdout_logfile=/usr/local/supervisor/logs/leanote.log
user=root
priority=1
```
⑤启动supervisor
```
supervisord -c /usr/local/supervisor/supervisord.conf
supervisorctl start all
```
导出leanote数据文件
```
mongodump -h 127.0.0.1 -u ZeroC -p toor -d leanote -o /root/data
```
注意如果用auth模式启动无备份权限无法备份数据库
报错如下:
```
2017-11-30T11:15:26.732+0800 Failed: error getting database names: not authorized on admin to execute command { listDatabases: 1 }
```