ansible安装drbd+nfs+keepalived

ansible管理机:192.168.8.35 名称:kick

tomcat主机: 192.168.8.234,192.168.8.235

VIP  : 192.168.8.100

系统版本: Centos7.2

##### 实验软件下载地址

配置文件:  http://pan.baidu.com/s/1eSou1Bs

NFS:           http://pan.baidu.com/s/1kVieBgN

DRBD:        http://pan.baidu.com/s/1nvkIxtR

######### 下载drbd 软件及模块

wget http://elrepo.reloumirrors.net/elrepo/el7/x86_64/RPMS/kmod-drbd84-8.4.6-1.el7.elrepo.x86_64.rpm

wget http://elrepo.reloumirrors.net/elrepo/el7/x86_64/RPMS/drbd84-utils-8.9.1-1.el7.elrepo.x86_64.rpm

######### 将下载软件复制到各节点中去,也可以直接下载

[[email protected] ~]# ansible store -m copy -a "src=drbd84-utils-8.9.1-1.el7.elrepo.x86_64.rpm dest=/tmp/"

[[email protected] ~]# ansible store -m copy -a "src=kmod-drbd84-8.4.6-1.el7.elrepo.x86_64.rpm dest=/tmp/"

######### 三步可以合一起直接yum -y install http://elrepo.reloumirrors.net/elrepo/el7/x86_64/RPMS/kmod-drbd84-8.4.6-1.el7.elrepo.x86_64.rpm

[[email protected] ~]# ansible store -m shell -a "yum -y install /tmp/drbd84-utils-8.9.1-1.el7.elrepo.x86_64.rpm"

[[email protected] ~]# ansible store -m shell -a "yum -y reinstall /tmp/kmod-drbd84-8.4.6-1.el7.elrepo.x86_64.rpm"

######### 加载drbd模块

[[email protected] ~]# ansible store -m shell -a "modprobe drbd"

######### 查看drbd模块是否已加载上

[[email protected] ~]# ansible store -m shell -a "lsmod | grep drbd"

192.168.8.235 | SUCCESS | rc=0 >>

drbd                  392583  0

libcrc32c              12644  2 xfs,drbd

192.168.8.234 | SUCCESS | rc=0 >>

drbd                  392583  0

libcrc32c              12644  2 xfs,drbd

# 新加一个磁盘分区不需要格式化

######### 配置drbd全局配置及资源

[[email protected] ~]# ansible store -m copy -a "src=global_common.conf dest=/etc/drbd.d/"

[[email protected] ~]# ansible store -m copy -a "src=mydrbd.res dest=/etc/drbd.d/"

[[email protected] ~]# vim global_common.conf

global {

usage-count no;

}

common {

handlers {

pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";

}

startup {

}

options {

}

disk {

on-io-error detach;

}

net {

cram-hmac-alg "sha1";

shared-secret "xiong123";

}

syncer {

rate 1024M;

}

}

################# 资源叫mydrbd,主机名称一定要在本地的/etc/hosts中增加主机名称解析否则会报错

[[email protected] ~]# vim mydrbd.res

resource mydrbd{

device /dev/drbd0;

disk /dev/sdb1;

meta-disk internal;

on store1 {

address 192.168.8.234:7789;

}

on store2 {

address 192.168.8.235:7789;

}

}

# 更改hosts主机名称

[[email protected] ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.8.234 store1

192.168.8.235 store2

[[email protected] ~]# ansible store -m copy -a "src=/etc/hosts dest=/etc/hosts"

######### 配置mydrbd资源并启动服务,查看资源信息两个没有主的时候都是seconary

[[email protected] ~]# ansible store -m shell -a "drbdadm create-md mydrbd"

[[email protected] ~]# ansible store -m shell -a "systemctl start drbd"

[[email protected] ~]# ansible store -m shell -a "drbd-overview"

# 随便登陆一台设置成主节点

[[email protected] ~]# drbdadm primary --force mydrbd

# 测试查看

######### 安装nfs软件,也可以直接安装nfs-utils-1.3.0-0.33.el7.x86_64.rpm 这个版本,最后有错误记录

[[email protected] ~]# ansible store -m yum -a "name=nfs-utils state=installed"

######### 配置keepalived,直接使用ansible安装即可

################# 主库 ##################################

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

}

