本文主要是介绍基于NFS和autofs的LAMP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、目标
服务器A:httpd服务+php服务 IP:172.17.16.173
服务器B:httpd服务+php服务+mysql服务 IP:172.17.17.173
服务器C:nfs服务+DNS IP:172.17.16.169
服务器A和服务器B的服务内容相同
通过DNS解析可以随机使用A或B, A和B使用同一个数据库B,使用同一个网页内容C。
二、配置服务器C(DNS和NFS)
1.DNS服务
yum install bind
vim /etc/named.conf
#修改下面4行#listen-on port 53 { 127.0.0.1; };#allow-query { localhost; };dnssec-enable no;dnssec-validation no;
vim /etc/named.rfc1912.zones
#添加下面几行zone "muzigan.com" IN {type master;file "named.muzigan.zone";};
vim /var/named/named.muzigan.zone$TTL 1D@ IN SOA dns1 mail.muzigan.com (0 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum@ NS dns1dns1 A 172.17.16.169www A 172.17.17.173www A 172.17.16.173
service named start
2.NFS服务器
yum install nfs-utilsmkdir /httpd
vim /etc/exports
#添加下面一行/httpd 172.17.16.173(rw,anonuid=498,anongid=498) 172.17.17.173(rw,all_squash,anonuid=498,anongid=498)
#启动服务
service rpcbind start
service nfs start
三、服务器B(httpd+php+mysql)
1.mysql服务
yum install mariadb-server
systemctl restart mariadb
mysql_secure_installation
mysql -uroot -pcreate database httpd ;grant all on httpd.* to http@'%' IDENTIFIED BY 'httpd';FLUSH PRIVILEGES;
2.httpd+php服务
yum install httpd php-fpm php-mysql vim /etc/httpd/conf.d/php-fpm.confLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soAddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phpsDirectoryIndex index.phpProxyRequests OffProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/httpd/$1
systemctl restart httpd php-fpm
四、服务器A(httpd服务+php服务)
服务器A:httpd服务+php服务
yum install httpd php-fpm php-mysql vim /etc/httpd/conf.d/php-fpm.confLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soAddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phpsDirectoryIndex index.phpProxyRequests OffProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/httpd/$1
systemctl restart httpd php-fpm
五、使用autofs服务挂载httpd服务站点内容
1.在服务器A和服务器B上用autofs挂载
绝对路径方式
服务器A和B操作一样
yum install autofs
vim /etc/auto.master/- /etc/autofs.d/httpdmkdir /etc/autofs.d
vim /etc/autofs.d/httpd/httpd -fstype=nfs 172.17.16.169:/httpd
systemctl restart autofs
六、测试
1.php文件放到-服务器C的nfs共享目录中
其中数据库指向服务器B
<?php$mysqli=new mysqli("172.17.17.173","http","httpd");if(mysqli_connect_errno()){echo "连接数据库失败!";$mysqli=null;exit;}echo "连接数据库成功!只能连接mysql";$mysqli->close();
?>
七、注意
一定要关闭防火墙和selinux
这篇关于基于NFS和autofs的LAMP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!