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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

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

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

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

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

1
2
3
4
####
/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标题的文章

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************** 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博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1959725如需转载请自行联系原作者

sandshell
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
24天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
27 0
|
23天前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
34 2
|
17天前
|
关系型数据库 MySQL 数据库
卸载云服务器上的 MySQL 数据库
卸载云服务器上的 MySQL 数据库
33 0
|
12天前
|
关系型数据库 MySQL 数据库连接
Django(四):Django项目部署数据库及服务器配置详解(MySQL)
Django(四):Django项目部署数据库及服务器配置详解(MySQL)
38 11
|
21天前
|
存储 缓存 NoSQL
Redis 服务器指南:高性能内存数据库的完整使用指南
Redis 服务器指南:高性能内存数据库的完整使用指南
|
22天前
|
弹性计算 关系型数据库 MySQL
阿里云数据库服务器价格表,数据库创建、连接和使用教程
阿里云数据库使用流程包括购买和管理。选择所需数据库类型如MySQL,完成实名认证后购买,配置CPU、内存和存储。确保数据库地域与ECS相同以允许内网连接。创建数据库和账号,设置权限。通过DMS登录数据库,使用账号密码连接。同一VPC内的ECS需添加至白名单以进行内网通信。参考官方文档进行详细操作。
125 3
|
28天前
|
SQL 关系型数据库 数据库
OceanBase数据库常见问题之OAT添加服务器预检查的时候报错如何解决
OceanBase 是一款由阿里巴巴集团研发的企业级分布式关系型数据库,它具有高可用、高性能、可水平扩展等特点。以下是OceanBase 数据库使用过程中可能遇到的一些常见问题及其解答的汇总,以帮助用户更好地理解和使用这款数据库产品。
|
1月前
|
弹性计算 分布式计算 DataWorks
DataWorks报错问题之ecs自建数据库连通性测试报错如何解决
DataWorks是阿里云提供的一站式大数据开发与管理平台,支持数据集成、数据开发、数据治理等功能;在本汇总中,我们梳理了DataWorks产品在使用过程中经常遇到的问题及解答,以助用户在数据处理和分析工作中提高效率,降低难度。
|
30天前
|
Ubuntu JavaScript 关系型数据库
在阿里云Ubuntu 20.04服务器中搭建一个 Ghost 博客
在阿里云Ubuntu 20.04服务器上部署Ghost博客的步骤包括创建新用户、安装Nginx、MySQL和Node.js 18.x。首先,通过`adduser`命令创建非root用户,然后安装Nginx和MySQL。接着,设置Node.js环境,下载Nodesource GPG密钥并安装Node.js 18.x。之后,使用`npm`安装Ghost-CLI,创建Ghost安装目录并进行安装。配置过程中需提供博客URL、数据库连接信息等。最后,测试访问前台首页和后台管理页面。确保DNS设置正确,并根据提示完成Ghost博客的配置。
在阿里云Ubuntu 20.04服务器中搭建一个 Ghost 博客
|
1月前
|
存储 弹性计算 数据可视化
要将ECS中的文件直接传输到阿里云网盘与相册(
【2月更文挑战第31天】要将ECS中的文件直接传输到阿里云网盘与相册(
419 4