notification_email_from [email protected]

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script check_run {

script "/etc/keepalived/notify_check.sh"

interval 10

weight 10

}

vrrp_instance nfs {

state MASTER

interface eno16780032

virtual_router_id 70

priority 100

advert_int 1

nopreempt                   # 不让它强制抢占资源

authentication {

auth_type PASS

auth_pass PPVk7CXXZ5U

}

track_script {

check_run weight 20                            # 检查节点信息状态,关闭keepalived,之后它会调取notify_stop

}

notify_stop /etc/keepalived/notify_stop.sh         # 当节点stop后停止所有服务

notify_master /etc/keepalived/notify_master.sh     # 当节点成为master时开启所有服务

virtual_ipaddress {

192.168.8.100

}

}

################# 备库 ##################################

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

}

notification_email_from [email protected]

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script check_run {

script "/etc/keepalived/notify_check.sh"

interval 10

weight 10

}

vrrp_instance nfs {

state BACKUP

interface eno16780032

virtual_router_id 70

priority 95

advert_int 1

nopreempt                     # 不让它强制抢占资源

authentication {

auth_type PASS

auth_pass PPVk7CXXZ5U

}

track_script {

check_run weight 20

}

notify_stop /etc/keepalived/notify_stop.sh

notify_master /etc/keepalived/notify_master.sh

virtual_ipaddress {

192.168.8.100

}

}

#############################################################

######### 配置NFS

[[email protected] ~]# cat /etc/exports

/data   192.168.8.0/24(rw,async,all_squash,anonuid=2021,anongid=2020)

######### 将配置文件复制到store两个drbd服务器中

[[email protected] data]# ansible store -m copy -a "src=exports dest=/etc/"

######### 创建mysql用户mysql组 后续使用

[[email protected] /]# ansible store -m shell -a "groupadd -g 2020 mysql"

[[email protected] /]# ansible store -m shell -a "useradd -g 2020 -u 2021 mysql -s /sbin/nologin"

[[email protected] /]# ansible store -m shell -a "chown mysql.mysql /data/ -R"

######### 复制脚本文件到各节点中

[[email protected] ~]# ansible store -m copy -a "src=notify_master.sh dest=/etc/keepalived/"

[[email protected] ~]# ansible store -m copy -a "src=notify_stop.sh dest=/etc/keepalived/"

[[email protected] ~]# ansible store -m copy -a "src=notify_check.sh dest=/etc/keepalived/"

[[email protected] ~]# ansible store -m copy -a "src=keepalived_store_drbd.conf dest=/etc/keepalived/keepalived.conf"

######################### 脚本内容 #####################################################

[[email protected] ~]# cat notify_master.sh      # 当keepalived为主节点时重启所有服务并设置drbd为主

#!/bin/bash

#

systemctl  restart rpcbind &>/dev/null

systemctl  restart nfs &>/dev/null

systemctl  restart drbd &>/dev/null

/sbin/drbdadm primary mydrbd &>/tmp/node_change.txt

mount /dev/drbd0 /data &>/tmp/node_change.txt

[[email protected] ~]# cat notify_stop.sh # 当检测节点为back时直接停停止各项服务

#!/bin/bash

#

umount /data

systemctl  stop rpcbind &>/dev/null

systemctl  stop nfs &>/dev/null

drbdadm secondary mydrbd &>/tmp/node_change.txt

echo -e "\n" &> /tmp/node_change.txt

systemctl  stop drbd &>/dev/null

[[email protected] ~]# cat notify_check.sh     # 检查服务的正常性 当NFS服务不正常时直接停止keepalived然后再调取notify_stop脚本

#!/bin/sh

###检查nfs可用性:进程和是否能够挂载

systemctl  status nfs &>/dev/null

if [ $? -ne 0 ];then

###如果服务状态不正常,先尝试重启服务

systemctl  restart restart

systemctl  status nfs &>/dev/null

if [ $? -ne 0 ];then

###若重启nfs服务后,仍不正常

###卸载drbd设备

