一、需求
1.搭建两台LNMP
2.数据库独立
3.文件共享
4.文件实时备份
5.搭建负载均衡
二、环境准备
主机 | ip | 服务 | 角色 |
---|---|---|---|
web01 | 10.0.0.7、172.16.1.7 | nginx、php | 客户端 |
web03 | 10.0.0.9、172.16.1.9 | nginx、php | 客户端 |
db01 | 172.16.1.51 | mariadb | 独立数据库 |
nfs | 172.16.1.31 | rpcbind、nfs-server | NFS服务端 |
backup | 172.16.1.41 | rsyncd | rsyncd服务端 |
lb01 | 10.0.0.4、172.16.1.4 | nginx | 负载均衡 |
三、web01\web03操作
1.安装nginx官方源
#配置官方源
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
#安装
[root@web01 ~]# yum install -y nginx
2.创建用户
[root@web01 ~]# groupadd -g666 www
[root@web01 ~]# useradd -u666 -g666 -M -s /sbin/nologin www
3.修改nginx配置
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;
http {
... ...
client_max_body_size 100M;
charset UTF-8
... ...
}
#启动服务
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx
4.安装php
#上传包
[root@web01 ~]# rz php.tar.gz
#解压包
[root@web01 ~]# tar xf php.tar.gz
#卸载旧版本
[root@web01 ~]# yum remove php-mysql-5.4 php php-fpm php-common -y
#安装本地所有rpm包
[root@web01 ~]# yum localinstall -y *.rpm
5.修改php配置文件
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
user = www
group = www
[root@web01 ~]# vim /etc/php.ini
upload_max_filesize = 100M
post_max_size = 100M
#启动服务
[root@web01 ~]# systemctl start php-fpm
[root@web01 ~]# systemctl enable php-fpm
6.搭建wordpress
#创建目录
[root@web01 ~]# mkdir /code
#上传包并解压
[root@web01 ~]# cd /code
[root@web03 /code]# rz
[root@web03 /code]# tar xf wordpress.tar.gz
#授权
[root@web01 /code]# chown -R www.www /code
#配置nginx文件
[root@web01 /code]# vim /etc/nginx/conf.d/www.blog.com.conf
server {
listen 80;
server_name linux.blog.com;
root /code/wordpress;
location / {
index index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#检测
[root@web01 /code]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#重启服务
[root@web01 /code]# systemctl restart nginx
7.浏览器访问测试
配置本地hosts文件
10.0.0.7 linux.blog.com
#10.0.0.9 linux.blog.com
浏览器输入linux.blog.com
访问成功
8.安装数据库
#安装
[root@web01 ~]# yum install -y mariadb-server
#启动
[root@web01 ~]# systemctl start mariadb
[root@web01 ~]# systemctl enable mariadb
#设置密码