调试了一下午,终于摸索调试成功了。下面是docker compose的配置文件。
[root@localhost web-db_docker]# cat docker-compose.yml
version: '3'
services:
db:
image: mysql:5.5
volumes:
- /data/mysql:/data/mysql ##/data/mysql是我本地数据库存放目录
- /data/config/my.cnf:/etc/mysql/my.cnf ##映射my.cnf数据库配置文件
restart: always
environment:
MYSQL_ROOT_PASSWORD: "password" #定义mysql数据库密码
ports:
- "3306:3306"
nginx-php-fpm:
image: richarvey/nginx-php-fpm:latest
restart: always
ports:
- "9000:9000"
- "80:80"
links:
- db
volumes:
- /data/www/build:/var/www/html #网站目录映射
- /data/config/typecho.conf:/etc/nginx/sites-enabled/default.conf #vhost文件映射
- /data/www/logs:/etc/nginx/logs #日志目录映射
迁移步骤:
1.需要先在目标服务器建立目录
mkdir -p /data/mysql
mkdir -p /data/www/build
mkdir -p /data/config
mkdir -p /data/www/logs
2.数据迁移到目标服务器
#配置文件拷贝
cp /etc/my.cnf /data/config
cp typecho.conf /data/config
#网站数据拷贝
cp -r $webdata/* /data/www/build/ ##$webdata指网站数据目录
#数据库拷贝
cp -r $db_data/* /data/mysql/ #da_data指数据库目录
3.确保数据库权限允许远程访问连接
grant all privileges on *.* to root@'%' identified by 'password';
flush privileges;
4.执行docker-compose命令
[root@localhost web-db_docker]# docker-compose up #前台执行
Starting web-db_docker_db_1 ... done
Recreating web-db_docker_nginx-php-fpm_1 ... done
Attaching to web-db_docker_db_1, web-db_docker_nginx-php-fpm_1
db_1 | 180628 2:27:55 [Warning] options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set
db_1 | 180628 2:27:55 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
db_1 | 180628 2:27:55 [Note] mysqld (mysqld 5.5.60) starting as process 1 ...
db_1 | 180628 2:27:55 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 180628 2:27:55 InnoDB: The InnoDB memory heap is disabled
db_1 | 180628 2:27:55 InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 180628 2:27:55 InnoDB: Compressed tables use zlib 1.2.3
db_1 | 180628 2:27:55 InnoDB: Using Linux native AIO
db_1 | 180628 2:27:55 InnoDB: Initializing buffer pool, size = 128.0M
db_1 | 180628 2:27:55 InnoDB: Completed initialization of buffer pool
db_1 | 180628 2:27:55 InnoDB: highest supported file format is Barracuda.
db_1 | 180628 2:27:55 InnoDB: Waiting for the background threads to start
db_1 | 180628 2:27:56 InnoDB: 5.5.60 started; log sequence number password
db_1 | 180628 2:27:56 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
db_1 | 180628 2:27:56 [Note] - '0.0.0.0' resolves to '0.0.0.0';
db_1 | 180628 2:27:56 [Note] Server socket created on IP: '0.0.0.0'.
db_1 | 180628 2:27:56 [Note] Event Scheduler: Loaded 0 events
db_1 | 180628 2:27:56 [Note] mysqld: ready for connections.
db_1 | Version: '5.5.60' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
nginx-php-fpm_1 | 2018-06-28 02:27:56,994 CRIT Set uid to user 0
nginx-php-fpm_1 | 2018-06-28 02:27:56,994 WARN No file matches via include "/etc/supervisor/conf.d/*.conf"
nginx-php-fpm_1 | 2018-06-28 02:27:57,026 INFO RPC interface 'supervisor' initialized
nginx-php-fpm_1 | 2018-06-28 02:27:57,026 CRIT Server 'unix_http_server' running without any HTTP authentication checking
nginx-php-fpm_1 | 2018-06-28 02:27:57,026 INFO supervisord started with pid 1
nginx-php-fpm_1 | 2018-06-28 02:27:58,030 INFO spawned: 'php-fpm' with pid 15
nginx-php-fpm_1 | 2018-06-28 02:27:58,032 INFO spawned: 'nginx' with pid 16
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: using the "epoll" event method
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: nginx/1.14.0
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: built by gcc 6.4.0 (Alpine 6.4.0)
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: OS: Linux 3.10.0-862.3.3.el7.x86_64
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: getrlimit(RLIMIT_NOFILE): 65536:65536
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: start worker processes
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: start worker process 17
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: start worker process 18
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: start worker process 19
nginx-php-fpm_1 | 2018/06/28 02:27:58 [notice] 16#16: start worker process 20
nginx-php-fpm_1 | 2018-06-28 02:27:59,142 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
nginx-php-fpm_1 | 2018-06-28 02:27:59,142 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
docker-compose up -d ####线上我们直接放后台执行
至此结束。
本文由 Mr Gu 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 28, 2018 at 10:51 am