nginx+keepalived+php+memcached+repcached

部署准备:

VIP1      192.168.1.9

VIP2      192.168.1.10

Nginx1     192.168.1.11     nginx php keepalived memcached repcached

Nginx2     192.168.1.12     nginx php keepalived memcached repcached

一、部署nginx1

1.安装nginx

yum -y installpcre-devel zlib-devel openssl-devel

useradd -M -s/sbin/nologin nginx

tar xfnginx-1.6.2.tar.gz

cd nginx-1.6.2

./configure--prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio--with-http_stub_status_module --with-http_ssl_module --with-http_flv_module--with-http_gzip_static_module && make && make install

启动nginx

ln -s/usr/local/nginx/sbin/nginx /usr/local/sbin/

nginx

2.安装php

tar xfphp-5.3.28.tar.gz

cd php-5.3.28

./configure--prefix=/usr/local/php --with-openssl --enable-fpm --enable-sockets --enable-sysvshm  --enable-xml --with-config-file-path=/etc && make && make install

cp/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

启动php-fpm

cd /usr/local/php/

sbin/php-fpm

如果启动报错:

[[email protected]]# sbin/php-fpm

[01-Dec-201600:41:54] ALERT: [pool www] pm.min_spare_servers(0) must be a positive value

[01-Dec-201600:41:54] ERROR: failed to post process the configuration

排错方法:

vim /usr/local/php/etc/php-fpm.conf

把以下几项的注释去掉

pm.start_servers=20

pm.min_spare_servers=5

pm.max_spare_servers=35

如下为启动成功

[[email protected]~]# netstat -antp |grep php-fpm

tcp        0     0 127.0.0.1:9000             0.0.0.0:*                   LISTEN      6337/php-fpm

3.整合nginx、php

修改nginx.conf以支持php

vim /usr/local/nginx/conf/nginx.conf

添加以下红色部分:

server {

listen 80;

server_name localhost;

location / {

root   html;

index index.html index.html;

location ~ \.php$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param SCRIPT_FILENAME  /$document_root$fastcgi_script_name;

include        fastcgi_params;

}

}

创建php测试页

cd /usr/local/nginx/html/

vim index.php

<?php

phpinfo();

?>

重启nginx

killall -9 nginx

nginx

验证:

访问http://192.168.1.11/index.php,出现以下页面

Nginx与php整合成功

4.安装memcached

yum -y install gccopenssl-devel pcre-devel zlib-devel

tar xflibevent-2.0.15-stable.tar.gz

cd libevent-2.0.15-stable

./configure--prefix=/usr/local/libevent && make && make install

tar xfmemcached-1.4.5.tar.gz

cd memcached-1.4.5

./configure--prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/ &&make && make install

vim /etc/ld.so.conf

加入红色内容:

