当前位置: 首页 > news >正文

wordpress如何导航网站电脑培训网上免费课程

wordpress如何导航网站,电脑培训网上免费课程,天河网站 建设seo信科分公司,自己搭建小型服务器文章目录 1、准备主服务器2、准备从服务器3、主库配置3.1、创建MySQL主服务器配置文件: 4、从库配置5、搭建主从&测试5.1、使用命令行登录MySQL主服务器5.2、主机中查询master状态:5.3、从机中查询slave状态:5.4、主机中创建slave用户&am…

文章目录

  • 1、准备主服务器
  • 2、准备从服务器
  • 3、主库配置
    • 3.1、创建MySQL主服务器配置文件:
  • 4、从库配置
  • 5、搭建主从&测试
    • 5.1、使用命令行登录MySQL主服务器
    • 5.2、主机中查询master状态:
    • 5.3、从机中查询slave状态:
    • 5.4、主机中创建slave用户:
    • 5.5、在从机上配置主从关系:
    • 5.6、启动从库的io和sql线程:都启动成功主从才搭建成功
  • 6、在3306主机上创建mydb1
  • 7、在3306主机上创建mydb2
  • 8、在3306主机上创建mydb3
  • 9、在3306主机上创建mydb4

mysql集群:
单台设备的负载压力:主从复制
集群:分摊访问压力和存储压力
需求:使用 3306 mysql当作主, 3316 mysql 当作从,在3306中对 mydb2/mydb3 数据库所有的操作,希望能够主从复制同步到3316,其他的数据库操作不同步。

1、准备主服务器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                       COMMAND                   CREATED        STATUS      PORTS                                                                                  
ab66508d9441   mysql:8                     "docker-entrypoint.s…"   8 months ago   Up 9 days   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                   spzx-mysql

此时我已经有一个主服务器 spzx-mysql

2、准备从服务器

docker run -d \
-p 3316:3306 \
-v mysql-slave1-conf:/etc/mysql/conf.d \
-v mysql-slave1-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
--name atguigu-mysql-slave1 \
mysql:8
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                       COMMAND                   CREATED          STATUS         PORTS                                                                                  NAMES
c236f876ae40   mysql:8                     "docker-entrypoint.s…"   10 seconds ago   Up 3 seconds   33060/tcp, 0.0.0.0:3316->3306/tcp, :::3316->3306/tcp                                   atguigu-mysql-slave1
ab66508d9441   mysql:8                     "docker-entrypoint.s…"   8 months ago     Up 9 days      0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                   spzx-mysql

3、主库配置

  1. 先在主mysql中配置 记录mydb2/mydb3库的操作日志到binlog日志文件中
    – 主库写操作会按照配置记录到二进制文件中(binlog)
    – 主库需要创建一个从账户并分配可以读取binlog日志的权限
  2. 在从mysql中配置中继日志文件,用来保存读取到的mysql主的 binlog 日志
    – 从库可以开启主从复制,从指定的主库的binlog文件中加载日志缓存到自己的relaylog文件中,最后通过一个sql线程将relaylog文件中的日志replay到自己的库表中
    – 从库需要使用主库提供的账号和主库的binlog文件建立连接

3.1、创建MySQL主服务器配置文件:

[root@localhost ~]# docker inspect spzx-mysql 
        "Mounts": [{"Type": "volume","Name": "mysql_conf","Source": "/var/lib/docker/volumes/mysql_conf/_data","Destination": "/etc/mysql","Driver": "local","Mode": "z","RW": true,"Propagation": ""},{"Type": "volume","Name": "mysql_data","Source": "/var/lib/docker/volumes/mysql_data/_data","Destination": "/var/lib/mysql","Driver": "local","Mode": "z","RW": true,"Propagation": ""}],