umount /dev/drbd0

###将drbd主降级为备

drbdadm secondary r0

#关闭keepalived

systemctl  stop keepalived

fi

fi

################################ 检查三项服务正常,当其中的任何一个不正常都直接干掉 ##################

#/bin/bash

systemctl  status rpcbind &>/dev/null

VAR1=$?

systemctl  status nfs &>/dev/null

VAR2=$?

systemctl  status drbd &>/dev/null

VAR3=$?

if [ $VAR1 -ne 0 || $VAR2 -ne 0 || $VAR -ne 0 ];then

systemctl  stop rpcbind &>/dev/null

systemctl  stop nfs &>/dev/null

umount /data

drbdadm secondary mydrbd &>/tmp/node_change.txt

echo -e "\n" >> /tmp/node_change.txt

systemctl  stop drbd &>/dev/null

systemctl stop keepalived

fi

##########################################################################################

############## 启动服务 ###########

[[email protected] data]# ansible store -m shell -a "systemctl start keepalived"

[[email protected] data]# ansible store -m shell -a "systemctl start rpcbind"

[[email protected] data]# ansible store -m shell -a "systemctl start nfs"

############### 配合日志查看 ############

[[email protected] data]# ansible store -m shell -a "systemctl status keepalived"

[[email protected] data]# ansible store -m shell -a "systemctl status nfs"

[[email protected] data]# ansible store -m shell -a "cat /var/log/message"

##########################################################################################

# 检查VIP地址以及NFS是否挂载

[[email protected] ~]# showmount -e 192.168.8.100

Export list for 192.168.8.100:

/data 192.168.8.0/24

################################## NFS 出现的一些错误 #################################

[[email protected] ~]# mount -t nfs 192.168.8.234:/data /data

mount.nfs: access denied by server while mounting 192.168.8.234:/data

#在/etc/exports中增加insecure,http://blog.chinaunix.net/uid-20554957-id-3444786.html

/data   192.168.8.0(rw,insecure,no_root_squash,async)

[[email protected] data]# systemctl restart nfs

###### 一直报这个错 ###### 排查确认是 centos7 关于nfs 1.3.0-0.21.el7_2 版本的bug

Jun 27 09:29:52 store1 nfsdcltrack[12174]: sqlite_insert_client: insert statement prepare failed: table clients has 2 columns but 3 values were supplied

# 将版本直接升级至nfs-utils-1.3.0-0.33.el7.x86_64

# 需要的软件包 libtirpc需要大于0.2.4-0.7,libtirpc-devel,nfs-utils-1.3.0-0.33.el7

[[email protected] ~]# ansible store -m copy -a "src=libtirpc-0.2.4-0.8.el7.x86_64.rpm dest=/tmp"

[[email protected] ~]# ansible store -m copy -a "src=libtirpc-devel-0.2.4-0.8.el7.x86_64.rpm dest=/tmp"

[[email protected] ~]# ansible store -m copy -a "src=nfs-utils-1.3.0-0.33.el7.x86_64.rpm dest=/tmp"

[[email protected] ~]# ansible store -m shell -a "rpm -Uvh /tmp/libtirpc-0.2.4-0.8.el7.x86_64.rpm"

[[email protected] ~]# ansible store -m shell -a "rpm -Uvh /tmp/libtirpc-devel-0.2.4-0.8.el7.x86_64.rpm"

[[email protected] ~]# ansible store -m shell -a "rpm -Uvh /tmp/nfs-utils-1.3.0-0.33.el7.x86_64.rpm"

时间: 2024-10-12 05:54:08

ansible安装drbd+nfs+keepalived的相关文章

Heartbeat+DRBD+NFS高可用

一.环境 系统:     CentOS 6.4x64 最小化安装 node1:     192.168.1.13 node2:     192.168.1.14 vip:      192.168.1.15 nfs:      192.168.1.10 二.基础配置 node1和node2的操作一样 #关闭iptables和selinux [[email protected] ~]# getenforce Disabled                        #确保这项是正确的 [[e

Heartbeat+Drbd+NFS高可用实现