include ld.so.conf.d/*.conf

/usr/local/libevent/lib/

ldconfig

/usr/local/memcached/bin/memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512

选项:

-h       #查看帮助信息

-p       #指定memcached监听的端口号默认11211

-l       #memcached服务器的ip地址

-u       #memcached程序运行时使用的用户身份必须是root用户

-m     #指定使用本机的多少物理内存存数据默认64M

-c      #memcached服务的最大链接数

-vvv  #显示详细信息

-n       #chunk size 的最小空间是多少单位字节

-f      #chunk size大小增长的倍数默认 1.25倍

-d       #在后台启动

检测memcached是否启动:

netstat  -antp| grep :11211

tcp        0     0 0.0.0.0:11211              0.0.0.0:*                   LISTEN      97860/memcached

测试memcached 能否存取数据

yum -y installtelnet

telnet 192.168.1.11 11211

set username 0 08

zhangsan

STORED

get username

VALUE username 0 8

zhangsan

END

quit

Connection closedby foreign host.

Memcached安装成功

5.整合php、memcached

安装php支持memcached模块

需要安装libmemcached客户端库,php的扩展memcached模块,因为该扩展是依赖libmemcached的API

安装libmemcached客户端库

tar xflibmemcached-1.0.18.tar.gz

cd libmemcached-1.0.18

./configure-prefix=/usr/local/libmemcached -with-memcached && make && makeinstall

安装php的扩展memcached模块

tar xfmemcached-2.2.0.tgz

cd memcached-2.2.0

/usr/local/php/bin/phpize   //先使用phpize命令生成一个configure文件

./configure-enable-memcached -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir-with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached--disable-memcached-sasl

make &&make install

记录下安装成功后的提示,类似于:

Installing sharedextensions:    /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

cp /root/php-5.3.28/php.ini-development/etc/php.ini  //在编译安装php时指定配置文件的路径是/etc下

增加扩展extension配置文件

vim /etc/php.ini

添加以下内容:

822 extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

823 extension = "memcached.so"

重启php-fpm:

killall -9 php-fpm

/usr/local/php/sbin/php-fpm

执行php –m命令查看是否加载了memcached模块

/usr/local/php/bin/php–m

访问http://192.168.1.11/index.php出现以下页面

建立测试页面:

vim /usr/local/nginx/html/memcached.php

<?php

session_start();

if(!isset($_SESSION[‘test‘])){

$_SESSION[‘test‘]= time();

}

print$_SESSION[‘test‘];

print"<br><br>";

print"SessionID: " . session_id();

?>

访问http://192.168.1.11/memcached.php出现以下页面

单台nginx+php+memcached存储session信息完成

二、部署nginx2

Nginx2与Nginx1做相同操作

最后访问http://192.168.1.12/memcached.php出现以下页面

三、分别在nginx1和nginx2上安装keepalived实现高可用

在两台nginx上做以下相同操作:

yum -y installkernel-devel openssl-devel

tar xfkeepalived-1.2.13.tar.gz

cd keepalived-1.2.13

./configure--prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-504.el6.x86_64/ &&make && make install

chkconfig --addkeepalived

chkconfig keepalived on

chkconfig --list keepalived

修改nginx1上的keepalived配置文件

vim /etc/keepalived/keepalived.conf

!Configuration File for keepalived

global_defs{

notification_email {

[email protected]

}

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instanceVI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 50

advert_int 1

authentication {

auth_type PASS

auth_pass 123

}

virtual_ipaddress {

192.168.1.9

}

}

vrrp_instanceVI_2 {

state MASTER

interface eth0

virtual_router_id 52

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 123

}

virtual_ipaddress {

192.168.1.10

}

}

修改nginx2上的keepalived配置文件

vim /etc/keepalived/keepalived.conf

!Configuration File for keepalived

global_defs{

notification_email {

[email protected]

}

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instanceVI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 123

}

virtual_ipaddress {

192.168.1.9

}

}

vrrp_instanceVI_2 {

state BACKUP

interface eth0

virtual_router_id 52

priority 50

advert_int 1

authentication {

auth_type PASS

auth_pass 123

}

virtual_ipaddress {

192.168.1.10

}

}

分别启动nginx1和nginx2的keepalived服务

service keepalived start

nginx1的VIP地址为192.168.1.10

nginx2的VIP地址为192.168.1.9

时间: 2024-10-14 20:56:39

nginx+keepalived+php+memcached+repcached的相关文章

nginx+keepalived的高可用负载均衡集群构建

实验架构图: 实验环境 Nginx和Keepalived原理介绍 参考博客:http://467754239.blog.51cto.com/4878013/1541421 1.nginx Nginx进程基于于Master+Slave(worker)多进程模型,自身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发, 从而达到Master进程的存活高可靠性,Slave(worker)进程所有的业务信号都 由主进程发出,Slave(wor

Nginx+Keepalived 实现反代 负载均衡 高可用(HA)配置

Nginx+Keepalived实现反代负载均衡高可用(HA)配置 Nginx+Keepalived实现反代负载均衡高可用配置 OS IP 子网掩码 路由网关 Centos6.6 nginx Keepalived Eth0:192.168.26.210 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6 Nginx Keepalived Eth0:192.168.26.211 255.255.252.0 192.168.25.3 VIP

nginx+keepalived高可用

nginx+keepalived高可用 1.环境如下 lb-01:192.168.75.136/24  nginx+keepalived-master lb-02:192.168.75.137/24  nginx+keepalived-backup VIP:192.168.75.135/24   rs-01:192.168.75.133/24 apache rs-02:192.168.75.13424 apache lb操作系统centos7.rs操作系统ubuntu14.04 2.lb-01/

nginx+keepalived双主高可用负载均衡

实验环境及软件版本:CentOS版本: 6.6(2.6.32.-504.el6.x86_64)nginx版本: nginx-1.6.3keepalived版本:keepalived-1.2.7 主LB1:LB-110-05 主LB2:LB-111-06 一.安装准备及依赖(用SecureCRT的交互窗口同时对两台LB操作,只贴出LB1的操作过程在此) [[email protected] ~]# mkdir tools [[email protected] ~]# mkdir /applicat

【Linux运维-集群技术进阶】Nginx+Keepalived+Tomcat搭建高可用/负载均衡/动静分离的Webserver集群

额.博客名字有点长.. . 前言 最终到这篇文章了,心情是有点激动的. 由于这篇文章会集中曾经博客讲到的全部Nginx功能点.包含主要的负载均衡,还有动静分离技术再加上这篇文章的重点.通过Keepalived实现的HA(High Available).为什么要实现高可用呢?曾经在搭建的时候仅仅用了一台Nginxserver,这种话假设Nginxserver宕机了,那么整个站点就会挂掉.所以要实现Nginx的高可用,一台挂掉还会有还有一台顶上去.从而保证站点能够持续的提供服务. 关于负载均衡和动静

搭建memcached repcached

近期因为生产环境需要调整memcached的缓存模式,之前也考虑换redis,因为可能会涉及到应用程序的调整,所以暂时先考虑上memcached repcached模式. 主节点:10.10.10.164    CentOS6.7_x64 从节点:10.10.10.165    CentOS6.7_x64 1)安装依赖关系(时间服务器也要检查下) [[email protected] src]# yum -y install install g++ make libevent-devel 2)配

Centos7+Nginx+Keepalived实现Apache服务的高可用&负载均衡

Centos7+Nginx+Keepalived实现Apache服务的高可用&负载均衡 今天是2017年的第一天,昨天也就是2016年的最后一天,我尝试部署了Centos7+Nginx+Keepalived实现WEB服务的高可用负载均衡服务,终于在2017年的第一天前完成了,所以在此分享给有需要的朋友:说到负载均衡,其实在linux下有很多服务可以实现,比如nginx.haproxy.lvs等服务,当前我们在前面的文章有介绍过了,但是对于高可用服务,我们在linux下最常见也是应用最多的是Kee

CentOS Linux 负载均衡高可用WEB集群之Nginx+Keepalived配置

Nginx+Keepalived实现负载均衡高可用的WEB服务集群,nginx作为负载均衡器,keepalived作为高可用,当其中的一台负载均衡器(nginx)发生故障时可以迅速切换到备用的负载均衡器(nginx),保持业务的连续性. 1.服务器的环境配置及IP分配 操作系统:CentOS release 6.7 (Final) nginx版本:nginx/1.8.0 keepalived版本:Keepalived v1.2.13 Nginx + keepalived服务器的IP分配表 服务器

Nginx+Keepalived主备切换(包含nginx服务停止)

原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4台CentOS 本机PC充当测试机win8 步骤: 1.搭建 nginx+keepalived主备切换(不考虑主nginx停掉现象)文章中的环境 2.修改两台部署的keepalived的配置文件 3.编写观察nginx进程情况的脚本内容 #!/bin/bash A=`ps -C nginx --no