操作系统:Centos6.3 Mysql版本:5.6.16 PHP版本:5.5.9 Nginx版本:1.2.6 Redis版本:2.8.9 Memcached版本:1.4.5
安装依赖库
yum -y groupinstall "Development tools" yum install -y gcc gcc-c++ make cmake zlib zlib-devel openssh openssl openssl-devel net-snmp pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel xinetd lrzsz dos2unix telnet python-devel mysql-devel libxslt-devel unixODBC-devel sqlite-devel
一.编译安装Mysql
传送门:http://blog.csdn.net/bronze_boy/article/details/29323811
二.编译安装Nginx
1. 检查安装依赖库
2. 添加用户和用户组
groupadd -r nginx useradd -r -g nginx nginx
3. 解压,编译
tar -zxf nginx-1.2.6.tar.gz cd nginx-1.2.6
./configure --prefix=/home/nginx --sbin-path=/home/nginx/sbin/nginx --conf-path=/home/nginx/nginx.conf --error-log-path=/home/nginx/log/error.log --http-log-path=/home/nginx/log/access.log --pid-path=/home/nginx/nginx.pid --lock-path=/home/nginx/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=/home/nginx/client --http-proxy-temp-path=/home/nginx/proxy --http-fastcgi-temp-path=/home/nginx/fcgi --http-uwsgi-temp-path=/home/nginx/uwsgi --http-scgi-temp-path=/home/nginx/scgi --with-pcre=/home/packages/pcre-8.35
注意pcre=的是pcre的源码包路径,不是安装路径
make && make install
4. 为nginx提供sysV init 脚本
vi /etc/rc.d/init.d/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: /home/nginx/nginx.conf # config: /home/nginx/sysconfig # pidfile: /home/nginx/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="/home/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/home/nginx/nginx.conf" [ -f /home/nginx/sysconfig ] && . /home/nginx/sysconfig lockfile=/home/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
5. 修改权限,启动服务
chmod u+x /etc/rc.d/init.d/nginx chkconfig --add nginx chkconfig nginx on service nginx start 启动nginx
6. 错误信息
chown: missing operand after `/home/nginx/client' Try `chown --help' for more information. chown: missing operand after `/home/nginx/proxy' Try `chown --help' for more information. chown: missing operand after `/home/nginx/fcgi' Try `chown --help' for more information. chown: missing operand after `/home/nginx/uwsgi' Try `chown --help' for more information. chown: missing operand after `/home/nginx/scgi' Try `chown --help' for more information. Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind() [FAILED]
解决办法:
更改目录权限:chown -R nginx:nginx /home/nginx
之前安装过apache占用了80端口,vi nginx.conf 修改端口为8999
ok. 再次启动
service nginx start Starting nginx: [ OK ]
三. 编译安装 memcached
安装依赖关系
yum install libevent libevent-devel -y
tar -zxf memcached-1.4.5.tar.gz cd memcached-1.4.5 ./configure --prefix=/home/memcached make && make install
配置环境变量
vi etc/profile PATH=/home/memcached/bin:$PATH export PATH
激活环境变量
source /etc/profile
开启memcached
memcached -d -m 10 -u root -p 11211 -c 1024 -P /home/memcached/memcached.pid
上面的参数意思是 启动一个守护进程 分配了10M存储,用root开启,端口11211 最大同时并发链接1024个
设置开机启动
echo "memcached -d -m 10 -u root -p 11211 -c 1024 -P /home/memcached/memcached.pid" >> /etc/rc.loacl
关闭memcached :
kill cat /home/memcached/memcached.pid
四. 编译安装PHP
1. 安装libmcrypt
tar -zxf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure --prefix=/home/rely/libmcrypt make && make install
2. 编译php
./configure --prefix=/home/php --with-config-file-path=/home/php/etc --with-mysql=/home/mysql --with-mysqli=/home/mysql/bin/mysql_config --with-mysql-sock=/home/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-mcrypt=/home/rely/libmcrypt/
编译通过,但是报警告:
configure: WARNING: unrecognized options: --enable-magic-quotes, --enable-safe-mode, --with-curlwrappers
这是新版本的php已经不再支持这几个选项,默认就是开启的
删掉这三个配置选项重新编译 。
./configure --prefix=/home/php --with-config-file-path=/home/php/etc --with-mysql=/home/mysql --with-mysqli=/home/mysql/bin/mysql_config --with-mysql-sock=/home/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-mcrypt=/home/rely/libmcrypt/
ok.Thank for using php
注意:
如果写成 --with-libmcrypt=/....... 就会报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt
make报错:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
这是因为虚拟内存不够 ....configure的时候加上 –disable-fileinfo
编译又报错:configure: error: /bin/sh ./config.sub disable-fileinfo failed
free -m 查看内存使用情况,swap直接是0.....找个地方建块虚拟内存吧
dd if=/dev/zero of=/tmp/big_swap bs=1024 count=100000 #这个意思是输出到 /tmp/big_swap 每一块1024B=1K,总共100000块
du -sh /tmp/big_swap #查看是否符合要求
ls -al /tmp/big_swap
mkswap /tmp/big_swap 设为swap分区文件
swapon big_swap 立即启用交换分区文件
free -m 查看一下现在的内存使用情况,一切正常
total used free shared buffers cached Mem: 994 924 70 0 2 372 -/+ buffers/cache: 548 446 Swap: 1953 0 1953
设置开机启动..... vi/etc/fstab
添加 swap /tmp/big_swap swap defaults 0 0
注意:增加虚拟内存别太大了,太多会导致系统错误
到php资源目录下,make && make install
终于ok了,到/home/php/etc 目录下 cp php-fpm.conf.default php-fpm.conf
开启 /home/php/sbin/php-fpm -c /home/php/etc/php-fpm.conf
注意修改 php.ini后要记得重启 php-fpm 停止php-fpm kill -INT PID
在php的源码目录 cp php.ini-production /home/php/etc
添加一个软连接:ln -s /home/php/etc/php.ini /etc/php.ini
关于 Nginx跟php怎么整合就不解释了.....
五. 编译安装redis
下载最新稳定版本 2.8.9 http://www.redis.cn/download.html
tar -zxf redis-2.8.9.tar.gz cd redis-2.8.9 make make PREFIX=/home/redis install vi /home/redis/redis.conf 简单配置,完成
动态加载 phpredis 模块,整合php跟redis
tar -zxvf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz phpredis cp phpredis /usr/include/php/ext/ (将文件拷贝至php源码目录的ext目录中) /home/php/bin/phpize (运行phpize,如果不知道在哪里,可以用whereis phpize命令) cd /home/php/include/php/ext/phpredis/ ./configure –with-php-config=/usr/bin/php-config (注意自己的php-config路径) make && make install
如果报错找不到 config.m4 find / -name config0.m4
找到 config0.m4 重命名
cp config0.m4 config.m4
再次编译安装
完成后修改 php.ini 添加 extension=redis.so 还有 extension_dir 必要的时候也需要修改
ok. kill -INT **** ./php-fpm -y /home/php/etc/php-fpm.conf service nginx restart 重启服务器
用php页面测试
$redis = new Redis(); $redis->set("aa","zzzzz"); echo $redis->get("aa");
用浏览器访问,页面输出zzzzz