云计算1+X初级题目之一 Centos7的mariadb主从服务

题目:使用镜像 centos7,创建两台云主机master和slave,并分别绑定浮动IP;在这2台云主机上安装mysql据库系统并配置为主从数据库(master为主节点、slave为从节点);并mater云主机的数据库中创建ChinaSkilldb库,在ChinaSkilldb库中创建表testable (id int not null primary key,Teamname varchar(50), remarks varchar(255)),在表中插入记录(1,“Cloud”,“ChinaSkill”)。

master为主节点 : 192.168.100.128
slave为从节点:192.168.100.129

安装mariadb服务(master和slave)

yum install mariadb mariadb-server -y
=============================================
systemctl start mariadb  (重启mariadb)
=============================================
systemctl enable mariadb  (开机自动启动服务)
=============================================
[root@root@master ~]# mysql_secure_installation(初始化数据库)
=============================================
[root@root@slave ~]# mysql_secure_installation(初始化数据库)
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 这个我打密码为六个零
Re-enter new password:  确认密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

登录进MySQL

[root@master ~]# mysql -uroot -p000000
MariaDB [(none)]> grant all on *.* to 'user'@'%' identified by '000000';
MariaDB [(none)]> update mysql.user set Grant_priv='Y' where Host='%';
=============================================
[root@slave ~]# mysql -uroot -p000000
MariaDB [(none)]> grant all on *.* to 'user'@'%' identified by '000000';
MariaDB [(none)]> update mysql.user set Grant_priv='Y' where Host='%';

以上操作两个节点一致

配置master和slave的my.cnf

master

[root@master ~]# vi /etc/my.cnf
[mysqld]
server-id=99   ID可以自定 但是不能与slave一样
log-bin=mysql-bin
wq 保存退出
[root@master ~]# systemctl restart mariadb 重启服务

slave

[root@slave ~]# vi /etc/my.cnf
[mysqld]
server-id=101   ID可以自定 但是不能与master一样
log-bin=mysql-bin
wq 保存退出
[root@slave ~]# systemctl restart mariadb 重启服务

配置master和slave数据库

master

[root@master ~]# mysql -uroot -p000000  进入mysql
MariaDB [(none)]> show master status\G  
*************************** 1. row ***************************
            File: mysql-bin.000001
        Position: 616
    Binlog_Do_DB: 
Binlog_Ignore_DB: 
1 row in set (0.00 sec)

slave

[root@slave ~]# mysql -uroot -p000000  进入mysql
MariaDB [(none)]> show slave status\G
Empty set (0.00 sec)
=============================================
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
=============================================
MariaDB [(none)]> change master to master_host='192.168.100.128',master_user='user',master_password='000000',master_log_file='mysql-bin.000001',master_log_pos=616; 
Query OK, 0 rows affected (0.00 sec)
=============================================
PS:master_log_file='mysql-bin.000001'  对应master的  File:
PS:master_log_pos=616;   对应master的 Position

最后创建ChinaSkilldb库,在ChinaSkilldb库中创建表testable (id int not null primary key,Teamname varchar(50), remarks varchar(255)),在表中插入记录(1,“Cloud”,“ChinaSkill”)

MariaDB [(none)]> create database ChinaSkilldb;  创建ChinaSkilldb库
Query OK, 1 row affected (0.00 sec)
============================================
MariaDB [(none)]> show databases;   
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ChinaSkilldb       |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
=============================================
MariaDB [(none)]> use ChinaSkilldb;  使用ChinaSkilldb库
Database changed
=============================================
MariaDB [ChinaSkilldb]> create table testable (id int not null primary key,Teamname varchar(50), remarks varchar(255)); 创建表testable
Query OK, 0 rows affected (0.00 sec)
=============================================
MariaDB [ChinaSkilldb]> show tables;
+------------------------+
| Tables_in_ChinaSkilldb |
+------------------------+
| testable               |
+------------------------+
1 row in set (0.00 sec)
=============================================
Database changed
MariaDB [ChinaSkilldb]> insert into testable values (1,"Cloud","ChinaSkill");  插入内容
Query OK, 1 row affected (0.00 sec)
=============================================

END

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晴空哦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值