Crmeb商城系统开源版目前版本在5.4.0,本文以此版本为基础实现docker部署。
crmeb 开源版本对系统的要求如下:
运行环境 | 要求 |
---|---|
操作系统 | Linux / Windows |
WEB 服务 | Nginx / Apache / IIS |
PHP 版本 | PHP 7.1 ~ 7.4 |
数据库 | MySQL 5.7 ~ 8.0(引擎:InnoDB) |
缓存 | Redis(可选,不安装则使用文件缓存) |
管理器 | Supervisor(用于管理消息队列) |
推荐工具 | 宝塔面板(简单易用) |
云服务器 | 阿里云 ECS / 腾讯云 CVM / 京东云ECS |
开放端口 | 80, 21, 8888, 888, 443, 3306, 6379(授权对象:0.0.0.0/0 ) |
PHP 扩展 | fileinfo(可选)、redis(可选) |
禁用函数 | proc_open , pcntl_signal , pcntl_signal_dispatch , pcntl_fork , pcntl_wait , pcntl_alarm |
消息队列 | 运行命令:php think queue:listen --queue (使用Supervisor) |
长连接 | 运行命令:sudo -u www php think workerman start --d (命令行执行) |
定时任务 | 运行命令:php think timer start --d (命令行执行) |
本次实战,只实现crmeb系统本身运行环境,即php环境的容器化部署,其它部分全部安装在宿主机,如:nginx,mysql,redis.
一、容器化部署的部分
PHP7.4-FPM、supervisord
dockerfiler内容如下:
python
FROM phpdockerio/php:7.4-fpm AS crmeb_php
WORKDIR /var/www
# 设置权限
RUN chown -R www-data:www-data /var/www
# 扩展依赖
RUN apt-get update; \
apt-get -y --no-install-recommends install \
php7.4-bcmath \
php7.4-redis \
php7.4-mysqli \
php7.4-gd \
supervisor
RUN apt-get clean
#RUN apt-get autoremove
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN echo "open_basedir = /tmp:/var" > /etc/php/7.4/fpm/conf.d/open_basedir.ini
# 配置PHP
COPY php-ini-overrides.ini /etc/php/7.4/fpm/conf.d/99-overrides.ini
# 配置 supervisord
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 暴露默认的PHP-FPM端口
EXPOSE 9000 4001 40002 40003
# 启动 Supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
需要用到的文件如下:
php-ini-overrides.ini,该文件参考官方安装手册,从中提取而来。若有修改请以官方版本为准。
python
upload_max_filesize = 100M
post_max_size = 108M
open_basedir = "/var:/var/tmp/:/tmp/"
disable_functions = system, exec, shell_exec, passthru, proc_get_status, checkdnsrr, getmxrr, getservbyname, getservbyport, syslog, popen, show_source, highlight_file, dl, socket_listen, socket_create, socket_bind, socket_accept, socket_connect, stream_socket_server, stream_socket_accept, stream_socket_client, ftp_connect, ftp_login, ftp_pasv, ftp_get, sys_getloadavg, disk_total_space, disk_free_space, posix_ctermid, posix_get_last_error, posix_getcwd, posix_getegid, posix_geteuid, posix_getgid, posix_getgrgid, posix_getgrnam, posix_getgroups, posix_getlogin, posix_getpgid, posix_getpgrp, posix_getpid, posix_getppid, posix_getpwnam, posix_getpwuid, posix_getrlimit, posix_getsid, posix_getuid, posix_isatty, posix_kill, posix_mkfifo, posix_setegid, posix_seteuid, posix_setgid, posix_setpgid, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname
upload_tmp_dir = /var/www/temp
supervisord.conf
bash
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[program:php-fpm]
command=/usr/sbin/php-fpm7.4 -F
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/php-fpm.stderr.log
stdout_logfile=/var/log/supervisor/php-fpm.stdout.log
[program:crmeb-queue]
command=/usr/bin/php7.4 /var/www/think queue:listen --queue
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/crmeb-queue.stdout.log
stderr_logfile=/var/log/supervisor/crmeb-queue.stderr.log
[program:crmeb-workerman]
command=/usr/bin/php7.4 /var/www/think workerman restart
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/crmeb-workerman.stdout.log
stderr_logfile=/var/log/supervisor/crmeb-workerman.stderr.log
[program:crmeb-timer]
command=/usr/bin/php7.4 /var/www/think timer restart
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/crmeb-timer.stdout.log
stderr_logfile=/var/log/supervisor/crmeb-timer.stderr.log
这里维护了php-fpm进程,以及crmeb要求的队列,长连接,定时任务三个进程。
编译镜像:
bash
docker build -t crmeb-open:7.4 .
二、nginx 设置
nginx安装在宿主机,配置文件如下:
bash
server {
listen 80;
index index.php index.html;
server_name bz.crmeb.net;
root /var/www/crmeb/public;
location / {
# try_files $uri /index.php$is_args$args;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
location /notice {
proxy_pass http://YOUR_LOCAL_HOST_IP:40002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /msg {
proxy_pass http://YOUR_LOCAL_HOST_IP:40003/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ~ \.php$ {
root /var/www/public;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 0.0.0.0:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
这里把"YOUR_LOCAL_HOST_IP"替换成要宿主机的本地IP地址。按道理0.0.0.0也行,可以试试。
三、其它服务
redis、amqp等服务请自行安装,这里都装在宿主机上。
运行容器:
bash
docker run -itd --name=crmeb-open-5.4.0 -v /var/www/crmeb:/var/www -v /var/www/crmeb/runtime:/var/www/temp -v /data/log/crmeb:/var/log/supervisor -p 9000:9000 -p 40001:40001 -p 40002:40002 -p 40003:40003 crmeb-open:7.4
若无报错,则部署成功。
四、系统安装
按照官方手册的方法执行安装,过程中会提示文件权限问题,按照要求修改相关文件权限。
在设置mysql,redis时,IP地址要填宿主机的IP。或者填0.0.0.0试试。
系统安装完成后,可以重启一下容器。
其它问题想到再补充。
-完-