[root@localhost _data]# cd /var/lib/docker/volumes/mysql_conf/_data
[root@localhost _data]# ll
总用量 8
drwxrwxr-x. 2 root root   41 1226 2023 conf.d
-rw-rw-r--. 1 root root 1080 1221 2021 my.cnf
-rw-r--r--. 1 root root 1448 928 2021 my.cnf.fallback
[root@localhost _data]# vim my.cnf

配置如下内容:

[mysqld]
# 服务器唯一id,默认值1
server-id=1
# 设置日志格式,默认值ROW。row(记录行数据)  statement(记录sql)  mixed(混合模式)
binlog_format=STATEMENT
# 二进制日志名,默认binlog
# log-bin=binlog
log-bin=spzxbinlog
# 设置需要复制的数据库,默认复制全部数据库
binlog-do-db=mydb2
binlog-do-db=mydb3
# 设置不需要复制的数据库
binlog-ignore-db=mydb4
#binlog-ignore-db=infomation_schema

在这里插入图片描述

[root@localhost _data]# docker restart spzx-mysql
spzx-mysql
[root@localhost _data]# ll ../../mysql_data/_data/

在这里插入图片描述

4、从库配置

[root@localhost _data]# docker inspect atguigu-mysql-slave1 

在这里插入图片描述

vim /var/lib/docker/volumes/mysql-slave1-conf/_data/my.cnf

配置如下内容:

[mysqld]
# 服务器唯一id,每台服务器的id必须不同,如果配置其他从机,注意修改id
server-id=2
# 中继日志名,默认xxxxxxxxxxxx-relay-bin
#relay-log=relay-bin

在这里插入图片描述

[root@localhost _data]# docker restart atguigu-mysql-slave1 
atguigu-mysql-slave1

5、搭建主从&测试

5.1、使用命令行登录MySQL主服务器

[root@localhost _data]# docker exec -it spzx-mysql /bin/bash
root@ab66508d9441:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

5.2、主机中查询master状态:

mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| spzxbinlog.000001 |      156 | mydb2,mydb3  | mydb4            |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)

5.3、从机中查询slave状态:

[root@localhost ~]# docker exec -it atguigu-mysql-slave1 /bin/bash
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@c236f876ae40:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 
mysql> show slave status;
Empty set, 1 warning (0.02 sec)

从库必须和主库主动建立连接 开启自己的sql和io线程

5.4、主机中创建slave用户:

-- 创建slave用户
CREATE USER 'atguigu_slave'@'%';
-- 设置密码
ALTER USER 'atguigu_slave'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
-- 授予复制权限
GRANT REPLICATION SLAVE ON *.* TO 'atguigu_slave'@'%';
-- 刷新权限
FLUSH PRIVILEGES;
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| spzxbinlog.000001 |     1074 | mydb2,mydb3  | mydb4            |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

5.5、在从机上配置主从关系:

CHANGE MASTER TO MASTER_HOST='192.168.74.148', 
MASTER_USER='atguigu_slave',MASTER_PASSWORD='123456', MASTER_PORT=3306,
MASTER_LOG_FILE='spzxbinlog.000001',MASTER_LOG_POS=1074; 
mysql> CHANGE MASTER TO MASTER_HOST='192.168.74.148', -> MASTER_USER='atguigu_slave',MASTER_PASSWORD='123456', MASTER_PORT=3306,-> MASTER_LOG_FILE='spzxbinlog.000001',MASTER_LOG_POS=1074; 
Query OK, 0 rows affected, 9 warnings (0.05 sec)
mysql> show slave status;
+----------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+-------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
| Slave_IO_State | Master_Host    | Master_User   | Master_Port | Connect_Retry | Master_Log_File   | Read_Master_Log_Pos | Relay_Log_File                | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File        | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version | Master_public_key_path | Get_master_public_key | Network_Namespace |
+----------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+-------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
|                | 192.168.74.148 | atguigu_slave |        3306 |            60 | spzxbinlog.000001 |                1074 | c236f876ae40-relay-bin.000001 |             4 | spzxbinlog.000001     | No               | No                |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                1074 |             156 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                  NULL | No                            |             0 |               |              0 |                |                             |                0 |             | mysql.slave_master_info |         0 |                NULL |                         |              86400 |             |                         |                          |                |                    |                    |                   |             0 |                      |              |                    |                        |                     0 |                   |
+----------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+-------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
1 row in set, 1 warning (0.00 sec)

