#!/bin/bash
#LNMP+memcached
#memcached是高性能的分布式缓存服务器 用来集中缓存数据库查询结果,减少数据库访问次数,用以提高中动态web应用的响应速度
#LNMP是主流网站搭建架构 即 nginx php linux mariadb
#代理服务器上proxy上安装memcached 最少需要三台 一代理服务 两台后面web 来做高可用 可以试着用代理服务本机做客户端
yum -y install memcached
#安装包
systemctl start memcached
systemctl status memcached
ss -pluatn | grep memcached
#开启服务 查看端口
setenforce 0
firewall-cmd --set-default-zone=trusted
#关闭SELinux、防火墙
yum -y install telnet
#telnet连接服务器测试memcached服务器 可装可不装
vim /usr/local/nginx/conf/nginx.conf
upstream webs {
server 192.168.2.100:80;
server 192.168.2.200:80;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://webs;
root html;
index index.php index.html index.htm;
}
}
#Nginx配置文件中,通过upstream定义后端服务器地址池,默认调度策略为轮询,使用proxy_pass调用upstream定义的服务器地址池:
/usr/local/nginx/sbin/nginx -s reload
重新加载服务
测试页面是否成功 curl http://192.168.4.5/index.html
#!/bin/bash
#在后端web服务上装基础包,搭建LNMP环境 详细的在LNMP环境一健安装有
yum -y install gcc openssl-devel pcre-devel zlib-devel
yum -y install mariadb mariadb-server mariadb-devel
yum -y install php php-mysql
yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
systemctl start mariadb php-fpm
vim /usr/local/nginx/conf/nginx.con
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name;
include fastcgi.conf;
}
#修改配置文件 几个web就要改几次
/usr/local/nginx/sbin/nginx -s reload
#重新加载nginx服务
**vim /usr/local/nginx/html/test.php
这个是测试脚本 测试服务是否成功 有内容显示 firefox http://192.168.2.100/test.php
yum -y install php-pecl-memcache
#后端LNMP服务器上部署Session共享 php-pecl-memcache 是PHP扩展模块
vim /etc/php-fpm.d/www.conf
文件的最后2行
修改前效果如下:
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
#始文件,默认定义Sessoin会话信息本地计算机(默认在/var/lib/php/session)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
修改后效果如下:
php_value[session.save_handler] = memcache
php_value[session.save_path] = “tcp://192.168.2.5:11211”
#Session信息存储在公共的memcached服务器上,主机参数中为memcache(没有d)
#过path参数定义公共的memcached服务器在哪(服务器的IP和端口)
systemctl restart php-fpm
重启服务
#我这里用的是LNMP 如果想用LAMP 可以把nginx服务停掉 然后安装HTTP软件包 然后开启服务 如果HPPD服务开启不了 可能是端口被抢占了 可以查看端口信息
systemctl stop nginx
yum -y install httpd
systemctl restart httpd
ss -ntplu | grep :80