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.
分區(qū)格式化 [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
將目錄屬主和組更改為test為了方便并賦予777權(quán)限 sudo chown test:test -R /data/ chmod 777 /data/ cd /data/ mkdir mysql cd /data/mysql/ 創(chuàng)建數(shù)據(jù)目錄,日志目錄,pid目錄 mkdir data logs run
將mysql軟件放在/usr/local/下 cd /usr/local/ sudo mkdir mysql sudo chown test:test ./mysql/ cd /data mv mysql-5.7.26-linux-glibc2.12-x86_64/* /usr/local/mysql/ 刪除空目錄 rm mysql-5.7.26-linux-glibc2.12-x86_64/
編輯mysql配置文件node1 sudo vi /etc/my.cnf [mysqld] port=9060 datadir=/data/mysql/data socket=/data/mysql/data/mysql.sock
用初始化生成的root密碼登錄并更改密碼 mysql -uroot -p set password=password("123456"); flush privileges;
配置主從 主節(jié)點(192.168.5.235) 創(chuàng)建同步用戶 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;
測試: 創(chuàng)建數(shù)據(jù)庫 create database test; 創(chuàng)建普通用戶 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; 查看數(shù)據(jù)庫 show databases; 查看用戶 select user,host from mysql.user; 創(chuàng)建表 create table testa( Id varchar(100)); 兩邊都能看到testa表 show tables; 插入語句 insert into testa values('1231'); insert into testa values('4567'); insert into testa values('5464'); 另一個數(shù)據(jù)庫都能看到 select * from testa; delete from testa where Id='1231'; 另一個數(shù)據(jù)庫數(shù)據(jù)顯也被刪除 至此,mysql主主已經(jīng)完全配置成功。
[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