MEC的Mysql主备创建过程
目录
目录
3.1.1. 给从数据库设置授权用户(创建复制账号)... 9
3.1.2. 修改主mysql配置,在my.cnf中添加一下内容... 9
3.1.5. 查看主服务器上当前的二进制日志名和偏移量值... 10
3.2.4. 建立从mysql与主mysql连接... 10
安装MEC环境时需要安装mysql主备数据库,初步接触该的同学由于不熟悉,现有文档太过简单,网上文档又比较杂乱,这些写一个Mysql主备安装文档对小白同学进行扫盲,大神绕行。
- CentOS镜像安装mysql数据库:
上传好mysql安装包,在root目录下,执行红色部分进行数据库安装,完成后获取数据库初始密码:
[[email protected] scripts]# ls
load_mec.sh mysql_install.sh sh_bak
[[email protected] scripts]# pwd
/root/mysql/scripts
[[email protected] scripts]# ./mysql_install.sh
successful, mysql user is already added!
successful, mysql.tar is already uncompress!
2020-06-23T09:56:06.776169Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-23T09:56:06.995261Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-23T09:56:07.035823Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-23T09:56:07.095571Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c201ea5c-b537-11ea-ae09-fa163e2c69d4.
2020-06-23T09:56:07.097523Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-23T09:56:07.097988Z 1 [Note] A temporary password is generated for [email protected]: rAe_i+qdw5tT
successful, mysql is already initialed!
0
successful, mysql is already started!
[[email protected] scripts]#
-
- 数据库root权限修改
登录mysql修改root密码和远程登录权限,执行以下步骤:
需要执行的命令:
/opt/mysql/mysql-5.7.24/bin/mysql -P3301 -p -S /data/mysql3301/mysql.sock
ALTER USER USER() IDENTIFIED BY '[email protected]#456';
use mysql;
update user set host='127.0.0.1' where user = 'root';
FLUSH PRIVILEGES;
操作实例:
[[email protected] scripts]# /opt/mysql/mysql-5.7.24/bin/mysql -P3301 -p -S /data/mysql3301/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> ALTER USER USER() IDENTIFIED BY '******';
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='127.0.0.1' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
-
-
- 导入MEC数据库
-
使用load_mec.sh脚本导入MEC数据库:
source scripts/load_mec.sh
导入数据库实例:
[[email protected] scripts]# source /root/mysql/scripts/load_mec.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| amsdb |
| mecs-1.0 |
| meomdb-1.0 |
| mysql |
| mysqllog |
| omsdb |
| performance_schema |
| sys |
| vm-operator |
+--------------------+
successful, mec sql is imported!
-
-
- 配置mysql登录软连接
-
找出安装目录做如下操作,进行数据库登录软连接:
[[email protected] scripts]# cd /usr/local/bin
[[email protected] bin]# ln -fs /opt/mysql/mysql-5.7.24/bin/mysql mysql
创建应用账号赋权:
mysql -uroot -p -h127.0.0.1 -P3301
GRANT ALL PRIVILEGES ON `vm-operator`.* TO 'mecs_user'@'%'identified by '******';
GRANT ALL PRIVILEGES ON `meomdb-1.0`.* TO 'mecs_user'@'%' identified by '******';
GRANT ALL PRIVILEGES ON `amsdb`.* TO 'mecs_user'@'%' identified by '******';
GRANT ALL PRIVILEGES ON `omsdb`.* TO 'mecs_user'@'%' identified by '******';
GRANT ALL PRIVILEGES ON `mecs-1.0`.* TO 'mecs_user'@'%' identified by '******';
验证应用账号:
Mysql -umecs_user -p‘密码’ -h127.0.0.1 -P3301
登录成功,则数据库安装完成。
- MySQL主从配置
MySQL01:192.168.0.184 主
MySQL02:192.168.0.63 从
grant replication slave on *.* to 'mecs_user'@'192.168.0.63' identified by '[email protected]#456';
flush privileges;
-
-
- 修改主mysql配置,在my.cnf中添加一下内容
-
server-id=1
log_bin=master_bin
log_slave_updates=true
注意:这里的my.cnf是由/opt/mysql中通拷贝来的,/opt/mysql中中的my.cnf有改动,按照“注意事项2”操作。
-
-
- 重启mysql服务
-
[[email protected] ~]# service mysqld restart
注意:如无法重启请按照“注意事项1”操作。
mysql -uroot -p -h127.0.0.1 -P3301
mysql> show master status;
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master_bin.000001 | 154 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
vi /etc/my.cnf
-------------------添加以下内容--------------------
server-id=3
relay_log=relay-log-bin
relay_log_index=slave-relay-bin.index
注意:按照“注意事项2”操作。
-
-
- 重启mysql服务
-
[[email protected] ~]# service mysqld restart
注意:如无法重启请按照“注意事项1”操作。
mysql -uroot -p -h127.0.0.1 -P3301
-
-
- 建立从mysql与主mysql连接
-
change master to master_host='192.168.0.184',master_port=3301,master_user='mecs_user',master_password='[email protected]#456',master_log_file='master_bin.000001',master_log_pos=154;
注: master_host是主节点的ip地址,master_user 和master_password主服务器创建的用于连接主服务器的帐号和密码,master_log_file和master_log_pos需要从master节点,进入Mysql数据库后进行查询.
start slave;(关闭:stop slave)
-
-
- 查询slave状态
-
show slave status \
过程:在主mysql创建一个数据库,去从数据库里面看看是否同步过去了。
主上创建数据库:
备上也备份:
mysql服务无法重启解决方法:
[[email protected] etc]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
Failed to restart mysql.service: Unit not found.
[[email protected] etc]# systemctl restart mysql
Failed to restart mysql.service: Unit not found.
[[email protected] etc]# /etc/init.d/ | grep mysql
-bash: /etc/init.d/: Is a directory
You have new mail in /var/spool/mail/root
[[email protected] etc]# find / -name mysql.server
/opt/mysql/mysql-5.7.24/support-files/mysql.server
/opt/mysql/mysql-5.7.24/mysql-5.7.24-el7-x86_64/support-files/mysql.server
[[email protected] etc]# cp /opt/mysql/mysql-5.7.24/support-files/mysql.server /etc/init.d/mysql
[[email protected] etc]#
[[email protected] etc]# service mysql start
Starting MySQL SUCCESS!
[[email protected] etc]# service mysql restart
Shutting down MySQL.... SUCCESS!
Starting MySQL.......... SUCCESS!
[[email protected] etc]#
-
- 注意事项2:my.cnf文件问题:
内存配置:
配置文件 innodb_buffer_pool 参数,要根据内存配置一下
你就配内存的 三分之二,还有其它点根据这个放开:
一个是/opt/mysql/my.cnf下文件权限问题,两个目录下都做下权限 修改:
my.cnf 权限有问题
chmod 644 my.cnf
[[email protected] mysql]# chmod 644 my.cnf
[[email protected] mysql]# cp my.cnf /etc/my.cnf
[[email protected] mysql]# cd /etc/
[[email protected] etc]# chmod 644 my.cnf
[[email protected] etc]#
[[email protected] etc]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL... SUCCESS!
https://blog.****.net/u010004734/article/details/94450563
https://www.cnblogs.com/zengpeng/p/11176171.html