集群LNMP组件分离

  1. 将LNMP一体机的数据库分离成独立的数据库
  1. 创建独立的数据库(db01-51数据库)

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz

tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz

mkdir -p /application

mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49

ln -s /application/mysql-5.5.49 /application/mysql

useradd -s /sbin/nologin mysql -M

chown -R mysql.mysql /application/mysql/data/

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

chmod +x /etc/init.d/mysqld

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

/etc/init.d/mysqld start

netstat -lntup|grep mysql

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

mysql

b.导出lnmp中的wordpress数据库数据(web01服务器)

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

c.导入到51的数据库中(web01服务器)

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

d.解压并导入(db01服务器)

gzip -d bak.sql.gz

mysqladmin -uroot password ceshi123  #创建用户和密码

mysql -uroot -pceshi123 </tmp/bak.sql  #导入数据库

mysql -uroot -pceshi123 -e "show databases like 'wordpress';"  #查看数据库内容

mysql -uroot -pceshi123 -e "use wordpress;show tables;"  #查看数据库是否有表

grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';  #创建库管理员

flush privileges;  #重新加载

select user,host from mysql.user;

e.更改.8服务器的配置文件

vim /application/nginx/html/blog/wp-config.php

/** MySQL主机 */

define('DB_HOST', '172.16.1.51');  #只修改主机名为51服务器的ip

f.关闭.8服务器的本地数据库

/etc/init.d/mysqld stop

chkconfig mysqld off

g.查看数据库的记录

select * from old_posts\G;

服务器的具体操作过程:

web01服务器的所有操作:

[root@web01 ~]# mysqldump -uroot -p123456 wordpress -B |gzip>bak.sql.gz

[root@web01 ~]# scp bak.sql.gz root@10.0.0.51:/tmp

root@10.0.0.51's password:

bak.sql.gz              100%  130KB 130.2KB/s   00:00    

[root@web01 ~]# /etc/init.d/mysqld stop

Shutting down MySQL.. SUCCESS!

[root@web01 ~]# chkconfig mysqld off

[root@web01 ~]# cd /application/nginx/html/blog/

[root@web01 blog]# vim wp-config.php

/** MySQL主机 */

define('DB_HOST', '172.16.1.51');

 

db01服务器的所有操作:

[root@db01 ~]# cd /tmp/

[root@db01 tmp]# ls

bak.sql.gz  mysql.sock

[root@db01 tmp]# gzip -d bak.sql.gz

[root@db01 tmp]# ls

bak.sql  mysql.sock

[root@db01 tmp]# mysqladmin -uroot password ceshi123

[root@db01 tmp]# mysql -uroot -pceshi123 </tmp/bak.sql

[root@db01 tmp]# mysql -uroot -pceshi123 -e "show databases like 'wordpress';"

+----------------------+

| Database (wordpress) |

+----------------------+

| wordpress            |

+----------------------+

[root@db01 tmp]# mysql -uroot -pceshi123 -e "use wordpress;show tables;"

+------------------------+

| Tables_in_wordpress    |

+------------------------+

| old_commentmeta        |

| old_comments           |

| old_links              |

| old_options            |

| old_postmeta           |

| old_posts              |

| old_term_relationships |

| old_term_taxonomy      |

| old_termmeta           |

| old_terms              |

| old_usermeta           |

| old_users              |

+------------------------+

mysql> grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;  

+-----------+------------+

| user      | host       |

+-----------+------------+

| root      | 127.0.0.1  |

| wordpress | 172.16.1.% |

| root      | ::1        |

|           | centos     |

| root      | centos     |

|           | localhost  |

| root      | localhost  |

+-----------+------------+

7 rows in set (0.00 sec)

 

mysql> use wordpress;

Database changed

mysql> show tables

    -> ;

+------------------------+

| Tables_in_wordpress    |

+------------------------+

| old_commentmeta        |

| old_comments           |

| old_links              |

| old_options            |

| old_postmeta           |

| old_posts              |

| old_term_relationships |

| old_term_taxonomy      |

| old_termmeta           |

| old_terms              |

| old_usermeta           |

| old_users              |

+------------------------+

12 rows in set (0.00 sec)

 

mysql> select * from old_posts\G;

*************************** 1. row ***************************

                   ID: 1

          post_author: 1

            post_date: 2018-07-11 22:22:32

        post_date_gmt: 2018-07-11 14:22:32

         post_content: 欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!

           post_title: 世界,您好!

         post_excerpt:

          post_status: publish

       comment_status: open

          ping_status: open

        post_password:

            post_name: hello-world

              to_ping:

               pinged:

        post_modified: 2018-07-11 22:22:32

    post_modified_gmt: 2018-07-11 14:22:32

post_content_filtered:

          post_parent: 0

                 guid: http://blog.etiantian.org/?p=1

           menu_order: 0

            post_type: post

       post_mime_type:

        comment_count:

2、将blog的资源文件迁移的NFS服务器上

[root@web01 ~]# cd /application/nginx/html/blog/

[root@web01 blog]# tree wp-content/uploads/

wp-content/uploads/

└── 2018

    └── 07

        ├── timg-6-1024x640.jpg

        ├── timg-6-1200x750.jpg

        ├── timg-6-150x150.jpg

        ├── timg-6-300x188.jpg

        ├── timg-6-768x480.jpg

        └── timg-6.jpg

 

2 directories, 6 files

资源目录为:wp-content/uploads/

 

 

在nfs01服务器上创建和web01服务器相同的用户

[root@web01 blog]# id www  #查看web01服务器的用户www

uid=890(www) gid=890(www) 组=890(www)

 

[root@nfs01 ~]# useradd -u 890 www  #nfs01服务器创建相同id号的www用户          

[root@nfs01 ~]# id www

uid=890(www) gid=890(www) 组=890(www)

[root@nfs01 ~]# vi /etc/exports

/data 172.16.1.0/24(rw,sync,all_squash,anonuid=890,anongid=890)

 

[root@web01 blog]# showmount -e 172.16.1.31  #显示NFS服务器上所有的共享目录

Export list for 172.16.1.31:

/data1 172.16.1.0/24

/data  172.16.1.0/24

[root@web01 blog]# rpm -qa rpcbind nfs-utils  #查看安装包

nfs-utils-1.2.3-75.el6_9.x86_64

rpcbind-0.2.0-13.el6_9.1.x86_64

[root@web01 blog]# /etc/init.d/rpcbind status

rpcbind (pid  985) 正在运行...

[root@web01 blog]# vi /etc/rc.local

/etc/init.d/rpcbind start  #添加的内容

[root@web01 blog]# cd wp-content/uploads/

[root@web01 uploads]# mv 2018 /tmp/

 

[root@nfs01 ~]# mkdir /data/nfs-blog   #nfs01服务器创建目录

[root@nfs01 ~]# chown -R www.www /data   #授权所有者和所属组

 

[root@web01 wp-content]# mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/  #web01挂载

[root@web01 wp-content]# df -h  #查看挂载

[root@web01 wp-content]# which mount

[root@web01 wp-content]# vi /etc/rc.local

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

[root@web01 uploads]# cp -a /tmp/2018/ .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值