具体配置如下:
分别给2台虚拟机添加2块5G的磁盘。如图-1所示。
图-1
实现此案例需要按照如下步骤进行。
步骤一:磁盘分区(2台数据库服务器都配置)
1)创建分区,每块盘分1个区即可
[root@mysql11 ~]# fdisk -l /dev/vdb //查看磁盘容量
磁盘 /dev/vdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@mysql11 ~]#
[root@mysql11 ~]# fdisk -l /dev/vdc //查看磁盘容量
磁盘 /dev/vdc:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@mysql11 ~]#
[root@mysql11 ~]# fdisk /dev/vdb //磁盘分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x882d04b7 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n //创建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //创建主分区
分区号 (1-4,默认 1):1 //指定编号
起始 扇区 (2048-10485759,默认为 2048): //起始柱面数
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-10485759,默认为 10485759)://结束柱面数
将使用默认值 10485759
分区 1 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@mysql11 ~]#
[root@mysql11 ~]# fdisk /dev/vdc //给vdc盘分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x5184f504 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-10485759,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-10485759,默认为 10485759):
将使用默认值 10485759
分区 1 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@mysql11 ~]#
2)查看分区
[root@mysql11 ~]# fdisk -l /dev/vdb
磁盘 /dev/vdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x882d04b7
设备 Boot Start End Blocks Id System
/dev/vdb1 2048 10485759 5241856 83 Linux
[root@mysql11 ~]#
[root@mysql11 ~]#
[root@mysql11 ~]# fdisk -l /dev/vdc
磁盘 /dev/vdc:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x5184f504
设备 Boot Start End Blocks Id System
/dev/vdc1 2048 10485759 5241856 83 Linux
[root@mysql11 ~]#
步骤二:创建LV
1)修改设备ID
[root@mysql11 ~]# fdisk /dev/vdb //修改/dev/vdb 欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):t //修改类型
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e //指定为8e
已将分区“Linux”的类型更改为“Linux LVM
命令(输入 m 获取帮助):w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@mysql11 ~]# fdisk -l /dev/vdb //查看磁盘信息
磁盘 /dev/vdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x882d04b7
设备 Boot Start End Blocks Id System
/dev/vdb1 2048 10485759 5241856 8e Linux LVM
[root@mysql11 ~]#
[root@mysql11 ~]# fdisk /dev/vdc
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@mysql11 ~]# fdisk -l /dev/vdc
磁盘 /dev/vdc:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x5184f504
设备 Boot Start End Blocks Id System
/dev/vdc1 2048 10485759 5241856 8e Linux LVM
[root@mysql11 ~]#
2)安装软件提供命令的软件
[root@mysql11 ~]# yum -y install lvm2 //安装软件 已加载插件:fastestmirror Loading mirror speeds from cached hostfile local_repo | 3.6 kB 00:00:00 正在解决依赖关系 --> 正在检查事务 ---> 软件包 lvm2.x86_64.7.2.02.177-4.el7 将被 安装 …… …… 已安装:lvm2.x86_64 7:2.02.177-4.el7
作为依赖被安装:
device-mapper-event.x86_64 7:1.02.146-4.el7
device-mapper-event-libs.x86_64 7:1.02.146-4.el7
device-mapper-persistent-data.x86_64 0:0.7.3-3.el7
libaio.x86_64 0:0.3.109-13.el7
lvm2-libs.x86_64 7:2.02.177-4.el7
完毕!
[root@mysql11 ~]#
3)创建PV
[root@mysql11 ~]# [root@mysql11 ~]# pvcreate /dev/vdb1 /dev/vdc1 //创建PVPhysical volume "/dev/vdb1" successfully created.Physical volume "/dev/vdc1" successfully created. [root@mysql11 ~]# [root@mysql11 ~]# pvdisplay //查看PV信息"/dev/vdb1" is a new physical volume of "<5.00 GiB"--- NEW Physical volume ---PV Name /dev/vdb1VG NamePV Size <5.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID nDR2To-tDoy-Vow6-AZz9-ryXe-go8D-RJLsdT
“/dev/vdc1” is a new physical volume of “<5.00 GiB”
— NEW Physical volume —
PV Name /dev/vdc1
VG Name
PV Size <5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID OLxKI6-OymP-erzX-2sFh-6R4Z-TUlI-A0Z3C1
[root@mysql11 ~]#
4)创建VG
[root@mysql11 ~]# vgcreate vg0 /dev/vdb1 /dev/vdc1 //创建vg 名称vg0Volume group "vg0" successfully created [root@mysql11 ~]# vgdisplay--- Volume group ---VG Name vg0System IDFormat lvm2Metadata Areas 2Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 2Act PV 2VG Size 9.99 GiBPE Size 4.00 MiBTotal PE 2558Alloc PE / Size 0 / 0Free PE / Size 2558 / 9.99 GiBVG UUID IEdyUc-jUgs-pNcs-En2M-XZLc-xpsx-GC3Xhc
[root@mysql11 ~]#
5)创建LV
[root@mysql11 ~]# lvcreate -L 9.99G -n lv0 vg0 //创建LV 名称为lv0 大小9.99GRounding up size to full physical extent 9.99 GiBLogical volume "lv0" created. [root@mysql11 ~]# lvdisplay--- Logical volume ---LV Path /dev/vg0/lv0LV Name lv0VG Name vg0LV UUID JTMuKS-b8bO-6dMK-VKqA-1ji0-rN59-FPVlchLV Write Access read/writeLV Creation host, time mysql11, 2019-07-05 09:39:41 +0800LV Status available# open 0LV Size 9.99 GiBCurrent LE 2558Segments 2Allocation inheritRead ahead sectors auto- currently set to 256Block device 252:0
[root@mysql11 ~]#
6)格式化
[root@mysql11 ~]# mkfs.xfs /dev/vg0/lv0 //格式化为 xfs 文件系统 meta-data=/dev/vg0/lv0 isize=512 agcount=4, agsize=654848 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2619392, imaxpct=25= sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
[root@mysql11 ~]# blkid /dev/vg0/lv0 //查看文件系统类型
/dev/vg0/lv0: UUID=“3e06f58f-8793-4800-b444-676f5a07fe10” TYPE=“xfs”
[root@mysql11 ~]#
具体操作如下:
实现此案例需要按照如下步骤进行。
步骤一:安装软件MySQL服务软件(2台数据库服务器都要安装)
1)解包软件
[root@mysql11 ~]# tar -xvf mysql-5.7.17.tar ./mysql-community-client-5.7.17-1.el7.x86_64.rpm ./mysql-community-common-5.7.17-1.el7.x86_64.rpm ./mysql-community-devel-5.7.17-1.el7.x86_64.rpm ./mysql-community-embedded-5.7.17-1.el7.x86_64.rpm ./mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm ./mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm ./mysql-community-libs-5.7.17-1.el7.x86_64.rpm ./mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm ./mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm ./mysql-community-server-5.7.17-1.el7.x86_64.rpm ./mysql-community-test-5.7.17-1.el7.x86_64.rpm [root@mysql11 ~]#
[root@mysql11 ~]# ls *.rpm
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
[root@mysql11 ~]#
2)安装软件
[root@mysql11 ~]# yum -y install mysql-community-*.rpm 已加载插件:fastestmirror 正在检查 mysql-community-client-5.7.17-1.el7.x86_64.rpm: mysql-community-client-5.7.17-1.el7.x86_64 mysql-community-client-5.7.17-1.el7.x86_64.rpm 将被安装 …… …… 已安装:mysql-community-client.x86_64 0:5.7.17-1.el7 mysql-community-common.x86_64 0:5.7.17-1.el7mysql-community-devel.x86_64 0:5.7.17-1.el7 mysql-community-embedded.x86_64 0:5.7.17-1.el7mysql-community-embedded-compat.x86_64 0:5.7.17-1.el7 mysql-community-embedded-devel.x86_64 0:5.7.17-1.el7mysql-community-libs.x86_64 0:5.7.17-1.el7 mysql-community-libs-compat.x86_64 0:5.7.17-1.el7mysql-community-minimal-debuginfo.x86_64 0:5.7.17-1.el7 mysql-community-server.x86_64 0:5.7.17-1.el7mysql-community-test.x86_64 0:5.7.17-1.el7
作为依赖被安装:
perl-Data-Dumper.x86_64 0:2.145-3.arch 0:2.59-2.el7
完毕!
[root@mysql11 ~]#
步骤二:挂载lv设备
1)设置开机挂载
[root@mysql11 ~]# blkid /dev/vg0/lv0 /dev/vg0/lv0: UUID="3e06f58f-8793-4800-b444-676f5a07fe10" TYPE="xfs" [root@mysql11 ~]#
[root@mysql11 ~]# vim /etc/fstab
/dev/vg0/lv0 /var/lib/mysql xfs defaults 0 0
:wq
[root@mysql11 ~]#
2)查看挂载信息
[root@mysql11 ~]# mount -a
[root@mysql11 ~]# mount | grep lv0
/dev/mapper/vg0-lv0 on /var/lib/mysql type xfs (rw,relatime,attr2,inode64,noquota)
[root@mysql11 ~]#
步骤三:启动服务
1)启动服务
2台数据库服务器都要启动服务
[root@mysql11 ~]# systemctl start mysqld [root@mysql11 ~]# [root@mysql11 ~]# ls /var/lib/mysql autof client-cert.pem ibdata1 ibtmp1 mysql.sock.lock public_key.pem sys ca-key.pem client-key.pem ib_logfile0 mysql performance_schema server-cert.pem ca.pem ib_buffer_pool ib_logfile1 mysql.sock private_key.pem server-key.pem [root@mysql11 ~]# [root@mysql11 ~]# systemctl enable mysqld [root@mysql11 ~]#
[root@mysql11 ~]# netstat -utnlp | grep :3306
tcp6 0 0 :::3306 ::😗 LISTEN 1531/mysqld
[root@mysql11 ~]#
步骤四:管理员登录
1)查看初始密码
[root@mysql11 ~]# grep password /var/log/mysqld.log 2019-07-05T01:56:51.895852Z 1 [Note] A temporary password is generated for root@localhost: bB0*uCmu:.Kj
[root@mysql11 ~]#
[root@mysql11 ~]# mysql -uroot -p’bB0*uCmu:.Kj’ //初始密码登录
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.17
Copyright © 2000, 2016, 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>
2)修改登录密码
mysql> alter user root@"localhost" identified by A"; Query OK, 0 rows affected (0.01 sec) mysql> mysql> exit Bye [root@mysql11 ~]#
3)新密码登录
[root@mysql11 ~]# mysql -uroot -A mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.7.17 MySQL Community Server (GPL)
Copyright © 2000, 2016, 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> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.00 sec)
配置步骤如下:
实现此案例需要按照如下步骤进行。
步骤一:配置主服务器
1)启用binlog日志
[root@mysql11 ~]# vim /etc/myf [mysqld] server_id=11 log-bin=master11 :wq [root@mysql11 ~]# systemctl restart mysqld [root@mysql11 ~]#
2)用户授权
[root@mysql11 ~]# mysql -uroot -A mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 mysql> mysql> grant replication slave on *.* to repluser@"%" identified by A"; Query OK, 0 rows affected, 1 warning (0.04 sec) mysql>
3)查看日志信息
[root@mysql11 ~]# mysql -uroot -A mysql> show master status; +-----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-----------------+----------+--------------+------------------+-------------------+ | master11.000001 | 441 | | | | +-----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
mysql>
步骤二:配置从服务器
1)指定server_id
[root@mysql22 ~]# vim /etc/myf [mysqld] server_id=22 :wq [root@mysql22 ~]# systemctl restart mysqld
2)指定主服务器信息
[root@mysql22 ~]# mysql -uroot -A mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.7.17 MySQL Community Server (GPL) Mysql>
mysql> change master to master_host=“192.168.4.11”,master_user=“repluser”,
-> master_password=“123qqq…A”,master_log_file=“master11.000001”,master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.41 sec)
mysql>
3)启动slave进程
mysql> start slave ; Query OK, 0 rows affected (0.02 sec)
mysql>
4)查看状态信息
[root@mysql22 ~]# mysql -uroot -p123qqq…A -e “show slave statusG” |grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@mysql22 ~]#
[root@mysql22 ~]# mysql -uroot -p123qqq…A -e “show slave statusG” |grep -i 192.168.4.11
mysql: [Warning] Using a password on the command line interface can be insecure.
Master_Host: 192.168.4.11
[root@mysql22 ~]#
配置步骤如下:
实现此案例需要按照如下步骤进行。
步骤一:配置读写分离服务
1)安装软件
[root@maxscale77 ~]# rpm -ivh maxscale-2.1.2-1.rhel.7.x86_64.rpm //安装软件 警告:maxscale-2.1.2-1.rhel.7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 8167ee24: NOKEY 准备中... ################################# [100%] 正在升级/安装...1:maxscale-2.1.2-1 ( 2%################################# [100%] [root@maxscale77 ~]# [root@maxscale77 ~]# ls /etc/maxscalef //主配置文件 /etc/maxscalef [root@maxscale77 ~]# ls /var/log/maxscale/ //日志目录
2)修改配置文件
[root@maxscale77 ~]# vim /etc/maxscalef
[maxscale] //服务线程数量
threads=auto
[server1] //第1台数据库服务器
type=server
address=192.168.4.11
port=3306
protocol=MySQLBackend
[server2] //第2台数据库服务器
type=server
address=192.168.4.22
port=3306
protocol=MySQLBackend
[MySQL Monitor] //指定监控数据库服务器server1 和 server2
type=monitor
module=mysqlmon
servers=server1, server2
user=maxscalemon //监控用户
passwd=123qqq…A //密码
monitor_interval=10000
[Read-Write Service] //定义读写分离服务
type=service
router=readwritesplit
servers=server1, server2
user=maxscalerouter //路由用户
passwd=123qqq…A //密码
max_slave_connections=100%
[MaxAdmin Service] //定义管理服务
type=service
router=cli
[Read-Write Listener] //定义读写分离服务端口
type=listener
service=Read-Write Service
protocol=MySQLClient
port=4006 //端口号
[MaxAdmin Listener] //定义管理服务端口
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default
port=4016 //端口号
:wq
[root@maxscale77 ~]#
步骤二:配置数据库服务器
1)创建用户:在主服务器上添加,从服务器查看即可
[root@mysql11 ~]# mysql -uroot -A mysql> grant replication slave, replication client on *.*-> to maxscalemon@"%"identified by A"; Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> grant select on mysql.* to
-> maxscalerouter@"%" identified by “123qqq…A”;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql>
2) 从服务器查看授权用户
[root@mysql22 ~]# mysql -uroot -A -e 'select user,host from mysql.user where user like "maxscale%" ' mysql: [Warning] Using a password on the command line interface can be insecure. +----------------+------+ | user | host | +----------------+------+ | maxscalemon | % | | maxscalerouter | % | +----------------+------+ [root@mysql22 ~]#
步骤三:启动maxsacle服务
1)启动服务
[root@maxscale77 ~]# [root@maxscale77 ~]# maxscale -f /etc/maxscalef [root@maxscale77 ~]#
2)查看服务信息(进程 和 端口)
[root@maxscale77 ~]# ps -C maxscalePID TTY TIME CMD 23254 ? 00:00:00 maxscale [root@maxscale77 ~]#
[root@maxscale77 ~]# netstat -utnlp | grep maxscale
tcp6 0 0 :::4006 ::😗 LISTEN 23254/maxscale
tcp6 0 0 :::4016 ::😗 LISTEN 23254/maxscale
[root@maxscale77 ~]#
3)在maxscale服务本机访问管理服务,查看监控信息
[root@maxscale77 ~]# maxadmin -uadmin -pmariadb -P4016 MaxScale> list servers Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- server1 | 192.168.4.11 | 3306 | 0 | Master, Running server2 | 192.168.4.22 | 3306 | 0 | Slave, Running -------------------+-----------------+-------+-------------+-------------------- MaxScale> MaxScale> exit [root@maxscale77 ~]#
具体配置如下:
给NFS服务器主机添加1块10G的磁盘。如图-2所示。
图-2
实现此案例需要按照如下步骤进行。
步骤一:磁盘分区
1)创建分区,分1个区即可
[root@nfs30 ~]# fdisk -l /dev/vdb //查看磁盘信息
磁盘 /dev/vdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@nfs30 ~]#
[root@nfs30 ~]# fdisk /dev/vdb //磁盘分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x67bb10cf 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Select (default p): p //创建主分区
分区号 (1-4,默认 1): //回车
起始 扇区 (2048-20971519,默认为 2048): //回车
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519)://回车
将使用默认值 20971519
分区 1 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@nfs30 ~]#
2)查看分区
[root@nfs30 ~]# fdisk -l /dev/vdb
磁盘 /dev/vdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x67bb10cf
设备 Boot Start End Blocks Id System
/dev/vdb1 2048 20971519 10484736 83 Linux
[root@nfs30 ~]#
步骤二:挂载磁盘
1)格式化
[root@nfs30 ~]# mkfs.xfs /dev/vdb1 //格式化 meta-data=/dev/vdb1 isize=512 agcount=4, agsize=655296 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621184, imaxpct=25= sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@nfs30 ~]# [root@nfs30 ~]# blkid /dev/vdb1 //查看 /dev/vdb1: UUID="81740d7a-51f1-4ce1-a830-7b6517cc778e" TYPE="xfs" [root@nfs30 ~]#
2)配置开机挂载
[root@nfs30 ~]# vim /etc/fstab //修改配置文件 /dev/vdb1 /sitedir xfs defaults 0 0 [root@nfs30 ~]#
[root@nfs30 ~]# mkdir /sitedir //创建挂载目录
[root@nfs30 ~]# chmod o+w /sitedir/ //赋予写权限
[root@nfs30 ~]# mount –a //加载文件中所有未加载的设备
[root@nfs30 ~]# mount | grep “/sitedir” //查看加载信息
/dev/vdb1 on /sitedir type xfs (rw,relatime,attr2,inode64,noquota)
[root@nfs30 ~]#
具体配置如下:
实现此案例需要按照如下步骤进行。
步骤一:部署NFS服务
1)安装软件
[root@nfs30 ~]# yum -y install nfs-utils rpcbind 已安装:nfs-utils.x86_64 1:1.3.0-0.54.el7 rpcbind.x86_64 0:0.2.0-44.el7
作为依赖被安装:
gssproxy.x86_64 0:0.7.0-17.el7 keyutils.x86_64 0:1.5.8-3.el7
libbasicobjects.x86_64 0:0.1.1-29.el7 libcollection.x86_64 0:0.7.0-29.el7
libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-29.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-29.el7
libref_array.x86_64 0:0.1.5-29.el7 libtirpc.x86_64 0:0.2.4-0.10.el7
libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-17.el7
arch 1:4.01-17.el7 tcp_wrappers.x86_64 0:7.6-77.el7
完毕!
[root@nfs30 ~]#
2)修改配置文件
[root@nfs30 ~]# [root@nfs30 ~]# vim /etc/exports /sitedir *(rw) :wq [root@nfs30 ~]# exportfs –r //加载配置 [root@nfs30 ~]#
步骤二:启动服务
1)启动服务
[root@nfs30 ~]# systemctl start rpcbind [root@nfs30 ~]# [root@nfs30 ~]# systemctl start nfs [root@nfs30 ~]#
[root@nfs30 ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@nfs30 ~]#
[root@nfs30 ~]# systemctl enable rpcbind
[root@nfs30 ~]#
2)查看共享信息
[root@nfs30 ~]# vim /etc/fstab //修改配置文件 [root@nfs30 ~]# showmount -e localhost Export list for localhost: /sitedir * [root@nfs30 ~]#
具体配置如下:
实现此案例需要按照如下步骤进行。
步骤一:部署网站服务
1)安装软件
[root@web33 ~]# yum -y install httpd //网站服务软件 已安装:httpd.x86_64 0:2.4.s
作为依赖被安装:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.arch 0:2.1.41-2.el7
完毕!
[root@web33 ~]#
[root@web33 ~]# yum -y install nfs-utils //访问nfs服务软件
已安装:
nfs-utils.x86_64 1:1.3.0-0.54.el7
作为依赖被安装:
gssproxy.x86_64 0:0.7.0-17.el7 keyutils.x86_64 0:1.5.8-3.el7
libbasicobjects.x86_64 0:0.1.1-29.el7 libcollection.x86_64 0:0.7.0-29.el7
libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-29.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-29.el7
libref_array.x86_64 0:0.1.5-29.el7 libtirpc.x86_64 0:0.2.4-0.10.el7
libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-17.el7
arch 1:4.01-17.el7 rpcbind.x86_64 0:0.2.0-44.el7
tcp_wrappers.x86_64 0:7.6-77.el7
完毕!
[root@web33 ~]#
2)挂载共享目录 到 /var/www/html
[root@web33 ~]# showmount -e 192.168.4.30 //查看共享 Export list for 192.168.4.30: /sitedir * [root@web33 ~]# [root@web33 ~]# vim /etc/fstab //配置开机挂载 192.168.4.30:/sitedir /var/www/html nfs defaults 0 0 :wq
[root@web33 ~]# mount –a //加载所有未加载的设备
步骤二:启动服务
1)启动服务
[root@web33 ~]# systemctl start httpd [root@web33 ~]#
[root@web33 ~]# systemctl enable remote-fs.target //设置远程加载服务开机运行
[root@web33 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@web33 ~]#
2)查看挂载信息
[root@web33 ~]# [root@web33 ~]# mount | grep "/var/www/html" 192.168.4.30:/sitedir on /var/www/html type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.4.33,local_lock=none,addr=192.168.4.30) [root@web33 ~]#
具体配置如下:
实现此案例需要按照如下步骤进行。
步骤一:测试NFS服务
1)在nfs服务器创建网页 test.html
[root@nfs30 ~]# echo "web test page" > /sitedir/test.html [root@nfs30 ~]# [root@nfs30 ~]# ls /sitedir/ test.html [root@nfs30 ~]#
2)在客户端192.168.4.254 分别访问网站服务
[root@room9pc17 ~]# curl 192.168.4.33/test.html //访问网站33主机 web test page [root@room9pc17 ~]# [root@room9pc17 ~]# curl 192.168.4.44/test.html //访问网站44主机 web test page [root@room9pc17 ~]#
步骤二:测试MySQL服务
1)在主数据库服务器上添加,访问数据的连接用户
[root@mysql11 ~]# mysql -uroot -A mysql> create database gamedb; //建库 Query OK, 1 row affected (0.03 sec)
mysql> grant select,insert,update,delete on gamedb.* to yaya99@"%" identified by “123qqq…A”; //用户授权
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> create table gamedb.user(name char(15)); //建表
Query OK, 0 rows affected (0.31 sec)
mysql> select * from gamedb.user;
Empty set (0.01 sec)
mysql>
2)在从服务器查看是否同步数据
[root@mysql22 ~]# mysql -uroot -p123qqq…A
mysql> show grants for yaya99@"%"; //查看授权用户
±-------------------------------------------------------------------+
| Grants for yaya99@% |
±-------------------------------------------------------------------+
| GRANT USAGE ON . TO ‘yaya99’@’%’ |
| GRANT SELECT, INSERT, UPDATE, DELETE ONgamedb
.* TO ‘yaya99’@’%’ |
±-------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> desc gamedb.user; //查看库表
±------±---------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±------±---------±-----±----±--------±------+
| name | char(15) | YES | | NULL | |
±------±---------±-----±----±--------±------+
1 row in set (0.01 sec)
mysql> select * from gamedb.user;
Empty set (0.00 sec)
mysql>
mysql> insert into gamedb.user values(“xdd”); //用来验证数据读写分离
Query OK, 1 row affected (0.03 sec)
mysql>
mysql> select * from gamedb.user;
±-----+
| name |
±-----+
| xdd |
±-----+
1 row in set (0.00 sec)
mysql>
3)测试读写分离服务
在网站服务器上,连接数据读写分离服务器77
[root@web33 ~]# yum -y install mariadb //安装提供连接命令软件 已安装:mariadb.x86_64 1:5.5.56-2.el7 作为依赖被安装:mariadb-libs.x86_64 1:5.5.56-2.el7 完毕! [root@web33 ~]#
[root@web33 ~]# mysql -h192.168.4.77 -P4006 -uyaya99 -p123qqq…A //连接读写分离服务
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 23258
Server version: 10.0.0 2.1.2-maxscale MySQL Community Server (GPL)
Copyright © 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.
MySQL [(none)]>
4)查询数据
MySQL [(none)]> select * from gamedb.user; //显示的是从服务器上的数据 +------+ | name | +------+ | xdd | +------+ 1 row in set (0.00 sec) MySQL [(none)]>
5)存储数据
MySQL [(none)]> insert into gamedb.user values("pmm"); //插入记录 Query OK, 1 row affected (0.05 sec) MySQL [(none)]> select * from gamedb.user; //查看记录 +------+ | name | +------+ | xdd | | pmm | +------+ 2 rows in set (0.00 sec)
MySQL [(none)]>
6)在主服务器本机登录查看数据
[root@mysql11 ~]# mysql -uroot -p123qqq…A -e “select * from gamedb.user”
mysql: [Warning] Using a password on the command line interface can be insecure.
±-----+
| name |
±-----+
| pmm |
±-----+
[root@mysql11 ~]#
具体配置如下:
实现此案例需要按照如下步骤进行。
步骤一:部署运行环境LNMP
1)安装LNMP环境
[root@zabbixserver ~]# yum -y install gcc pcre-devel openssl-devel [root@zabbixserver ~]# tar -xf nginx-1.12. [root@zabbixserver ~]# cd nginx-1.12.2 [root@zabbixserver nginx-1.12.2]# ./configure --with-http_ssl_module [root@zabbixserver nginx-1.12.2]# make && make install [root@zabbixserver ~]# yum -y install php php-mysql > mariadb mariadb-devel mariadb-server [root@zabbixserver ~]# yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm //注意,php-fpm这个软件包在lnmp_soft/目录下
2)修改Nginx配置文件
配置Nginx支持PHP动态网站,因为有大量PHP脚本需要执行,因此还需要开启Nginx的各种fastcgi缓存,加速PHP脚本的执行速度。
[root@zabbixserver ~]# vim /usr/local/nginx/f … … http{ … …fastcgi_buffers 8 16k; //缓存php生成的页面内容,8个16kfastcgi_buffer_size 32k; //缓存php生产的头部信息fastcgi_connect_timeout 300; //连接PHP的超时时间fastcgi_send_timeout 300; //发送请求的超时时间fastcgi_read_timeout 300; //读取请求的超时时间 location ~ .php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include f;} … …
3)启动服务
启动Nginx、PHP-FPM、MariaDB服务,关闭SELinux与防火墙。
[root@zabbixserver ~]# systemctl start mariadb [root@zabbixserver ~]# systemctl start php-fpm [root@zabbixserver ~]# ln -s /usr/local/nginx/sbin/nginx /sbin/nginx [root@zabbixserver ~]# nginx
[root@zabbixserver ~]# firewall-cmd --set-default-zone=trusted
[root@zabbixserver ~]# setenforce 0
4)客户端测试LNMP环境
服务器创建PHP测试页面,浏览器访问页面测试网页连通性。
[root@zabbixserver ~]# cat /usr/local/nginx/html/test.php
<?php
$i=33;
echo $i;
?>
[root@zabbixserver ~]# curl 192.168.2.5/test.php
步骤二:安装Zabbix软件
1)安装源码Zabbix软件
[root@zabbixserver lnmp_soft]# yum -y install net-snmp-devel
> curl-devel
//安装相关依赖包
[root@zabbixserver lnmp_soft]# yum -y install
> libevent-devel-2.0.21-4.el7.x86_64.rpm
//注意libevent-devel这个软件包在lnmp_soft目录下有提供
[root@zabbixserver lnmp_soft]# tar -xf zabbix-3.4.
[root@zabbixserver lnmp_soft]# cd zabbix-3.4.4/
[root@zabbixserver zabbix-3.4.4]# ./configure --enable-server
> --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config
> --with-net-snmp --with-libcurl
// --enable-server安装部署zabbix服务器端软件
// --enable-agent安装部署zabbix被监控端软件
// --enable-proxy安装部署zabbix代理相关软件
// --with-mysql配置mysql_config路径
// --with-net-snmp允许zabbix通过snmp协议监控其他设备
// --with-libcurl安装相关curl库文件,这样zabbix就可以通过curl连接http等服务,测试被监控主机服务的状态
[root@zabbixserver zabbix-3.4.4]# make && make install
步骤三:初始化配置
1)创建数据库
[root@zabbixserver ~]# mysql mysql> create database zabbix character set utf8; //创建数据库,支持中文字符集 mysql> grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix'; //创建可以访问数据库的账户与密码 [root@zabbixserver ~]# cd zabbix-3.4.4/database/mysql/ [root@zabbixserver mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql [root@zabbixserver mysql]# mysql -uzabbix -pzabbix zabbix < images.sql [root@zabbixserver mysql]# mysql -uzabbix -pzabbix zabbix < data.sql
2)安装依赖
[root@zabbixserver ~]# yum -y install php-gd php-xml [root@zabbixserver ~]# yum –y install php-bcmath [root@zabbixserver ~]# yum –y install php-mbstring
3)修改php程序运行参数
[root@zabbixserver ~]# vim /etc/php.ini date.timezone = Asia/Shanghai //设置时区 max_execution_time = 300 //最大执行时间,秒 post_max_size = 32M //POST数据最大容量 max_input_time = 300 //服务器接收数据的时间限制 memory_limit = 128M //内存容量限制 :wq [root@zabbixserver ~]# systemctl restart php-fpm
步骤四:修改配置文件
1)在主数据库服务器上添加,访问数据的连接用户
[root@zabbixserver ~]# vim /usr/local/etc/f DBHost=localhost //数据库主机,默认该行被注释 DBName=zabbix //设置数据库名称 DBUser=zabbix //设置数据库账户 DBPassword=zabbix //设置数据库密码,默认该行被注释 LogFile=/tmp/zabbix_server.log //设置日志
:wq
步骤五:启动服务
1)启动服务
[root@zabbixserver ~]# useradd -s /sbin/nologin zabbix //不创建用户无法启动服务
[root@zabbixserver ~]# zabbix_server //启动服务
2)查看服务状态信息
[root@zabbixserver ~]# ss -ntulp |grep zabbix_server //确认连接状态,端口10051
tcp LISTEN 0 128 *:10051 : users:((“zabbix_server”,pid=23275,fd=4),(“zabbix_server”,pid=23274,fd=4)
具体配置如下:
实现此案例需要按照如下步骤进行。
步骤一:安装软件
1)安装依赖软件
]#yum -y install gcc pcre-devel
2)安装源码zabbix软件
]#tar -zxvf zabbix-3.4. ]#cd zabbix-3.4.4/ ]#./configure --enable-agent ]# make install
3)修改配置文件
]#vim /usr/local/etc/f #Server=127.0.0.1 StartAgents=0 ServerActive=192.168.4.55 Hostname=web33 :wq
步骤二:启动服务
1)启动服务,只有端口没有进程
]# useradd zabbix ]# zabbix_agentd ]# netstat -utnlp | grep :10050 没有端口 ]# ps -C zabbix_agentd 有进程
在监控服务器上做如下配置:
实现此案例需要按照如下步骤进行。
步骤一:创建主动模式监控模板
1)克隆监控模板,新模板名称为:Template OS Linux ServerActive。如图-3所示
图-3
2)修改模板中的监控项目的监控模式为主动模式,如图-4所示
3)禁用不支持主动模式的监控项目如图-5所示。
图-5
步骤二:配置自动发现
1)创建自动发现规则
通过Configuration(配置)-->Discovery(自动发现)-->Create discovery rule(创建发现规则),如图-6所示。
图-6
2)填写规则
填写自动发现的IP范围(逗号隔开可以写多个),多久做一次自动发现(默认为1小时,仅实验修改为1m),如图-7所示。配置检查的方式:Ping、HTTP、FTP、Agent的自定义key等检查,如图-8所示。
图-7
图-8
3)创建Action动作
通过Configuration(配置)--> Actions Event source(事件源):自动发现(Discovery)-->Create action(创建动作),如图-9所示。
图-9
4)配置Action动作具体行为
配置动作,添加动作名称,添加触发动作的条件,如图-10所示。
图-10
点击操作(触发动作后要执行的操作指令),操作细节:添加主机到组,与模板链接(HTT如图-11所示。
图-11
步骤三:查看监控信息
1)验证监控效果,如图-12所示
图-12
本文发布于:2024-01-31 01:27:43,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170663566824356.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |