Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000adb11
Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 9414655 4194304 82 Linux swap / Solaris /dev/vda3 9414656 41943039 16264192 83 Linux
[test@host-192-168-5-236 ~]$ sudo fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xf2a1312e.
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-1048575999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): Using default value 1048575999 Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
分区格式化 [test@host-192-168-5-235 /]$ sudo mkfs -t ext3 /dev/vdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 32768000 inodes, 131071744 blocks 6553587 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 4000 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000
Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
用初始化生成的root密码登录并更改密码 mysql -uroot -p set password=password("123456"); flush privileges;
配置主从 主节点(192.168.5.235) 创建同步用户 CREATE USER 'sync'@'%' IDENTIFIED WITH mysql_native_password BY 'sync@123456'; GRANT REPLICATION SLAVE ON *.* TO 'sync'@'%'; flush privileges; show master status; mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 997 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
mysql> show slave status/G 看到两个YES,代表主主成功 Slave_IO_Running: Yes Slave_SQL_Running: Yes
赋予root用户远程访问(为了远程访问root用户) GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by 'otn@2019#zy'; flush privileges;
测试: 创建数据库 create database test; 创建普通用户 CREATE USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; grant all privileges on test.* to 'test'@'%'; grant all privileges on mysql.* to 'test'@'%'; flush privileges; 查看数据库 show databases; 查看用户 select user,host from mysql.user; 创建表 create table testa( Id varchar(100)); 两边都能看到testa表 show tables; 插入语句 insert into testa values('1231'); insert into testa values('4567'); insert into testa values('5464'); 另一个数据库都能看到 select * from testa; delete from testa where Id='1231'; 另一个数据库数据显也被删除 至此,mysql主主已经完全配置成功。
[test@host-192-168-5-235 ~]$ tar -xvf keepalived-2.0.13.tar.gz cd keepalived-2.0.13 sudo ./configure --prefix=/usr/local/keepalived --安装到/usr/local/keepalived sudo make && sudo make install