本文共 4264 字,大约阅读时间需要 14 分钟。
3、再通过varnish实现动静分离
注:1、先装Nginx +keepalived
2、装varnish3、装lamp需要6台虚拟机(100-101装Nginx +keepalived:100主,101备)需要联网(102-103装varnish)需要联网(104-105装lamp)需要联网所有主机必做的步骤systemctl stop firewalld //关闭防火墙setenforce 0 //关闭监控
1、装Nginx +keepalived(两台机子都要做的)(100主101备)systemctl stop firewalld //关闭防火墙setenforce 0 //关闭监控cd /etc/yum.repos.d/mv back/* ./
yum install -y epel-release
yum install -y nginx
yum install keepalived -y
vi /etc/keepalived/keepalived.conf(把里面内容全删了添加以下内容)! Configuration File for keepalived global_defs { route_id NGINX-01 }vrrp_script nginx { script "/opt/nginx.sh" interval 2 weight -10}vrrp_instance VI_1 { state MASTER interface ens32 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { nginx } virtual_ipaddress { 192.168.80.188 }}
scp /etc/keepalived/keepalived.conf root@192.168.80.101:/etc/keepalived/keepalived.conf
vi /etc/keepalived/keepalived.conf(修改以下画圈部分)
vi /opt/nginx.sh(添加以下内容)#!/bin/bashA=$(ps -ef | grep keepalived | grep -v grep | wc -l)if [ $A -gt 0 ];then systemctl start nginxelse systemctl sop nginxfi
chmod +x /opt/nginx.shll /opt/nginx.sh
netstat -anpt | grep nginxsystemctl start keepalivednetstat -anpt | grep nginx
ip addr show ens32
vi /opt/nginx.sh(添加以下内容)#!/bin/bashA=$(ip addr | grep 192.168.80.188/32 | grep -v grep | wc -l)if [ $A -gt 0 ];then systemctl start nginx else systemctl stop nginxfi
chmod +x /opt/nginx.shsystemctl start keepalivedcat /var/log/messages
cat /var/log/messages
vi /etc/nginx/nginx.conf(修改以下内容)upstream varnish_pool { server 192.168.80.102:80; server 192.168.80.103:80; }proxy_pass http://varnish_pool;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;
nginx -t
scp /etc/nginx/nginx.conf 192.168.80.101:/etc/nginx/nginx.conf
systemctl restart nginx
2、装varnish(80.102,80.103)(两台机子都需要做)systemctl stop firewalld //关闭防火墙setenforce 0 //关闭监控cd /etc/yum.repos.d/mv back/* ./yum install epel-release -y //需要联网
yum install -y varnish
vi /etc/varnish/varnish.params(修改环圈部分)
vi /etc/varnish/default.vcl(修改添加以下部分)backend web1 { .host = "192.168.80.104"; .port = "80";}backend web2 { .host = "192.168.80.105"; .port = "80";}sub vcl_recv {if (req.url ~ "(?i)\.php$"){ set req.backend_hint = web1;}else{ set req.backend_hint = web2;}
systemctl start varnishnetstat -anpt | grep varnish
vi /etc/varnish/varnish.params(修改以下内容)
scp /etc/varnish/default.vcl 192.168.80.103:/etc/varnish/default.vcl
systemctl start varnishnetstat -anpt | grep varnish
3、装lamp(两台机子都要做的)(100主101备)systemctl stop firewalld //关闭防火墙setenforce 0 //关闭监控cd /etc/yum.repos.d/mv back/* ./安装wgetyum install -y wget
yum install -y httpd
systemctl start httpdsystemctl enable httpd获取rpm软件包:wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
安装rpm包rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装mysqlyum install -y mysql-community-server
启动 systemctl start mysqlsystemctl enable mysql修改root密码并设置允许远程连接进入mysql mysql -uroot
设置root密码为123456set password for 'root'@'localhost' =password('123456');设置允许用root账户进行远程连接,并设置其密码为123456grant all privileges on *.* to root@'%'identified by '123456';修改的配置立即生效flush privileges;退出:exit
部署phpyum install -y php
安装组件是php支持mysql yum install -y \php-mysql \php-gd \libjpeg* \php-ldap \php-odbc \php-pear \php-xml \php-xmlrpc \php-mbstring \php-bcmath \php-mhash
vi /etc/httpd/conf/httpd.conf(修改以下内容)ServerName www.example.com:80去掉#号
systemctl start httpdecho "192.168.80.101
" > /var/www/html/index.php
vi /etc/httpd/conf/httpd.conf(修改以下内容)ServerName www.example.com:80去掉#号
systemctl start httpdecho "192.168.80.102
" > /var/www/html/index.html
转载于:https://blog.51cto.com/14158288/2351758