码迷,mamicode.com
首页 > 数据库 > 详细

编译安装Nginx+Mariadb+Memcache+php实现Nginx与Memcache结合

时间:2014-05-05 12:18:04      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:用户

bubuko.com,布布扣

前端Nginx配置:

1、安装nginx

创建Nginx用户、创建/var/tmp/nginx目录并编译安装

useradd -r nginx
mkdir /var/tmp/nginx
tar xf nginx-1.4.7.tar.gz
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid  --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi make && make install

提供Nginx服务脚本并加到服务列表中有执行权限

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse #               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

  

2、安装php:

首先需要解决以下依赖关系

yum -y install mhash-devel libcurl-devel bzip2-devel gd-devel libxml2-devel

解压缩并编译安装

tar xf php-5.4.26.tar.bz2
cd php-5.4.26
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm  --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl
make && make install

为php提供配置文件、为php-fpm提供Sysv init脚本,并将其添加至服务列表、为php-fpm提供配置文件

cp php.ini-production /etc/php.ini
cp sapi//fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

编辑php-fpm的配置文件

vim /usr/local/php/etc/php-fpm.conf
pid = /usr/local/php/var/run/php-fpm.pid  (修改pid文件路径位置)
error_log = /var/log/php-fpm.log    (启动错误日志功能)
pm.max_children = 50    (设置最大进程为50个)
pm.start_servers = 8    (默认启动5个)
pm.min_spare_servers = 4    (最小空闲进程数)
pm.max_spare_servers = 8    (最大空闲进程数)
pm.max_requests = 500    (最大请求数)
pm.status_path = /status    (启动status状态页面)
ping.path = /ping
ping.response = pong

启动php-fpm并验证9000端口是否打开

service php-fpm start

3、安装Mariadb

创建mysql系统用户、创建mysql数据目录

useradd -r mysql
mkdir /mydata/data -pv
chown -R mysql.mysql /mydata/data/

解压缩源码包并初始化Mariadb

tar xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-10.0.10-linux-x86_64 mysql
chown -R root.mysql mysql/*
scripts/mysql_install_db --datadir=/mydata/data --user=mysql

为Mariadb提供主配置文件及服务脚本

cp support-files/my-large.cnf /etc/mysql/my.cnf
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

测试mysqld能够启动成功,并查看端口是否打开

service mysqld start

4、安装Xcache

 

解压缩并编译安装Xcache

tar xf xcache-3.1.0.tar.bz2
cd xcache-3.1.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install

 

编辑php.ini,整合php和xcache,将xcache提供的样例配置导入php.ini

mkdir /etc/php.d
cp xcache.ini /etc/php.d/

 

编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

 

重新启动php-fpm

service php-fpm restart

 

5、整合nginx和php5

编辑/etc/nginx/nginx.conf,启用如下选项

location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
include        fastcgi_params;
}

 

编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

 

未完待补充

本文出自 “LYD” 博客,请务必保留此出处http://4904702.blog.51cto.com/4894702/1405830

编译安装Nginx+Mariadb+Memcache+php实现Nginx与Memcache结合,布布扣,bubuko.com

编译安装Nginx+Mariadb+Memcache+php实现Nginx与Memcache结合

标签:用户

原文地址:http://4904702.blog.51cto.com/4894702/1405830

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!