设为首页 收藏本站
查看: 1157|回复: 0

[经验分享] heartbeat搭建高可用NFS

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-19 11:06:11 | 显示全部楼层 |阅读模式
基本环境准备;
wKioL1S7pgGApQ4qAAFru3qSIDE579.jpg
[iyunv@localhost ~]# vim/etc/sysconfig/network  (修改主机名)
NETWORKING=yes
HOSTNAME=node1.dragon.com                    (这里每台主机自行修改为node1,2,3)
[iyunv@localhost~]# vim /etc/hosts                                (修改主机文件,分别指向node1,2,3)
127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4
::1        localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1node1.dragon.com node1             (这里每台主机自行修改为node1,2,3)
172.16.18.10node1.dragon.com node1
172.16.18.20node2.dragon.com node2
172.16.18.30node3.dragon.com node3
[iyunv@localhost ~]# scp /etc/hosts node2:/etc/         (把文件传给node2,node3)
[iyunv@localhost ~]# scp /etc/hosts node3:/etc/
[iyunv@localhost ~]# scp/etc/sysconfig/network node2:/etc/sysconfig/
[iyunv@localhost ~]# scp/etc/sysconfig/network node3:/etc/sysconfig/
[iyunv@ localhost ~]# init 6(修改完三台服务器名称记得重启)

生成私钥;
方便几台服务器之间传输文件。这里仅是node1给node2和node3传私钥,如果node2想给node1传文件只需同样的配置;
[iyunv@node1 ~]# ssh-keygen -t rsa  (生成密钥,无密码)
[iyunv@node1 ~]# ssh-copy-id node2  (密钥传给node2)
[iyunv@node1 ~]# ssh-copy-id node3  (密钥传给node2)

安装相关包
(在两node1和node2执行)
[iyunv@node1 yum.repos.d]# yum -ygroupinstall "development tools" "platform development"  (安装开发平台,开发环境,三服务器全装)
[iyunv@node1 ~]# yum install net-snmp-libs libnet  PyXML  perl-TimeDate  (安装依赖关系,node1,node2装)
[iyunv@node1 heartbeat2]# cd heartbeat2/
[iyunv@node1 heartbeat2]# ll                                   (相关包可去官网下载)
-rw-r--r-- 1 root root 1420924 Sep 10  2013 heartbeat-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root 3589552 Sep 10  2013heartbeat-debuginfo-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root  282836 Sep 10 2013 heartbeat-devel-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root  168052 Sep 10 2013 heartbeat-gui-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root  108932 Sep 10 2013 heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root   92388 Sep 10 2013 heartbeat-pils-2.1.4-12.el6.x86_64.rpm
-rw-r--r-- 1 root root  166580 Sep 10 2013 heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
[iyunv@node1 heartbeat2]# rpm -ivh heartbeat-pils-2.1.4-12.el6.x86_64.rpmheartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-2.1.4-12.el6.x86_64.rpm

设置时间同步
[iyunv@node1 yum.repos.d]# date ;ssh node2'date'   (查看时间 )
[iyunv@node1 yum.repos.d]# ntpdate172.16.0.1 ;ssh node2  'ntpdate172.16.0.1'  (我时间服务器是172.16.0.1,也可以去百度找时间服务器)
[iyunv@node2 heartbeat2]# which ntpdate           (查看某命令路径)
/usr/sbin/ntpdate
[iyunv@node1 yum.repos.d]# crontab –e               (在两节点执行,设置任务计划,每三分钟同步一次)
*/3 * * * */usr/sbin/ntpdate 172.16.0.1  &>/dev/null

