erpnext 为开源的erp系统,采用python语言编写,本次部署采用windows7+docker方式进行,erpnext需要运行python、redis、mariadb或者mysql、nginx。
参考资料
- erpnext gtihub源码地址 https://github.com/frappe/erpnext
- frappe web框架源码地址 https://github.com/frappe/frappe
- Multi-tenant platform to manage Frappe(管理工具) / ERPNext https://github.com/frappe/bench
docker镜像
- dockerfile构建地址 https://github.com/Ridhosribumi/docker-erpnext
erpnext基于ubuntu操作系统构建。
pull erpnext镜像
docker pull lukptr/erpnext7
运行erpnext
docker run -d --name erpnext -p 80:80 lukptr/erpnext7
- 启动之后访问虚拟机ip地址就可以,比如 192.168.99.100
- 登录名:Administrator 密码:12345678
这种方式运行之后,数据没有得到持久化,db数据没有持久化,app数据没有进行持久化,如果程序发生错误,下次再次运行erpnext时,数据就会消失。
erpnext 数据持久化
通过docker的volume方式,把docker容器的数据持久化到宿主机。
site1.local 目录数据持久化
- 把容器里面的site1.local目录复制到windows7系统,在做操作之前,把windows7的F盘共享给docker宿主机
docker cp erpnext:/home/frappe/frappe-bench/sites/site1.local /F/DataAgg/erpnext/frappe/
如下:
docker@dataagg:/F/DataAgg/erpnext/frappe/site1.local$ ls -la
total 9
drwxrwxrwx 1 docker staff 4096 Mar 20 00:52 ./
drwxrwxrwx 1 docker staff 4096 Mar 20 08:13 ../
drwxrwxrwx 1 docker staff 0 Mar 20 00:52 error-snapshots/
drwxrwxrwx 1 docker staff 0 Mar 19 17:07 locks/
drwxrwxrwx 1 docker staff 0 Mar 19 17:07 private/
drwxrwxrwx 1 docker staff 0 Mar 19 17:07 public/
-rwxrwxrwx 1 docker staff 107 Mar 20 03:29 site_config.json
drwxrwxrwx 1 docker staff 0 Mar 19 17:07 task-logs/
docker@dataagg:/F/DataAgg/erpnext/frappe/site1.local$
- db数据持久化
docker cp erpnext:/var/lib/mysql /F/DataAgg/erpnext/
把mysql的数据复制到F:\DataAgg\erpnext\mysql下面,下次启动erpnext时候,映射到宿主机
执行docker数据持久化命令:
docker run -d --name erpnext -v /F/DataAgg/erpnext/mysql/:/var/lib/mysql/ -v /F/DataAgg/erpnext/frappe/site1.local:/home/frappe/frappe-bench/sites/site1.local -v /F/DataAgg/erpnext/logs:/home/frappe/frappe-bench/logs -p 80:80 lukptr/erpnext7
进入容器查看mysql数据权限不对,如下:
# pwd
/var/lib/mysql
# ls -la
total 177065
drwxrwxrwx 1 frappe staff 4096 Mar 20 07:44 .
drwxr-xr-x 29 root root 4096 Mar 15 07:44 ..
drwxrwxrwx 1 frappe staff 393216 Mar 15 07:46 1bd3e0294da19198
-rwxrwxrwx 1 frappe staff 78504 Mar 20 07:36 2ad672a21283.err
-rwxrwxrwx 1 frappe staff 146756 Mar 20 07:44 6f45cefeaeff.err
-rwxrwxrwx 1 frappe staff 24576 Mar 20 07:44 aria_log.00000001
-rwxrwxrwx 1 frappe staff 52 Mar 20 07:44 aria_log_control
-rwxrwxrwx 1 frappe staff 0 Mar 15 07:39 debian-10.1.flag
-rwxrwxrwx 1 frappe staff 240847 Mar 20 07:11 fd9157e5d433.err
-rwxrwxrwx 1 frappe staff 50331648 Mar 20 07:44 ib_logfile0
-rwxrwxrwx 1 frappe staff 50331648 Mar 15 07:38 ib_logfile1
-rwxrwxrwx 1 frappe staff 79691776 Mar 20 07:44 ibdata1
-rwxrwxrwx 1 frappe staff 0 Mar 15 07:39 multi-master.info
drwxrwxrwx 1 frappe staff 40960 Mar 20 06:30 mysql
-rwxrwxrwx 1 frappe staff 15 Mar 15 07:39 mysql_upgrade_info
drwxrwxrwx 1 frappe staff 0 Mar 15 07:39 performance_schema
-rwxrwxrwx 1 frappe staff 24576 Mar 20 07:00 tc.log
#
修改mysql数据目录的用户和组为mysql,命令:
# chown -R mysql:mysql mysql
# ls -la
total 84
drwxr-xr-x 29 root root 4096 Mar 15 07:44 .
drwxr-xr-x 24 root root 4096 Mar 20 07:37 ..
drwxr-xr-x 7 root root 4096 Mar 15 07:44 apt
drwxr-xr-x 13 root root 4096 Mar 15 07:44 dpkg
drwxr-xr-x 2 root root 4096 Mar 23 2016 git
drwxr-xr-x 2 root root 4096 Feb 5 2016 initscripts
drwxr-xr-x 2 root root 4096 Feb 5 2016 insserv
drwxr-xr-x 2 root root 4096 Apr 12 2016 misc
drwxrwxrwx 1 frappe staff 4096 Mar 20 07:44 mysql
drwxr-xr-x 7 root root 4096 Mar 15 07:44 nginx
drwxr-xr-x 2 root root 4096 Nov 14 16:21 pam
drwxr-xr-x 2 postfix postfix 4096 Mar 15 07:44 postfix
drwxr-xr-x 2 root root 4096 Mar 15 07:37 python
drwxr-xr-x 2 redis redis 4096 Mar 15 07:37 redis
drwxr-xr-x 3 root root 4096 Nov 23 05:00 sudo
drwxr-xr-x 7 root root 4096 Mar 15 07:34 systemd
drwxr-xr-x 2 root root 4096 Nov 23 05:00 ucf
drwxr-xr-x 2 root root 4096 Mar 6 2015 update-rc.d
drwxr-xr-x 2 root root 4096 Feb 5 2016 urandom
drwxr-xr-x 3 root root 4096 Mar 15 07:44 vim
drwxr-xr-x 2 root root 4096 Mar 15 07:37 xfonts
#
发现/var/lib/mysql的目录权限没有发生变化,再查看mysqld服务是否启动,多次输入supervisorctl status 查看服务状态
# supervisorctl status
crond:cron RUNNING pid 30, uptime 0:46:25
frappe-bench-redis:frappe-bench-redis-cache RUNNING pid 9, uptime 0:46:25
frappe-bench-redis:frappe-bench-redis-queue RUNNING pid 8, uptime 0:46:25
frappe-bench-redis:frappe-bench-redis-socketio RUNNING pid 10, uptime 0:46:25
frappe-bench-web:frappe-bench-frappe-web RUNNING pid 13, uptime 0:46:25
frappe-bench-web:frappe-bench-node-socketio RUNNING pid 14, uptime 0:46:25
frappe-bench-workers:frappe-bench-frappe-default-worker-0 RUNNING pid 26, uptime 0:46:25
frappe-bench-workers:frappe-bench-frappe-long-worker-0 RUNNING pid 28, uptime 0:46:25
frappe-bench-workers:frappe-bench-frappe-schedule RUNNING pid 27, uptime 0:46:25
frappe-bench-workers:frappe-bench-frappe-short-worker-0 RUNNING pid 29, uptime 0:46:25
mysqld RUNNING pid 7960, uptime 0:00:04
nginx RUNNING pid 17, uptime 0:46:25
# supervisorctl status
crond:cron RUNNING pid 30, uptime 0:46:30
frappe-bench-redis:frappe-bench-redis-cache RUNNING pid 9, uptime 0:46:30
frappe-bench-redis:frappe-bench-redis-queue RUNNING pid 8, uptime 0:46:30
frappe-bench-redis:frappe-bench-redis-socketio RUNNING pid 10, uptime 0:46:30
frappe-bench-web:frappe-bench-frappe-web RUNNING pid 13, uptime 0:46:30
frappe-bench-web:frappe-bench-node-socketio RUNNING pid 14, uptime 0:46:30
frappe-bench-workers:frappe-bench-frappe-default-worker-0 RUNNING pid 26, uptime 0:46:30
frappe-bench-workers:frappe-bench-frappe-long-worker-0 RUNNING pid 28, uptime 0:46:30
frappe-bench-workers:frappe-bench-frappe-schedule RUNNING pid 27, uptime 0:46:30
frappe-bench-workers:frappe-bench-frappe-short-worker-0 RUNNING pid 29, uptime 0:46:30
mysqld RUNNING pid 8061, uptime 0:00:03
nginx RUNNING pid 17, uptime 0:46:30
#
通过上面pid可以发现,mysqld的pid一直在递增,说明mysqld服务一直在重启。
由于mysql数据目录的用户和属组没有成功改成mysql,导致mysql服务一直起不来。初步判断是因为共享机制的问题,windows7的数据共享个docker 宿主机,docker宿主机再次把数据映射到docker erpnext容器。其他windows系统可以尝试上面的方法持久化mysql数据。在linux下面采用这种方式没有问题,已经测试可以使用。
采用外部mariadb数据库
由于windows7的共享机制尝试失败,采用外部db作为erpnext存储,达到持久化数据目的。
- 修改F:\DataAgg\erpnext\frappe\site1.local目录下面的site_config.json文件内容
{
"db_host": "192.168.10.234",
"db_name": "erpnext",
"db_user": "erpnext",
"db_password": "erpnext"
}
- 修改mariadb的配置文件
[mysqld]
innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
- 运行erpnext容器,备份mysql数据
docker run -d --name erpnext -v /F/DataAgg/erpnext/frappe/site1.local:/home/frappe/frappe-bench/sites/site1.local \
-p 80:80 lukptr/erpnext7
# cd /home/frappe/frappe-bench
# bench backup
# pwd
/home/frappe/frappe-bench/sites/site1.local/private/backups
# ls -la
total 3974
drwxrwxrwx 1 frappe staff 4096 Mar 20 08:37 .
drwxrwxrwx 1 frappe staff 0 Mar 19 17:07 ..
-rwxrwxrwx 1 frappe staff 3156985 Mar 20 03:01 20170320_110153_83043d43_database.sql
-rwxrwxrwx 1 frappe staff 453779 Mar 20 03:01 20170320_110153_83043d43_database.sql.gz
-rwxrwxrwx 1 frappe staff 453458 Mar 20 08:37 20170320_163732_b350d2cf_database.sql.gz
#
启动20170320_163732_b350d2cf_database.sql.gz文件为备份的sql文件
- 在外部db执行备份的sql文件
最终采用下面命令启动erpnext
docker run -d --name erpnext -v /F/DataAgg/erpnext/logs:/home/frappe/frappe-bench/logs -v /F/DataAgg/erpnext/frappe/site1.local:/home/frappe/frappe-bench/sites/site1.local -p 80:80 lukptr/erpnext7
访问192.168.99.100进入登陆界面,默认的用户名Administrator 密码 12345678,app数据和db数据得到持久化处理。