集团公司已经在oracle方向有成熟的几十套环境,但是为了节约成本,要尝试下mysql下面先用两台linux x86 Red Hat Enterprise Linux Server release 5.4 (Tikanga) 和linux6.3 安装测试下性能。
环境:
节点1:192.168.6.235
节点2:192.168.6.79
【配置第一个节点235】
4.从新修改登录限制
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.15 MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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> 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> select host, user from user; +-----------------------+------+ | host | user | +-----------------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | root | | localhost.localdomain | root | +-----------------------+------+ mysql> update user set host = '%' where user = 'root'; ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' -- 这个无所谓 mysql> select host, user from user; +-----------------------+------+ | host | user | +-----------------------+------+ | % | root | | 127.0.0.1 | root | | ::1 | root | | localhost.localdomain | root | +-----------------------+------+ 4 rows in set (0.00 sec) mysql> FLUSH PRIVILEGES -> ; Query OK, 0 rows affected (0.00 sec) mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.15 | +-----------+ 1 row in set (0.00 sec)
【配置第2个节点79】
以同样的方式配置6.79
步骤同上 (省略)
【主从配置】
先以79作为主数据库,235作从数据库
看看79的/etc/my.cnf
[root@localhost ~]# more /etc/my.cnf # Example MySQL config file for medium systems. # # This is for a system with little memory (32M - 64M) where MySQL plays # an important part, or systems up to 128M where MySQL is used together with # other programs (such as a web server) # # MySQL programs look for option files in a set of # locations which depend on the deployment platform. # You can copy this option file to one of those # locations. For information about these locations, see: # http://dev.mysql.com/doc/mysql/en/option-files.html # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M lower_case_table_names=1 #忽略大小写 # binary logging format - mixed recommended binlog_format=mixed # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id = 1 #第一个节点 binlog-do-db =roamingsms_v1 #主库(要同步的数据库) replicate-do-db = roamingsms_v1 #从库 binlog-ignore-db=mysql #忽略的数据库 binlog-ignore-db=test #忽略的数据库 log-bin=mysql-bin # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /usr/local/mysql/var #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /usr/local/mysql/var # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
看看235的/etc/my.cnf
[root@localhost ~]# more /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
lower_case_table_names=1 # 大小写忽略
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 2 #节点2,每个节点只要不一样就行,不一定是2 replicate-do-db = roamingsms_v1 #从库(同步的数据库) log-bin = mysql-bin #同步的日志
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
在主库79重启mysql
#service mysqld restart #重启mysql
登陆Mysql
mysql> grant replication slave,reload,super on *.* to'sync'@'%' identified by 'mengliang'; #分配一个用户用于同步
mysql> flush privileges; #权限生效
mysql> show master status;
+------------------+----------+---------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+---------------+------------------+-------------------+
| mysql-bin.000046 | 120 | roamingsms_v1 | mysql,test | |
+------------------+----------+---------------+------------------+-------------------+
1 row in set (0.00 sec)
在从库235
mysql> flush logs;
mysql>stop slave;
mysql>reset slave;
mysql>change master to master_host='192.168.6.79',master_user='sync',master_password='broadtech',master_log_file='mysql-bin.000046',master_log_pos=120;
mysql> flush privileges;
mysql> show slave status\G; #查看状态
主从配置成功。
【主从配置】
先以235作为主数据库,79作从数据库
在235
#service mysqld restart #重启mysql
登陆Mysql
mysql> grant replication slave,reload,super on *.* to'sync'@'%' identified by 'mengliang'; #分配一个用户用于同步
mysql> flush privileges; #权限生效
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 725 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
然后再79配置
mysql> flush logs;
mysql>stop slave;
mysql>reset slave;
mysql>change master to master_host='192.168.6.79',master_user='sync',master_password='broadtech',master_log_file='mysql-bin.000007',master_log_pos=725;
mysql> flush privileges;
mysql> show slave status\G; #查看状态
从主配置完成
双机MM完成。
【高可用配置】
1.利用keepalived构建高可用MySQL-HA,保证两台MySQL数据的一致性,然后用keepalived实现虚拟VIP,通过keepalived自带的服务监控功能来实现MySQL故障时自动切换实现failover (下面详细实施步骤)
2.mmm模式 (以后慢慢介绍...)
3.mha模式(以后慢慢介绍...)
4.cluster模式(以后慢慢介绍...)
先在79上配置
安装keepalived
# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz
# yum -y install gcc gcc-c++ openssl-devel
# tar xf keepalived-1.2.2.tar.gz
# cd keepalived-1.2.2
# ./configure --prefix=/usr/local/keepalived
# make && make install
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# mkdir /etc/keepalived
keepalived实现虚拟IP,通过keepalived自带的服务监控功能来实现MySQL故障时自动切换;
[root@localhost keepalived]# vi /usr/local/keepalived/etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id mysql-ha } vrrp_instance VI_1 { ! Configuration File for keepalived global_defs { router_id mysql-ha } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 79 priority 100 advert_int 1 nopreempt authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.6.82 } } virtual_server 192.168.6.82 3306 { delay_loop 2 lb_algo rr lb_kind DR persistence_timeout 60 protocol TCP real_server 192.168.6.79 3306 { weight 1 notify_down /usr/local/keepalived/etc/keepalived/mysql.sh TCP_CHECK { connect_port 3306 connect_timeout 3 nb_get_retry 2 delay_before_retry 1 } } }
先在235上配置
重复79的操作。
Keepalived双主高可用配置已经配置好了,可以测试。