基于NFS存储建立WEB群(PCS工具)

简介: 基于NFS存储建立WEB群(PCS工具)

实现NFS共享存储的WEB群集,前提是建立好web群集 这是我另一篇建立web群集的博客: blog.csdn.net/qq_45714272…


基于NFS服务器的WEB群集原理


image.png


可以根据这个图片来理解这个原理,我在web1上有照片,但是我web2没有,我可以在两台web后加一个nfs存储服务器,NFS是一个共享目录或文件的服务。web1收到的数据,在发给nfs,nfs在给web2 1、安装NFS服务器


[root@sto yum.repos.d]# yum install -y nfs-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package matching 1:nfs-utils-1.3.0-0.21.el7.x86_64 already installed. Checking for update.
Nothing to do
[root@sto yum.repos.d]# systemctl restart rpcbind
[root@sto yum.repos.d]# systemctl enable rpcbind
[root@sto yum.repos.d]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@sto yum.repos.d]# systemctl start nfs-server
[root@sto yum.repos.d]# systemctl status firewalld
[root@sto http]# systemctl stop firewalld


防火墙开启的情况要增加nfs,rpc-bind,mounted服务,然后reload生效


2、准备NFS服务器资源

创建Export目录(共享目录)
[root@sto yum.repos.d]# mkdir /http
[root@sto yum.repos.d]# chmod a+x /http
[root@sto yum.repos.d]# vi /etc/exports
/http * (rw)
[root@sto yum.repos.d]# systemctl restart nfs-server
在其他节点进行测试
[root@rs1 ~]# showmount -e sto
Export list for sto:
/http *
[root@rs1 ~]# mkdir /mnt/nfs
[root@rs1 ~]# mount sto:/http /mnt/nfs
[root@rs1 ~]# cp ./anaconda-ks.cfg /mnt/nfs/test.txt
[root@rs2 ~]# showmount -e sto
Export list for sto:
/http *
[root@rs2 ~]# mkdir /mnt/nfs
[root@rs2 ~]# mount sto:/http /mnt/nfs
[root@rs2 ~]# cp ./anaconda-ks.cfg /mnt/nfs/test2.txt
[root@sto http]# ls
test2.txt  test.txt

创建NFS集群

