2021年4月4日星期日

docker 安装 leanote

1. 下载 leanote 安装包
在 [https://github.com/leanote/leanote/releases](https://github.com/leanote/leanote/releases),下载最新版本 leanote

当前版本:leanote-linux-amd64-v2.6.1.bin.tar.gz

2. 下载 mongo 镜像
```
docker pull mongo:latest
```

3. 建立容器,并开启认证
```
docker run -itd -p 27017:27017 --restart=always --name mongo -v /home/mongo:/data/db mongo --auth
```

3. 解压 leanote-linux-amd64-v2.6.1.bin.tar.gz
```
tar zxvf leanote-linux-amd64-v2.6.1.bin.tar.gz
```

4. 把 leanote 初始化数据放入 docker
```
docker cp leanote/mongodb_backup/leanote_install_data mongo:/
```

5. 建立 mongo 的全局管理员,username: admin,password: abc123
```
docker exec -it mongo mongo

use admin;
db.createUser({ user:'admin',pwd:'abc123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
exit
```

6. 对 mongo 进行初始化
```
docker exec -it mongo mongorestore -h localhost -d leanote --drop --dir /leanote_install_data/ --authenticationDatabase admin -u admin -p 'abc123'
```

7. 建立 leanote 数据库管理员,username: leanote,password: leanote123
```
docker exec -it mongo mongo -u "admin" -p "abc123" --authenticationDatabase "admin"

use leanote;
db.createUser({user: 'leanote', pwd: 'leanote123', roles: [{role: 'dbOwner', db: 'leanote'}]});
exit
```

8. 下载 leanote 镜像
```
docker pull cnkmmk/leanote:2.6.1
```

9. 修改配置文件
```
mkdir -p /home/leanote/{conf,files}
cp leanote/conf/* /home/leanote/conf/

docker inspect mongo | grep IPAddress

sed -i 's/^db.host=127.0.0.1/db.host=172.17.0.2/g' /home/leanote/conf/app.conf
sed -i 's/^db.username= #/db.username=leanote #/g' /home/leanote/conf/app.conf
sed -i 's/^db.password= #/db.password=leanote123 #/g' /home/leanote/conf/app.conf
```

10. 启动容器
```
docker run -itd -p 9000:9000 --restart=always -v /home/leanote/conf:/leanote/conf -v /home/leanote/files:/leanote/files --name leanote leanote:latest
```

11. 初始用户
username: admin
password: abc123

12. 关闭注册使用
```
后台管理 -> confiration -> Open Register
```
以后要加入其它人员,用管理员人工加入
```