配置heartbeat
[iyunv@node1 yum.repos.d]# cd/usr/share/doc/heartbeat-2.1.4/
[iyunv@node1 heartbeat-2.1.4]# cp -pauthkeys haresources ha.cf /etc/ha.d/  (保持原有属性,复制文件)
ha.cf:heartbeat的主配置文件;
authkeys:集群信息加密算法及密钥;
haresources:heartbeat v1的CRM配置接口;
[iyunv@node1 heartbeat-2.1.4]# cd /etc/ha.d/
[iyunv@node1 ha.d]# chmod 600 authkeys
[iyunv@node1 ha.d]# vim ha.cf               (编辑主配置文件;)
#      File to write other messages to
logfile /var/log/ha-log
#      Facility to use for syslog()/logger
#logfacility    local0
……………..
mcast eth0 225.0.0.14 6941 0               (多播地址,范围224.0.2.0~238.255.255.255
,可随意填写, 基于多播的方式进行通信 ,选网卡,组,端口,多播报文ttl值(1是直达目标主机),0拒绝接收本地回环

#     Set up a unicast / udp heartbeat medium
……….
#      (note: auto_failback can be any boolean or "legacy")
auto_failback on             (默认选项,出故障时自动恢复)
……….
#      Tell what machines are in the cluster
#      node    nodename ...    -- must match uname -n
#node  ken3
#node  kathy
node node1.dragon.com                         (定义节点名称,必须是各主机#uname -n的名称)
node node2.dragon.com
……….
#      note: don't use a cluster node as ping node   
#ping 10.10.10.254
ping 172.16.18.30           (定义仲裁节点,能Ping通就说明正常工作)
……….
#      library in the system.     
compression    bz2              (定义压缩工具)
#      Confiugre compression threshold
compression_threshold 2               (小于2K不压缩)

[iyunv@node1 ~]# openssl rand -hex 6  (生成一个随机数)
febe06c057d0
[iyunv@node1 ha.d]# vim authkeys       (集群信息加密算法及密钥)
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 1
1 sha1 febe06c057d0
[iyunv@node1 ha.d]# vim haresources  (设置资源管理haresources 主节点)
#      They must match the names of the nodes listed in ha.cf, which in turn
#      must match the `uname -n` of some node in the cluster.  So they aren't
#      virtual in any sense of the word.
node1.dragon.com  172.16.18.51/16/eth0/172.16.255.255 httpd (主节点,vip(虚拟IP),启动的服务)
[iyunv@node1 ha.d]# scp -p authkeysharesources  ha.cf  node2:/etc/ha.d/  (node1,node2配置同步)
[iyunv@node1 heartbeat2]# service heartbeatstart ; ssh node2 'service heartbeat start'  (启动两节点heartbeat服务,会自动启用httpd服务)
[iyunv@node1 ha.d]# vim /var/www/html/index.html
node1
[iyunv@node2 heartbeat2]# vim/var/www/html/index.html
node2
访问虚拟IP,发现vip在Node1节点上
QQ截图20150119110354.jpg

[iyunv@node1 ha.d]# service heartbeat stop  (再访问172.16.18.51,会跳转到node2)
QQ截图20150119110406.jpg
[iyunv@node1 ha.d]# service heartbeat start

[iyunv@node1 ha.d]# cd /usr/lib64/heartbeat/
[iyunv@node1 heartbeat]# ./hb_standby  (也可以输入命令使自己变备用节点)
[iyunv@node1 heartbeat]#./hb_takeover  (也可以输入命令使自己变主节点)


添加NFS服务器

[iyunv@node3 yum.repos.d]# mkdir /web/htdocs–pv
[iyunv@node3 yum.repos.d]# vim/web/htdocs/index.html
pages from nfsserver
[root@node3yum.repos.d]# vim /etc/exports   (共享文件/web/htdocs)      
/web/htdocs172.16.0.0/16(rw,no_root_squash)
[iyunv@node3 yum.repos.d]# service nfs start     (启动NFS服务)
[iyunv@node3 yum.repos.d]# chkconfig nfs on (设置开机启动此服务)
[iyunv@node3 yum.repos.d]# chkconfig   –list  nfs  (查看开机启动)
[iyunv@node1 heartbeat]# cd /etc/ha.d/  
[iyunv@node1 ha.d]# service heartbeat stop;ssh node2 'service heartbeat stop'  (先关闭服务)
[iyunv@node1 ha.d]#  mount -t nfs 172.16.18.30:/web/htdocs /mnt  (尝试挂载,最好在两节点都亲尝试)
[iyunv@node1 ha.d]# mount                   (查看是否挂载成功)
[iyunv@node1 ha.d]# umount /mnt/  (成功后卸载)
[iyunv@node1 ha.d]# vim haresources
#node1.dragon.com172.16.18.51/16/eth0/172.16.255.255 httpd (注释前面的配置)
node1.dragon.com172.16.18.51/16/eth0/172.16.255.255Filesystem::172.16.18.30:/web/htdocs::/var/www/html::nfs httpd
Node1(默认主节点名称)   IP地址 Filesystem(代理文件)::172.16.18.30:/web/htdocs(代理文件地址,我们这里是共享文件,也可以是本地文件,如果是本地文件直接写本地路径)::/var/www/html挂在点::nfs文件系统 所用服务:httpd

[iyunv@node1 ha.d]# scp haresourcesnode2:/etc/ha.d/   (复制给Node2)
[iyunv@node1 ha.d]# service heartbeatrestart ;ssh node2 'service heartbeat restart' (启动服务)
[iyunv@node1 ha.d]# mount           (等待几秒发现文件已经挂载成功)
172.16.18.30:/web/htdocson /var/www/html type nfs (rw,vers=4,addr=172.16.18.30,clientaddr=172.16.18.10)

再次访问172.16.18.51(虚拟IP),就显示NFS的页面了!

QQ截图20150119110413.jpg
[iyunv@node1 ha.d]# serviceheartbeat stop (停止主节点服务)
[iyunv@node2 ha.d]# mout    (文件已经挂载到备用节点)
172.16.18.30:/web/htdocson /var/www/html type nfs (rw,vers=4,addr=172.16.18.30,clientaddr=172.16.18.20)
仍然可以访问!!!
QQ截图20150119110423.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-41050-1-1.html 上篇帖子: Heartbeat+httpd+NFS 实现高可用的Web服务器 下篇帖子: heartbeat3.0.5+drbd8.4.4+nfs 构建高可用nfs环境
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表