magedu_linux02的ChinaUnix博客
magedu_linux02
全部博文(6)
2015年(6)
马哥教育
分类: LINUX
2015-09-08 21:47:00
NFS相关介绍
一、NFS简介
1. NFS(Network File System): NFS是一个文件共享协议, 也是是在类Unix系统中在内核中实现的文件系统。
2. 起源: 最早是由SUN公司研发,非常古老,只是实现文件共享,安全控制方面比较简陋。 版本有, NFSv1, NFSv2,NFSv3,NFSv4. v4版开始支持kerberos 认证。
3. RPC(Remote Procedure Call):NFS协议是基于PRC(远程过程调用)实现的。
基本过程如下图,客户端某程序发起过程请求–>rpc客户端接过请求–>通过套接字通信交给服务器端–>服务器端接过请求交给某程序执行–>执行后把结果或者状态返回客户端
RPC守护进程rpcbind监听: 111/tcp 和 111/udp
RPC远程调用进程rpc.mount 监听: 2049/tcp 和 2049/udp
4. 关于NFS的安全设置,原生的NFS服务只能基于IP认证。 NFSv4可以基于以下两种认证方式认证
NIS: Network Information Service
Kerberos 5. 安装配置: nfs-utils包, NFS为内核实现,所以只需要工具包
6. 三个关键进程:
mountd: 挂载搜索进程,负责客户端源认证的进程
nfsd:文件读写
idmapd:id映射进程
7. 配置文件/etc/exports:
点击(此处)折叠或打开
8. 相关命令
9. 由于nfs辅助进程mountd默认监听随机端口,有可能会占用一些重要端口,例如80,所以有时需要锁定端口
在/etc/sysconfig/nfs 中实现
双web服务器 + php-fpm + nfs + mysql 搭建discuz论坛,实现双web服务器共享后端数据。
、
在四台主机上,需要搭建五个服务。
1) 两台主机担任前端httpd1和httpd2服务器。具有同样域名不同ip,负责简单负载均衡
2) 一台主机担任php-fpm服务器,接受前端web服务对于php页面的反向代理请求。 NFS服务器负责为前端两个web服务器导出论坛安装目录。
3) 最后一台主机存放mysql服务器, 为前端论坛提供数据库服务。
以下配置过程,从后往前配置,先从mysql服务器开始
一、 配置mysql服务器 (主机192.168.98.131)
四、配置最前端的两台web 服务器 (192.168.98.128 和 192.168.98.129) 点击(此处)折叠或打开 1. 同样安装编译环境。 2. 安装apache运行环境apr和apr-util # tar xf apr-1.5.2.tar.gz # cd apr-1.5.2 # ./configure --prefix=/usr/local/apr # make && make install # tar xf apr-util-1.5.4.tar.gz # cd apr-util-1.5.4 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # make && make install 3. 编译安装httpd # tar -xf httpd-2.4.16.tar.gz # cd httpd-2.4.16 # ./configure --prefix=/usr/local/httpd24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enables-modules=most --enable-mpms-shared=all --with-mpm=event # make && make install 4. 提供服务脚本 # vim /etc/rc.d/init.d/httpd24 复制粘贴一下内容,通常把yum源安装的httpd服务脚本,稍加修改即可 #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/httpd24/bin/apachectl httpd=${HTTPD-/usr/local/httpd24/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd24.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd24} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL # chmod +x /etc/rc.d/init.d/httpd # chkconfig --add httpd24 5. 配置httpd ## 创建网页文件目录 # mkdir -p /var/www/htdocs/Discuz/upload/ ## 查看192.168.98.130主机是否成功导出目录 # showmount -e 192.168.98.130 Export list for 192.168.98.130: /var/www/htdocs/Discuz/upload 192.168.98.129/24,192.168.98.128/24 ## 在/etc/fstab中添加自动挂载项 192.168.98.130:/var/www/htdocs/Discuz/upload /var/www/htdocs/Discuz/upload nfs auto,acl 0 0 # mount -a 6. 配置虚拟主机,设置反向代理 # vim /etc/httpd24/httpd.conf 添加或者开启 ## 反向代理支持模块 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so ## 虚拟主机,需要注释掉原主机 #DocumentRoot "/usr/local/httpd24/htdocs/Discuz/upload" <VirtualHost *:80> DocumentRoot "/var/www/htdocs/Discuz/upload" DirectoryIndex index.php index.html home.html default.html ServerName www.discuz.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.98.130:9000/var/www/htdocs/Discuz/upload/$1 <Directory "/var/www/htdocs/Discuz/upload"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> ## 启动服务 # service httpd24 start
五、安装discuz论坛并测试 。
windows 测试
浏览器输入域名后,即可进行安装,数据库安装时,输入预先在192.168.98.131数据库服务器上设置的认证信息
关闭192.168.98.129 web服务器,上传一个图片
关闭192.168.98.128后,启动192.168.98.129,刷新浏览器依然可以看到附件,说明负载均衡生效了
上一篇:Linux精品之OpenStack Icehouse私有云实战部署
下一篇:没有了
登录 注册