FreeBSD下NGINX 1.8+PHP5.6 +PERL 5.20 +Mysql 5.6+FTP 环境搭建与优化

FreeBSD下NGINX 1.8+PHP5.6 +PERL 5.20 +Mysql 5.6+FTP 环境搭建与优化

为什么选择FreeBSD做为os,这里不再讲,具体可以看这里《Free BSD,Linux之比较》

附件提供了已做了优化后的配置文件,下载直接可以使用。

#安装perl 支持
--------------------------------------
cd /usr/ports/lang/perl5.20 && make config

#安装完以后发现新版本的5.20的perl改变了目录,这里做个链接。
ln -s /usr/local/bin/perl /usr/bin/perl

#安装perl支持组件(perl on nginx)
cd /usr/ports/databases/rrdtool && make install clean
cd /usr/ports/databases/p5-DBD-mysql && make install clean
cd /usr/ports/devel/p5-File-Tail && make install clean
cd /usr/ports/devel/p5-Time-HiRes && make install clean
cd /usr/ports/graphics/p5-GD && make install clean
cd /usr/ports/sysutils/p5-Unix-Syslog && make install clean
cd /usr/ports/www/p5-LWP-UserAgent-WithCache && make install clean
cd /usr/ports/dns/p5-Net-DNS && make install clean
cd /usr/ports/security/p5-Digest-HMAC && make install clean
cd /usr/ports/security/p5-Digest-MD5 && make install clean
cd /usr/ports/security/p5-Digest-Perl-MD5 && make install clean
cd /usr/ports/security/p5-Digest-SHA1 && make install clean
cd /usr/ports/net-mgmt/p5-Net-IP && make install clean
cd /usr/ports/lang/p5-ExtUtils-F77 && make install clean
cd /usr/ports/www/p5-FCGI && make install clean
cd /usr/ports/www/p5-FCGI-ProcManager && make install clean
--------------------------------------

#安装nginx(组件根据自已需要勾选)
--------------------------------------
cd /usr/ports/www/nginx && make config

#安装php 5.6 on nginx(组件根据自已需要勾选)
cd /usr/ports/lang/php56 && make config

#安装php 5.6的扩展库(组件根据自已需要勾选)
cd /usr/ports/lang/php56-extensions && make config

#安装php常用的支持库
cd /usr/ports/databases/php5-redis && make install clean
cd /usr/ports/databases/pecl-memcache && make install clean
cd /usr/ports/graphics/ImageMagick && make install clean
cd /usr/ports/graphics/pecl-imagick && make install clean
cd /usr/ports/graphics/php-magickwand && make install clean

#安装常用的缓存及数据服务
cd /usr/ports/databases/redis && make install clean
cd /usr/ports/databases/memcached && make install clean
cd /usr/ports/www/xcache && make install clean
cd /usr/ports/databases/mysql56-client && make install clean
--------------------------------------

#将服务加入开机启动项
--------------------------------------
vi /etc/rc.conf

#############################
sendmail_enable=”NO”
sendmail_submit_enable=”NO”
sendmail_outbound_enable=”NO”
sendmail_msp_queue_enable=”NO”
############################
mysql_enable=”YES”
memcached_enable=”YES”
redis_enable=”YES”
############################
php_fpm_enable=”YES”
perl_fcgi_enable=”YES”
nginx_enable=”YES”
############################
pureftpd_enable=”YES”

#先启动redis和memcached服务,这两个无需配置,默认即可。
/usr/local/etc/rc.d/redis restart
/usr/local/etc/rc.d/memcached restart
--------------------------------------

#配置nginx
--------------------------------------
#下载配置脚本:附件 nginx-config.zip
#解压后获取文件(vhosts_params、nginx.conf、mime.types、fastcgi_params、domain.com)

目录结构

nginx /

|—— vhosts_params
|—— nginx.conf
|—— mime.types
|—— fastcgi_params
|——……..
|——vhosts
|——domain.com
|——……

#将 vhosts_params、nginx.conf、mime.types、fastcgi_params 文件移动到如下目录
mv vhosts_params /usr/local/etc/nginx/
mv fastcgi_params /usr/local/etc/nginx/
mv nginx.conf /usr/local/etc/nginx/
mv mime.types /usr/local/etc/nginx/

#然后进入nginx下建立 vhosts 目录
#vhosts目录以后放置 虚拟站点的配置文件
cd /usr/local/etc/nginx/
mkdir vhosts

#将 domain.com 移动到 /usr/local/etc/nginx/vhosts/ 目下
mv domain.com /usr/local/etc/nginx/vhosts/

#有关domain.com 的配置说明
server
{
listen 80;
#server_name _; #这个是所有域名均可访问
server_name abc.domain.com; #这个是指定域名访问

index index.html index.htm index.php index.cgi;
root /usr/local/www/abc.domain.com; #网站文件的目录位置

include vhosts_params;
}

#有关 vhosts_params文件的说明
#vhosts_params 文件是我建立的一个配置文件,主要方便后面做多个虚拟主机时可以快速的引用。

location ~* ^.+.gzjs$ { #支持对js、css等脚本的压缩
add_header Content-Encoding gzip;
gzip off;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #将图片文件本地缓存30天
expires 30d;
}

location ~ .*\.(js|css)?$ { #将js css文件本地缓存30天
expires 1h;
}

