分布式部署LNMP+WordPress

一.MYSQL主从配置

1. 基础环境安装

(1)修改主机名

使用远程连接工具CRT连接到192.168.200.30、192.168.200.40这两台虚拟机,并对这两台虚拟机进行修改主机名的操作,192.168.200.30主机名修改为mysql1,192.168.200.40主机名修改为mysql2。命令如下:

mysql1节点:

[root@localhost ~]#

[root@localhost ~]# hostnamectl set-hostname mysql1

[root@localhost ~]# bash

[root@mysql1 ~]# hostnamectl

     Static hostname: mysql1

           Icon name: computer-vm

            Chassis: vm

          Machine ID: ee0b84dcaf7b4238828a5e8b5034f13a

            Boot ID: 0ba766491a56409980ed3a0f891f1596

     Virtualization: vmware

   Operating System: CentOS Linux 7 (Core)

        CPE OS Name: cpe:/o:centos:centos:7

             Kernel: Linux 3.10.0-327.el7.x86_64

       Architecture: x86-64

mysql2节点:

[root@localhost ~]# hostnamectl set-hostname mysql2

[root@localhost ~]# bash

[root@mysql2 ~]# hostnamectl

    Static hostname: mysql2

          Icon name: computer-vm

            Chassis: vm

         Machine ID: ee0b84dcaf7b4238828a5e8b5034f13a

            Boot ID: 628055e67e634e259d2dc86b9b913e14

     Virtualization: vmware

   Operating System: CentOS Linux 7 (Core)

        CPE OS Name: cpe:/o:centos:centos:7

             Kernel: Linux 3.10.0-327.el7.x86_64

       Architecture: x86-64

(2)关闭防火墙及SELinux服务

两个节点关闭防火墙firewalld及SELinux服务,命令如下:

[root@mysql2 ~]# setenforce 0

[root@mysql2 ~]# systemctl stop firewalld

(3)配置hosts文件

两个节点配置/etc/hosts文件,修改为如下:

[root@mysql2 ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.131.30 mysql1

192.168.131.40 mysql2

(4)配置YUM源并安装数据库服务

使用项目3-Linux系统与服务构建运维中的方法,挂载CentOS-7-x86_64-DVD-1511.iso镜像并自行配置YUM源,配置完毕后,两个节点安装数据库服务,命令如下:

[root@mysql2 ~]# yum install -y mariadb mariadb-server

两个节点启动数据库服务并设置开机自启,命令如下:

[root@mysql2 ~]# systemctl start mariadb

[root@mysql2 ~]# systemctl enable mariadb

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

2. 初始化数据库并配置主从服务

(1)初始化数据库

两个节点初始化数据库,配置数据库root密码为000000,命令如下:       

[root@mysql1 ~]# 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 e

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值