安装PHP以及搭建博客(三)服务迁移分离

LNMP服务环境都在一台机器上(IP:125),现在要做到把mysql服务迁移出来(IP:129),把图片文件迁移到NFS服务器上(IP:130)

mysql服务器(129)

安装mysql配置过程(下载略)

 

useradd mysql -s /sbin/nologin -M

mkdir -p /application

tar xf mysql-5.5.59-linux-glibc2.12-x86_64.tar.gz 

mv mysql-5.5.59-linux-glibc2.12-x86_64 /application/mysql-5.5.59

ln -s /application/mysql-5.5.59/ /application/mysql 

chown -R mysql.mysql /application/mysql

cd /application/mysql

 ./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/

 cp ./support-files/my-small.cnf /etc/my.cnf 

cp support-files/mysql.server /etc/init.d/mysqld

sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/my.cnf /etc/init.d/mysqld /application/mysql/bin/mysqld_safe

/etc/init.d/mysqld start

lsof -i:3306

cp -a /application/mysql/bin/* /usr/local/sbin/

mysqladmin -uroot password 123456

 

LNMP环境导出mysql中的数据(IP:125)

mysqldump -uroot -p123456 -B wordpress |gzip>bak.sql.gz

scp bak.sql.gz root@192.168.70.129:/tmp

 

导入到mysql服务器中(129)

gzip -d bak.sql.gz 

mysql -uroot -p123456 </tmp/bak.sql 

 

登录数据库查看

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)

数据库授让LNMP可以访问

grant all on wordpress.* to wordpress@'192.168.70.%' identified by '123456';

flush privileges;

 

 

停掉LNMP中的数据库(125)

/etc/init.d/mysqld stop

 

 

修改wordpress 文件(125)

cd /application/nginx/html/blog/

vim wp-config.php

/** MySQL主机 */
define('DB_HOST', '192.168.70.129');

 

 

这就可以访问了

blog.daxian.com

 

测试blog中的mysql

发表一篇博文

查看129的数据库

 

select * from daxian_posts\G  

*************************** 8. row ***************************
ID: 8
post_author: 1
post_date: 2018-02-07 16:00:38
post_date_gmt: 0000-00-00 00:00:00
post_content: 
post_title: 123456daxian

 

 

成功

==========================图片分离到NFS=================

图片位置在于

tree /application/nginx/html/blog/wp-content/uploads/
wp-content/uploads/
└── 2018
└── 02
├── m2w500hq85lt_x_large_EQqD_500c000026851262-100x100.jpg
├── m2w500hq85lt_x_large_EQqD_500c000026851262-150x150.jpg
├── m2w500hq85lt_x_large_EQqD_500c000026851262-300x194.jpg
├── m2w500hq85lt_x_large_EQqD_500c000026851262.jpg
├── m2w500hq85lt_x_large_vIqg_741d00001d1f1262-100x100.jpg
├── m2w500hq85lt_x_large_vIqg_741d00001d1f1262-150x150.jpg
├── m2w500hq85lt_x_large_vIqg_741d00001d1f1262-300x216.jpg
└── m2w500hq85lt_x_large_vIqg_741d00001d1f1262.jpg

 

在NFS服务器上创建用户

useradd -u 506 www  (查看125上www用户uid是多少)

 

 

安装NFS(客户端跟服务端都要安装))

yum install nfs-utils rpcbind -y

NFS上启动

/etc/init.d/rpcbind start

/etc/init.d/nfs start

rpcinfo -p localhost
mkdir /data/blog -p
chown -R www.www /data
vim /etc/exports

/data 192.168.70.0/24(rw,sync,all_squash,anonuid=506,anongid=506)

重启NFS

/etc/init.d/nfs reload
showmount -e 192.168.70.130

客户端启动(125)

/etc/init.d/rpcbind start

showmount -e 192.168.70.130
Export list for 192.168.70.130:
/data 192.168.70.0/24

将原有数据移动走(125

cd /application/nginx/html/blog/wp-content/uploads

mv 2018 /tmp

 

挂载

 mount -t nfs 192.168.70.130:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/

 

将数据移动回来

cp -a /tmp/2018/ .

 

完成MYSQL分离以及图片分离

 

可以再NFS上查看了

pwd
/data/nfs-blog/2018/02

ls
m2w500hq85lt_x_large_EQqD_500c000026851262-100x100.jpg
m2w500hq85lt_x_large_EQqD_500c000026851262-150x150.jpg
m2w500hq85lt_x_large_EQqD_500c000026851262-300x194.jpg
m2w500hq85lt_x_large_EQqD_500c000026851262.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-100x100.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-1-100x100.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-1-150x150.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-1-300x216.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-150x150.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-1.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262-300x216.jpg
m2w500hq85lt_x_large_vIqg_741d00001d1f1262.jpg

 

 

posted @ 2018-02-07 17:00  大仙儿没溜儿  阅读(154)  评论(0编辑  收藏  举报