location ~ \.php$ { #php-fcgi的配置,支持php文件
gzip off;
fastcgi_pass unix:/var/run/php-fcgi.sock;
fastcgi_index index.php;
include fastcgi_params;
# fastcgi_cache ngx_fcgi_cache;
# fastcgi_cache_key $scheme$request_method$host$request_uri;
}

location ~ .*\.(pl|cgi)?$ { #perl-fcgi的配置,支持cgi pl文件
gzip off;
fastcgi_pass unix:/var/tmp/perl-fcgi.sock;
fastcgi_index index.cgi;
include fastcgi_params;
# fastcgi_cache ngx_fcgi_cache;
# fastcgi_cache_key $scheme$request_method$host$request_uri;
}

location ~ ^/nginxstatus/ { #打开nginxstatus状态显示
stub_status on;
}

error_page 404 = /404/; #定义404错误的信息

--------------------------------------

#配置nginx支持 php
--------------------------------------
#下载配置脚本:附件 php-config.zip
#替换原有的配置文件
mv php-fpm.conf /usr/local/etc/
mv php.ini /usr/local/etc/

#启动nginx和php-fpm
/usr/local/etc/rc.d/php-fpm restart
/usr/local/etc/rc.d/nginx restart

vi /usr/local/www/domain.com/phptest.php

#访问查看php情况:http://domain.com/phptest.php

--------------------------------------

阅读更多

lvs+keepalived+nginx实现高性能负载均衡集群

一、为什么要使用负载均衡技术?

1、系统高可用性

2、  系统可扩展性

3、  负载均衡能力

LVS+keepalived能很好的实现以上的要求,LVS提供负载均衡,keepalived提供健康检查,故障转移,提高系统的可用性!采用这样的架构以后很容易对现有系统进行扩展,只要在后端添加或者减少realserver,只要更改lvs的配置文件,并能实现无缝配置变更!

二、LVS+Keepalived介绍

1、  LVS

LVS是一个开源的软件,可以实现LINUX平台下的简单负载均衡。LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器。目前有三种IP负载均衡技术(VS/NAT、VS/TUN和VS/DR);八种调度算法(rr,wrr,lc,wlc,lblc,lblcr,dh,sh)。

2、  keepalived

Keepalived 是运行在lvs 之上,它的主要功能是实现真实机的故障隔离及负载均衡器间的失败切换,提高系统的可用性

三、环境:

四台服务器,系统全为CentOS6.8:

192.168.2.203 master lvs+keepalived

192.168.2.202 backup lvs+keepalived

192.168.2.204 web1(nginx)

192.168.2.205 web2 (nginx)

vip:192.168.2.13

其中nginx已预装好,这里不再写搭建过程

 

四、搭建并配置

1、分别在backup lvs和master lvs上安装lvs

1 root@bogon src]# yum -y install ipvsadm

2 已加载插件:fastestmirror

3 设置安装进程

4 Determining fastest mirrors

5 epel/metalink                                                                                   | 5.4 kB     00:00

6  * base: mirror.lzu.edu.cn

7 … …

8 已安装:

9   ipvsadm.x86_64 0:1.26-4.el6

10

11 作为依赖被安装:

12   libnl.x86_64 0:1.1.4-2.el6

13

14 完毕!

2、把ipvsadm模块加载进系统

1 [root@bogon src]# ipvsadm

2 IP Virtual Server version 1.2.1 (size=4096)

3 Prot LocalAddress:Port Scheduler Flags

4   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

5 [root@bogon src]# lsmod | grep ip_vs

6 ip_vs                 126897  0

7 libcrc32c               1246  1 ip_vs

8 ipv6                  336282  270 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

3、分别在backup lvs和master lvs上安装keepalived(keepalived官网:http://www.keepalived.org/)

[root@bogon src]# tar zxf keepalived-1.2.24.tar.gz

[root@bogon src]# cd keepalived-1.2.24

[root@bogon keepalived-1.2.24]# ./configure –sysconf=/etc –with-kernel-dir=/lib/modules/2.6.32-642.3.1.el6.x86_64/

报错:

configure: error:

!!! OpenSSL is not properly installed on your system. !!!

!!! Can not include OpenSSL headers files.            !!!

系统缺少openssl-devel包所致

安装openssl-devel

root@bogon keepalived-1.2.24]# yum -y install openssl-devel

再次编辑安装

[root@bogon keepalived-1.2.24]# ./configure –sysconf=/etc –with-kernel-dir=/lib/modules/2.6.32-642.3.1.el6.x86_64/

Keepalived configuration

————————

Keepalived version       : 1.2.24

Compiler                 : gcc

Preprocessor flags       : -I/lib/modules/2.6.32-642.3.1.el6.x86_64//include

Compiler flags           : -Wall -Wunused -Wstrict-prototypes

Linker flags             :

Extra Lib                : -ldl -lssl -lcrypto

Use IPVS Framework       : Yes

IPVS use libnl           : No

IPVS syncd attributes    : No

IPVS 64 bit stats        : No

fwmark socket support    : Yes

Use VRRP Framework       : Yes

Use VRRP VMAC            : Yes

Use VRRP authentication  : Yes

With ip rules/routes     : Yes

SNMP keepalived support  : No

SNMP checker support     : No

SNMP RFCv2 support       : No

SNMP RFCv3 support       : No

SHA1 support             : No

Use Debug flags          : No

Stacktrace support       : No

Memory alloc check       : No

libnl version            : None

Use IPv4 devconf         : No

Use libiptc              : No

Use libipset             : No

Build genhash            : Yes

Build documentation      : No

阅读更多