继续之前的操作,来完成heartbeat+drbd+nfs高可用的实现. heartbeat+drbd还是使用原来的环境即可,然而需要添加一台nfs客户端,客户端的信息如下: 主机名 IP地址 角色 server136.contoso.com 192.168.49.136 nfs客户端 一.环境准备 1)注意:因为我的客户端是192.168.49.0/24端,所以这里需要把VIP改为这个网段,所以先修改两个节点的haresources文件,将VIP修改为192.168.49.100.可以根据实际

实战:ansible自动化部署nginx+keepalived+mysql负载均衡集群

一.目的 使用ansible自动化部署nginx+keepalived+mysql负载均衡集群. 二.拓扑规划 三.详细步骤 1.环境的搭建 (1).安装ansible,同时配置私钥免密码进行通信 [[email protected] ~]# ssh-keygen  -t rsa #-t表示使用的加密类型,其中rsa1表示version1版本,rsa.dsa.ecdsa的加密对于的是version2版本 Generating public/private rsa key pair. #这里询问你

使用ansible自动化部署nfs+rsync+sersync+web01自动化挂载

第1章 思考 1.1如何一键使用ansible搭建 1.1.1第一步目标 首先我们要明确的是我们需要实现的是一键的自动化脚本,既执行一个脚本然后就自动化安装nfs+rsync+sersync,然后让web01自动挂载nfs共享目录, 1.1.2第二步关系明确及顺序 既然有目标了那么我们需要做的就是我们需要明白自动化安装的先后顺序. 既然我们是需要ansible才能自动化安装那么我们就需要先安装ansible 安装了ansible之后,既然我们想要挂载,那么我们就需要有nfs共享,和rsync备份

Heartbeat+DRBD+NFS高可用案例

9.4 部署DRBD 的需求描述 9.4.1业务需求描述 假设两台服务器Rserver-1/Lserver-1, 其实际IP分别为192.168.236.143(Rserver)和192.168.236.192(Lserver) 配置目标:两台服务器分别配置好DRBD服务后.实现在Rserver-1机器上/dev/sdb 分区上写入数据.数据会时时的同步到Lserver-1机器上面.一旦服务器Rserver-1机器宕机或硬盘损坏导致数据不可用.Lserver-1机器上的数据此时是picdata-

drbd+nfs+heartbeat高可用

DRBD是一种基于软件的.基于网络的块复制存储解决方案 DRBD在IP网络传输,所有在集中使用DRBD作为共享存储设备,不需要任何硬件投资,可以节约很多成本 NFS1 IP1:10.10.10.166     心跳和数据传输网卡  不配置网关,添加路由即可 添加路由:route add -host IP dev eth0并且写在rc.local内 VIP:10.10.10.150 DRBD至少使用两个分区需要单独分出来 NFS2 IP1:10.10.10.167 VIP:10.10.10.50

(转)Heartbeat+DRBD+NFS高可用案例

原文:http://9861015.blog.51cto.com/9851015/1939521--------------------------------Heartbeat+DRBD+NFS高可用案例 9.4 部署DRBD 的需求描述 9.4.1业务需求描述 假设两台服务器Rserver-1/Lserver-1, 其实际IP分别为192.168.236.143(Rserver)和192.168.236.192(Lserver) 配置目标:两台服务器分别配置好DRBD服务后.实现在Rserv

【mac】ansible安装及基础使用

安装 环境释放 mac 10.12.5 #more /System/Library/CoreServices/SystemVersion.plist 安装命令 #ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" #brew update #brew install Ansible 安装后hosts默认访问位置 /usr/local/et

ansible安装应用及playbook剧本的定义

在配置集群时,每个节点上有很多相同的配置,如启动服务相同.安装程序.提供相同的配置文件,甚至定制相同的任务计划来定期执行某些操作等.如果你管理的只是三两个节点配置起来还是相当简单的,但是有三五十台,甚至上百台你还要自已一个一个手动来配置,那就太痛苦了.因些我们就需要能实现批量管理的一套组件,ansible就是实现这样管理的工具. ansible以它强大功能和简单上手的应用,在2012年获OSS(Open Source Software,开源软件 开放源代码软件)一项大奖,评为前十名,评为最有用的