[root@rs1 ~]# pcs resource create WebFS ocf:heartbeat:Filesystem \
> device='sto:/http' directory='/var/www/html' fstype='nfs' \
> op monitor interval=20s timeout=40s \
> op start timeout=60s op stop timeout=60s
[root@rs1 ~]# pcs resource create WebFS ocf:heartbeat:Filesystem  device='storage:/http' directory='/var/www/html' fstype='nfs' op monitor interval=20s timeout=40s > op start timeout=60s op stop timeout=60s
[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 02:59:31 2020
Last change: Sat May  9 02:59:22 2020 by root via cibadmin on rs1
2 nodes configured
3 resources configured
Online: [ rs1 rs2 ]
Full list of resources:
 VirtualIP  (ocf::heartbeat:IPaddr2): Started rs1
 WebFS  (ocf::heartbeat:Filesystem):  Started rs2
Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled
[root@rs1 ~]# echo NFS > /var/www/html
[root@rs1 ~]# systemctl restart httpd

创建web集群

pcs resource create Wbsite ocf:heartbeat:apache httpd="/usr/sbin/httpd" \ configfile=/etc/httpd/conf/httpd.conf \

statusurl="http://localhost/server-status" \ op monitor interval=1min


之前碰到的问题是web群集起不来,后来在一篇文章发现要添加httpd="/usr/sbin/httpd" ,也就是httpd命令的位置,这样就可以了


[root@rs1 html]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 03:41:11 2020
Last change: Sat May  9 03:21:45 2020 by root via cibadmin on rs1
2 nodes configured
3 resources configured
Online: [ rs1 rs2 ]
Full list of resources:
 VirtualIP  (ocf::heartbeat:IPaddr2): Started rs1
 WebFS  (ocf::heartbeat:Filesystem):  Started rs1
 Wbsite (ocf::heartbeat:apache):  Started rs1
Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled

配置组和约束


通过将资源运行在同一节点上

[root@rs1 ~]# pcs resource group add a VirtualIP WebFS Website [root@rs1 html]# pcs status Cluster name: cluster1 Stack: corosync Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum Last updated: Sat May  9 03:42:47 2020 Last change: Sat May  9 03:42:44 2020 by root via cibadmin on rs1


2 nodes configured 3 resources configured


Online: [ rs1 rs2 ]


Full list of resources:


Resource Group: a VirtualIP (ocf::heartbeat:IPaddr2): Started rs1 WebFS (ocf::heartbeat:Filesystem): Started rs1 Wbsite (ocf::heartbeat:apache): Started rs1


Daemon Status:   corosync: active/disabled   pacemaker: active/disabled   pcsd: active/enabled


通过约束管理资源的启动


[root@rs1 ~]# pcs constraint order VirtualIP then Website 
Adding VirtualIP Wbsite (kind: Mandatory) (Options: first-action=start then-action=start)
[root@rs1 ~]# pcs constraint order WebFS then Website
Adding WebFS Wbsite (kind: Mandatory) (Options: first-action=start then-action=start)


资源在web1的情况下访问VIP


image.png


资源在web2的情况下访问:

[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 03:55:54 2020
Last change: Sat May  9 03:55:40 2020 by root via cibadmin on rs1
2 nodes configured
3 resources configured
Node rs1: standby
Online: [ rs2 ]
Full list of resources:
 Resource Group: a
     VirtualIP  (ocf::heartbeat:IPaddr2): Started rs2
     WebFS  (ocf::heartbeat:Filesystem):  Started rs2
     Wbsite (ocf::heartbeat:apache):  Starting rs2
Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled

image.png

结果还是一样的,这样就完成啦基于NFS存储的WEB群集了


还有个重点:


[root@rs1 html]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2020-05-09 03:37:45 EDT; 10min ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 27583 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 27582 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 27582 (code=exited, status=1/FAILURE)
May 09 03:37:45 rs1 httpd[27582]: (98)Address already in use: AH00072: make_sock: co...:80
May 09 03:37:45 rs1 httpd[27582]: (98)Address already in use: AH00072: make_sock: co...:80
May 09 03:37:45 rs1 httpd[27582]: no listening sockets available, shutting down
May 09 03:37:45 rs1 httpd[27582]: AH00015: Unable to open logs
May 09 03:37:45 rs1 systemd[1]: httpd.service: main process exited, code=exited, sta...URE
May 09 03:37:45 rs1 kill[27583]: kill: cannot find process ""
May 09 03:37:45 rs1 systemd[1]: httpd.service: control process exited, code=exited s...s=1
May 09 03:37:45 rs1 systemd[1]: Failed to start The Apache HTTP Server.
May 09 03:37:45 rs1 systemd[1]: Unit httpd.service entered failed state.
May 09 03:37:45 rs1 systemd[1]: httpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@rs1 html]# ps aux |grep http
root      18067  0.0  0.3 224068  3476 ?        Ss   03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    18068  0.0  0.3 224204  3752 ?        S    03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    18069  0.0  0.3 224204  3752 ?        S    03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    18070  0.0  0.3 224204  3752 ?        S    03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    18071  0.0  0.3 224204  3756 ?        S    03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    18072  0.0  0.3 224204  3764 ?        S    03:19   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
apache    31002  0.0  0.3 224204  3704 ?        S    03:44   0:00 /sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf -c PidFile /var/run/httpd.pid
root      35170  0.0  0.0 112712   952 pts/1    R+   03:49   0:00 grep --color=auto http

我们的httpd服务显示暂停了,但是看进程还是在运行的,是因为: 当我们添加web群集之后,httpd不在由systemctl控制,而是由群集组件控制,所以我们用进程看httpd还是在运行的

用PCS建立WEB集群,一直不生效怎么解决!


心累,耗了我2天时间才解决。

[root@rs1 ~]# pcs resource create Website ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf  

statusurl="http://localhost/server-status" \ op monitor interval=1min

[root@rs1 ~]# pcs status Cluster name: cluster1 Stack: corosync Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum Last updated: Sat May  9 02:29:59 2020 Last change: Sat May  9 02:28:36 2020 by root via cibadmin on rs1

2 nodes configured 2 resources configured

Online: [ rs1 rs2 ]

Full list of resources:

VirtualIP (ocf::heartbeat:IPaddr2): Started rs1  Website (ocf::heartbeat:apache): Stopped

Failed Resource Actions:

  • Website_start_0 o n rs1 'unknown error' (1): call=19, status=Timed Out, exitreason='', last-rc-change='Sat May  9 02:29:17 2020', queued=0ms, exec=40004ms
  • Website_start_0 on rs2 'unknown error' (1): call=14, status=Timed Out, exitreason='', last-rc-change='Sat May  9 02:28:36 2020', queued=0ms, exec=40006ms

Daemon Status:   corosync: active/disabled   pacemaker: active/disabled   pcsd: active/enabled


在放个日志文件

May  9 02:29:48 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:49 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:49 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:50 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:50 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:51 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:51 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:52 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:52 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:53 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:53 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:54 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:54 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:55 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:55 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:56 b apache(Website)[12391]: INFO: apache not running
May  9 02:29:56 b apache(Website)[12391]: INFO: waiting for apache /etc/httpd/conf/httpd.conf to come up
May  9 02:29:57 b lrmd[9228]: warning: Website_start_0 process (PID 12391) timed out
May  9 02:29:57 b lrmd[9228]: warning: Website_start_0:12391 - timed out after 40000ms
May  9 02:29:57 b crmd[9231]:   error: Result of start operation for Website on rs1: Timed Out
May  9 02:29:57 b crmd[9231]: warning: Action 5 (Website_start_0) on rs1 failed (target: 0 vs. rc: 1): Error
May  9 02:29:57 b crmd[9231]:  notice: Transition aborted by operation Website_start_0 'modify' on rs1: Event failed
May  9 02:29:57 b crmd[9231]:  notice: Transition 16 (Complete=2, Pending=0, Fired=0, Skipped=0, Incomplete=1, Source=/var/lib/pacemaker/pengine/pe-input-16.bz2): Complete
May  9 02:29:57 b pengine[9230]: warning: Processing failed start of Website on rs1: unknown error
May  9 02:29:57 b pengine[9230]: warning: Processing failed start of Website on rs1: unknown error
May  9 02:29:57 b pengine[9230]: warning: Processing failed start of Website on rs2: unknown error
May  9 02:29:57 b pengine[9230]: warning: Forcing Website away from rs1 after 1000000 failures (max=1000000)
May  9 02:29:57 b pengine[9230]: warning: Forcing Website away from rs2 after 1000000 failures (max=1000000)
May  9 02:29:57 b pengine[9230]:  notice:  * Stop       Website       (        rs1 )   due to node availability
May  9 02:29:57 b pengine[9230]:  notice: Calculated transition 17, saving inputs in /var/lib/pacemaker/pengine/pe-input-17.bz2

解决方案重新创建web集群

[root@rs1 html]# pcs resource create Wbsite ocf:heartbeat:apache 
httpd="/usr/sbin/httpd" \
configfile=/etc/httpd/conf/httpd.conf  \
statusurl="http://localhost/server-status" \
op monitor interval=1min
可以看出我在原来的基础上加了一个httpd="/usr/sbin/httpd" \,也就是httpd命令的位置,看结果:
[root@rs1 html]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 03:33:01 2020
Last change: Sat May  9 03:21:45 2020 by root via cibadmin on rs1
2 nodes configured
3 resources configured
Online: [ rs1 rs2 ]
Full list of resources:
 VirtualIP  (ocf::heartbeat:IPaddr2): Started rs1
 WebFS  (ocf::heartbeat:Filesystem):  Started rs1
 Wbsite (ocf::heartbeat:apache):  Started rs1
Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled

解决了!


相关文章
|
1月前
|
存储 Web App开发 移动开发
HTML5 Web 存储详解
HTML5 Web存储提供了两种客户端数据存储机制:**Local Storage**和**Session Storage**。Local Storage用于长期存储数据,即使关闭浏览器数据也依然存在,适用于保存用户偏好设置等信息。Session Storage则在标签或窗口关闭时清除数据,适合存储临时信息。两者均提供了简单的API进行数据的存取操作,但需要注意的是,Web存储并非加密存储,不应存放敏感信息。现代浏览器普遍支持Web存储,合理利用这两种存储方式可提升Web应用的用户体验。
|
7天前
|
人工智能 前端开发 计算机视觉
Inpaint-Web:纯浏览器端实现的开源图像处理工具
在刷短视频时,常看到情侣在景区拍照被路人“抢镜”,男朋友用手机将路人“P”掉,既贴心又有趣。最近我发现了一个纯前端实现的开源项目——inpaint-web,可在浏览器端删除照片中的部分内容,非常酷。该项目基于 WebGPU 和 WASM 技术,支持图像修复与放大,已在 GitHub 上获得 5.1k Star。项目地址:[GitHub](https://github.com/lxfater/inpaint-web)。
47 3
 Inpaint-Web:纯浏览器端实现的开源图像处理工具
|
1月前
|
存储 缓存 前端开发
Web应用中的存储方式有哪些?
本文首发于微信公众号“前端徐徐”,介绍了几种常见的前端数据存储技术:Cookie、Web Storage(包括 localStorage 和 sessionStorage)、IndexedDB、Cache Storage 和 Memory Storage。每种技术的特点和使用场景不同,适用于不同的开发需求。文章详细解释了它们的使用方法、特点和应用场景,并提供了代码示例。
102 2
Web应用中的存储方式有哪些?
|
21天前
|
前端开发 JavaScript 开发者
构建响应式设计的现代Web应用:实用技巧与工具
【10月更文挑战第24天】本文介绍了构建响应式Web应用的实用技巧和工具,涵盖流体网格布局、弹性图片、CSS媒体查询、CSS Grid和Flexbox、响应式导航菜单、图片和字体的响应式处理,以及测试和调试工具。掌握这些技能将帮助开发者提升用户体验和项目适应性。
|
21天前
|
移动开发 数据可视化 前端开发
可视化设计web界面的工具
有什么可视化设计web界面的工具
30 0
|
1月前
|
存储 移动开发 缓存
HTML5 Web 存储详解
HTML5 Web 存储包括 `localStorage` 和 `sessionStorage`,前者提供持久存储且无过期时间,后者仅在会话期间有效。两者均支持键值对形式存储数据,容量约为 5-10 MB。`localStorage` 适用于用户偏好设置、登录状态保持及离线应用缓存;`sessionStorage` 则用于临时数据如表单输入。数据以字符串形式存储,可通过 `JSON` 方法处理对象。由于数据存储于本地,不适合存放敏感信息。示例代码展示了如何使用按钮将输入框内容保存至 `localStorage` 并进行清除操作。
|
1月前
|
存储 前端开发 API
前端开发中,Web Storage的存储数据的方法localstorage和sessionStorage的使用及区别
前端开发中,Web Storage的存储数据的方法localstorage和sessionStorage的使用及区别
93 0
|
1月前
|
缓存 前端开发 JavaScript
深入了解Webpack:现代Web开发的核心工具
【10月更文挑战第11天】深入了解Webpack:现代Web开发的核心工具
|
1月前
|
JavaScript 前端开发 API
深入了解jQuery:简化Web开发的强大工具
【10月更文挑战第11天】深入了解jQuery:简化Web开发的强大工具
13 0
|
1月前
|
开发框架 .NET 开发工具
visualstudio如何加入工作插件---Web developer工具
visualstudio如何加入工作插件---Web developer工具
22 0

热门文章

最新文章