码迷,mamicode.com
首页 > 数据库 > 详细

0537-实战将lnmp服务中的数据库独立分离到服务器

时间:2017-08-28 00:50:09      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:linux

前面安装的nginx和php,mysqld的服务要加入开机自启动,加入方法如下:

    vi /etc/rc.local添加如下内容为开机自启动

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

    追加到/etc/rc.local文件最后面

####
/application/nginx/sbin/nginx
/application/php/sbin/php-fpm
/etc/init.d/mysqld start

备份所有库(不需要备份所有库只需要备份wordpress库即可)
[root@web01 ~]# mysqldump -uroot -p123456 -A -B |gzip>bak.sql.gz
-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
备份wordpress库
[root@web01 ~]# cd /home/oldboy/tools
[root@web01 tools]# mysqldump -uroot -p123456 wordpress -B |gzip>bak.sql.gz
50台规模集群LNMP组件分离
1、LNMP一体机的数据库分离成独立的数据库
  a.创建独立的数据库51
  b.导出lnmp中的wordpress数据库数据
    mysqldump -uroot -p123456 wordpress -B |gzip>bak.sql.gz
  c.导入到51数据库里
    scp bak.sql.gz root@10.0.0.51:/tmp

[root@db01 mysql]# cd /tmp
[root@db01 tmp]# ll
总用量 160
-rw-r--r-- 1 root  root  159841 8月  27 15:40 bak.sql.gz
srwxrwxrwx 1 mysql mysql      0 8月  27 15:30 mysql.sock
[root@db01 tmp]# gzip -d bak.sql.gz
[root@db01 tmp]# ll
总用量 660
-rw-r--r-- 1 root  root  673182 8月  27 15:40 bak.sql
srwxrwxrwx 1 mysql mysql      0 8月  27 15:30 mysql.sock
给数据库设置密码
[root@db01 tmp]# mysqladmin -uroot password 123456
导入到数据库
[root@db01 tmp]# mysql -uroot -p123456 </tmp/bak.sql
查看数据库
[root@db01 tmp]# mysql -uroot -p123456 -e "show databases like ‘wordpress‘;"
+----------------------+
| Database (wordpress) |
+----------------------+
| wordpress            |
+----------------------+
进入wordpress数据库看是否有表
[root@db01 tmp]# mysql -uroot -p123456 -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              |
+------------------------+
如上操作还不能分离,因为51数据库没有管理员,管理员所在的库在mysql里面,所以要添加一个管理员
创建数据库wordpress管理员账号和密码
mysql> grant all on wordpress.* to wordpress@‘172.16.1.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.03 sec)
刷新特权
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
查看mysql数据所有的用户
mysql> select user,host from mysql.user;
+-----------+------------+
| user      | host       |
+-----------+------------+
| root      | 127.0.0.1  |
| wordpress | 172.16.1.% |
| root      | ::1        |
|           | db01       |
| root      | db01       |
|           | localhost  |
| root      | localhost  |
+-----------+------------+
7 rows in set (0.00 sec)
51上进行数据库授权,让.8web可以访问

停掉web01里面的数据库
[root@web01 tools]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
开机mysql开机启动也停掉
[root@web01 tools]# chkconfig mysqld off

再次浏览器中刷新http://blog.etiantian.org/会提示建立数据库连接时出错

在web01上面操作
[root@web01 tools]# cd /application/nginx/html/blog/
[root@web01 blog]# vim wp-config.php在32行中localhost修改为172.16.1.51
 31 /** MySQL主机 */
 32 define(‘DB_HOST‘, ‘localhost‘);
再次在浏览器中刷新http://blog.etiantian.org/ 网址就可以打开了blog了
新建一篇文章标题为666

在51数据库查询
[root@db01 tmp]# mysql -uroot -p123456
mysql> use wordpress;
mysql> show tables;
如下操作就可以查看666标题的文章
select * from old_posts\G;

如下是666标题的文章

*************************** 11. row ***************************
                   ID: 11
          post_author: 1
            post_date: 2017-08-27 16:15:28
        post_date_gmt: 2017-08-27 08:15:28
         post_content: 666
           post_title: 666
         post_excerpt: 
          post_status: inherit
       comment_status: closed
          ping_status: closed
        post_password: 
            post_name: 10-revision-v1
              to_ping: 
               pinged: 
        post_modified: 2017-08-27 16:15:28
    post_modified_gmt: 2017-08-27 08:15:28
post_content_filtered: 
          post_parent: 10
                 guid: http://blog.etiantian.org/?p=11
           menu_order: 0
            post_type: revision
       post_mime_type: 
        comment_count: 0
11 rows in set (0.00 sec)


本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1959725

0537-实战将lnmp服务中的数据库独立分离到服务器

标签:linux

原文地址:http://sandshell.blog.51cto.com/9055959/1959725

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!