在这里插入图片描述

5.6、启动从库的io和sql线程:都启动成功主从才搭建成功

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> show slave status;
+----------------------------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+----------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
| Slave_IO_State                   | Master_Host    | Master_User   | Master_Port | Connect_Retry | Master_Log_File   | Read_Master_Log_Pos | Relay_Log_File                | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID                          | Master_Info_File        | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State                                  | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version | Master_public_key_path | Get_master_public_key | Network_Namespace |
+----------------------------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+----------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
| Waiting for source to send event | 192.168.74.148 | atguigu_slave |        3306 |            60 | spzxbinlog.000001 |                1074 | c236f876ae40-relay-bin.000002 |           325 | spzxbinlog.000001     | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                1074 |             541 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |                1 | af98f4d4-a3ca-11ee-b194-0242ac110002 | mysql.slave_master_info |         0 |                NULL | Replica has read all relay log; waiting for more updates |              86400 |             |                         |                          |                |                    |                    |                   |             0 |                      |              |                    |                        |                     0 |                   |
+----------------------------------+----------------+---------------+-------------+---------------+-------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+----------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+-------------------+
1 row in set, 1 warning (0.01 sec)

在这里插入图片描述

6、在3306主机上创建mydb1

在这里插入图片描述
在这里插入图片描述
此时刷新3316从数据库,发现没有mydb1

7、在3306主机上创建mydb2

在这里插入图片描述
此时刷新3316从数据库,发现从机复制了主机中的mydb2数据库到从机中

8、在3306主机上创建mydb3

在这里插入图片描述

9、在3306主机上创建mydb4

在这里插入图片描述

http://www.15wanjia.com/news/30530.html

相关文章:

  • hyip系统网站开发百度云引擎搜索
  • 企业网站的内容营销站长seo综合查询
  • 在国外网站上买机票怎样做财务迅雷磁力链bt磁力天堂
  • 江苏网站建设网络推广人工智能培训机构哪个好
  • 邢台网站制作哪家强淘宝优化
  • 佛山网站建设哪个好点seo建站优化推广
  • dw对网站建设有哪些作用站群优化公司
  • wordpress 子主题目录优化大师下载旧版本安装
  • 什么公司做网站出名微信营销管理软件
  • p2p网站策划怎么做个人网页
  • 16岁0元开网店赚钱软件常用的seo工具的是有哪些
  • 外贸网站制作时间及费用网店代运营公司哪家好
  • 微信菜单栏那些网站怎么做最好的bt磁力搜索引擎
  • 南宁最高端网站建设新手小白怎么学做运营
  • 郑州建网站的公司2023年度最火关键词
  • 有没有专门做av字幕的网站百度网盘在线登录
  • 好用的网站链接国内做seo最好的公司
  • 曲周专业做网站google手机官网
  • 建设网站需申请什么资料北京网络推广
  • 小说主角重生之后做网站外贸营销策略都有哪些
  • 南阳企业网站建设汕头seo外包机构
  • webstation做网站上海网站推广服务公司
  • 手机网站如何生成app百度推广怎么登陆
  • 北京网站建设著名公司文大侠seo
  • 武汉网页设计课程seo营销推广服务公司
  • 阿里云如何注册域名上海网站seo诊断
  • 企业网站产品优化怎么做宁波seo网络推广主要作用
  • 定制软件开发公司北京优化seo排名
  • 企业网站建设英文网站外链购买平台
  • 哈尔滨模板建站新报价百度问问首页