→→→大虾好吃吗←←←
目录
→→→大虾好吃吗←←←
实验目标:搭建lnmp平台,安装wordpress论坛搭建nfs,客户端通过调度器访问nfs论坛。
实验拓扑图如下:
web1:192.168.1.4
web2:192.168.1.5
mysql:192.168.1.6
php:192.168.1.7
1.web1安装操作
- [root@nginx1 ~]# rpm -ivh /media/nginx-rpm/* --nodeps --force
-
- [root@nginx1 ~]# systemctl start nginx
-
- [root@nginx1 ~]# systemctl enable nginx
2.web2安装操作
- [root@nginx2 ~]# rpm -ivh /media/nginx-rpm/* --nodeps --force
-
- [root@nginx2 ~]# systemctl start nginx
-
- [root@nginx2 ~]# systemctl enable nginx
3.mysql安装操作
- [root@mysql ~]# rpm -ivh /media/mysql5.6-rpm/* --nodeps --force
-
- [root@mysql ~]# systemctl start mysqld
-
- [root@mysql ~]# systemctl enable mysqld
-
- [root@mysql ~]# mysqladmin -uroot password
-
- New password: //输入新密码
-
- Confirm new password: //输入新密码
4.php安装操作
- [root@php ~]# rpm -ivh /media/php-rpm/* --nodeps --force
-
- [root@php ~]# systemctl start php-fpm
-
- [root@php ~]# systemctl enable php-fpm
1.安装论坛
- [root@nginx1 ~]# cp -rp /media/wordpress-4.9.4-zh_CN.zip /
-
- [root@nginx1 ~]# cd /
-
- [root@nginx1 /]# unzip wordpress-4.9.4-zh_CN.zip
-
- [root@nginx1 /]# chmod -R 777 wordpress
2.nginx1编辑配置文件
- [root@nginx1 ~]# cd /etc/nginx/conf.d/
-
- [root@nginx1 conf.d]# rm -rf default.conf //删除默认文件
-
- [root@nginx1 conf.d]# vim blog.conf
-
- server {
-
- listen 80;
-
- server_name www.blog.com;
-
- root /wordpress;
-
- index index.php index.html;
-
-
-
- location ~ \.php$ {
-
- root /wordpress;
-
- fastcgi_pass 192.168.1.7:9000; //指定新的PHP主机IP
-
- fastcgi_index index.php;
-
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
- include fastcgi_params;
-
- }
-
- }
-
- [root@nginx1 conf.d]# systemctl restart nginx
-
- [root@nginx1 conf.d]# scp -rp blog.conf root@192.168.1.5:/etc/nginx/conf.d/
3.nginx2配置
- [root@nginx2 ~]# rm -rf /etc/nginx/conf.d/default.conf //删除默认配置文件
-
- [root@nginx2 ~]# systemctl restart nginx
-
- [root@nginx2 ~]# scp -rp root@192.168.1.4:/wordpress /
创建数据库并创建用户。
- [root@mysql ~]# mysql -uroot -p123
-
- //省略部分内容
-
- mysql> create database blog;
-
- Query OK, 1 row affected (0.00 sec)
-
-
-
- mysql> grant all on blog.* to lisi@'%' identified by '123456';
-
- Query OK, 0 rows affected (0.00 sec)
- [root@php ~]# vim /etc/php-fpm.d/www.conf //修改下面两行
-
- listen = 192.168.1.7:9000 //监听php主机
-
- listen.allowed_clients = 192.168.1.4,192.168.1.5 //允许监听的主机
-
- [root@php ~]# systemctl restart php-fpm
-
- [root@php ~]# scp -rp root@192.168.1.4:/wordpress / //复制nginx1安装的论坛到PHP根目录下
现在访问192.168.1.4或者192.168.1.5应都可以看到下面的安装页面,点击现在就开始!。
输入数据库信息点击提交,完成后点击现在安装。
添加站点信息,管理员用户密码,邮箱等。
下面登录刚创建好的admin用户,就可以看到论坛首页,这样用户可以根据需求添加修改自己的论坛了。
1.nfs安装操作
- [root@nfs ~]# yum -y install nfs-utils rpcbind
-
- [root@nfs ~]# systemctl start nfs rpcbind
-
- [root@nfs ~]# systemctl enable nfs rpcbind
2.调度器安装操作
- [root@nginx_lb ~]# rpm -ivh /media/nginx-rpm/* --nodeps --force
-
- [root@nginx_lb ~]# systemctl start nginx
-
- [root@nginx_lb ~]# systemctl enable nginx
1.nfs服务器
- [root@nfs ~]# mkdir -p /nfs/blog //创建挂载点
-
- [root@nfs ~]# vim /etc/exports //发布共享目录
-
- /nfs/blog 192.168.1.0/24(rw,sync,no_root_squash)
-
- [root@nfs ~]# systemctl restart nfs rpcbind //重启服务
2.nginx服务器验证
- [root@nginx1 ~]# showmount -e 192.168.1.8
-
- Export list for 192.168.1.8:
-
- /nfs/blog 192.168.1.0/24
3.挂载nfs服务器盘
(1)nginx1挂载
- [root@nginx1 ~]# cd /wordpress/
-
- [root@nginx1 wordpress]# scp -rp wp-content/* root@192.168.1.8:/nfs/blog/ //把网站首页复制到nfs服务器中
-
- [root@nginx1 wordpress]# mount -t nfs 192.168.1.8:/nfs/blog wp-content //挂载nfs服务器
(2)nginx2挂载
- [root@nginx2 ~]# cd /wordpress/
-
- [root@nginx2 wordpress]# mount -t nfs 192.168.1.8:/nfs/blog wp-content
(3)php挂载
- [root@php ~]# cd /wordpress/
-
- [root@php wordpress]# mount -t nfs 192.168.1.8:/nfs/blog wp-content
- [root@nginx_lb ~]# cd /etc/nginx/conf.d/
-
- [root@nginx_lb conf.d]# rm -rf default.conf
-
- [root@nginx_lb conf.d]# vim lb.conf
-
- upstream webcluster {
-
- server 192.168.1.4:80;
-
- server 192.168.1.8:80;
-
- }
-
- server {
-
- listen 80;
-
- server_name www.blog.com;
-
-
- location / {
-
- proxy_pass http://webcluster;
-
- proxy_set_header Host $http_host;
-
- proxy_set_header X-Real-IP $remote_addr;
-
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
- }
-
- }
-
- [root@nginx_lb conf.d]# systemctl restart nginx
浏览器访问192.168.1.10,此时已经可以看到论坛页面了。
使用nginx1和nginx2分别动态查看nginx访问日志。
[root@nginx1 ~]# tail -f /var/log/nginx/access.log
[root@nginx2 ~]# tail -f /var/log/nginx/access.log