Linux 2.6+ centos 5.5

一、获取相关开源程序:
所需软件:

yum -y install gcc gcc-c++ bzip2 make vixie-cron flex ncurses-devel wget patch ntp libxml2 libxml2-devel libevent m4 autoconf zip unzip gd freetype gettext-devel

eaccelerator-0.9.6.tar.bz2
mysql-5.1.51.tar.gz
php-5.2.14.tar.bz2
php-fpm-0.6-5.2.11.tar.gz
ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
nginx-0.7.62.tar.gz
pcre-7.9.tar.gz

===========================

安装之前要确保系统中安装了以下这些包。
我们可以用rpm -qa |grep 来查看系统是否装

bzip2-devel
zlib-devel
libjpeg-devel
libpng-devel
libtiff-devel
freetype-devel
openssl-devel
libxml2-devel
gettext-devel

二、安装MYSQL

# tar -zxvf mysql-5.1.51.tar.gz
# cd mysql-5.1.51
# useradd -s /sbin/nologin -M mysql
useradd -s /sbin/nologin -M -u 78 www
useradd -s /sbin/nologin -M -u 112 ftpacc

# ./configure –prefix=/usr/local/www/mysql
–with-charset=utf8
–with-collation=utf8_general_ci
–with-extra-charsets=all
–enable-thread-safe-client –without-debug
–with-mysqld-ldflags=-all-static
–with-client-ldflags=-all-static
–without-embedded-server
–with-server-suffix=-community
–with-unix-socket-path=/tmp/mysql.sock   
–with-mysqld-user=mysql
–enable-local-infile
–with-big-tables
–with-plugins=csv,innobase,myisam,partition
–with-readline

# make && make install
# cp support-files/my-medium.cnf   /etc/my.cnf
# chown -R mysql.mysql /usr/local/www/mysql/

mysql 初始化安装

# /usr/local/www/mysql/bin/mysql_install_db
–defaults-file=/etc/my.cnf
–basedir=/usr/local/www/mysql
–datadir=/backup/data
–user=mysql

启动数据库服务,并添加到自启动

# /usr/local/www/mysql/bin/mysqld_safe –user=mysql &
# netstat -ant

查看3306端口

加入自动启动服务队列:

# cp   support-files/mysql.server   /etc/rc.d/init.d/mysqld
# chmod   755   /etc/rc.d/init.d/mysqld
# chkconfig –add mysqld
# chkconfig mysqld on

# vi /etc/init.d/mysqld

basedir=/usr/local/www/mysql
datadir=/backup/data

添加root密码

# /usr/local/www/mysql/bin/mysqladmin -u root password "123456"

测试一下:

# /usr/local/www/mysql/bin/mysql -u root -p

输入密码:123456,看能不能进入到数据库

远程连接数据库用户
grant all on *.* to "zmkm"@"%" identified by "31415926";

配置库文件搜索路径

# echo "/usr/local/www/mysql/lib/mysql">>/etc/ld.so.conf
# ldconfig
# ldconfig -v
# echo "export PATH=$PATH:/usr/local/www/mysql/bin">>/etc/profile
# source /etc/profile

三、安装PHP

# tar -zxvf libiconv-1.13.1.tar.bz2
# cd libiconv-1.13.1/
# ./configure –prefix=/usr/local/www/libiconv
# make && make install
# ln -sv /usr/local/www/libiconv/lib/libiconv.* /usr/lib/

# tar -jxvf libmcrypt-2.5.8.tar.bz2
# cd libmcrypt-2.5.8/
# ./configure
# make && make install
# /sbin/ldconfig
# cd libltdl/
# ./configure –enable-ltdl-install
# make && make install

# tar -jxvf mhash-0.9.9.9.tar.bz2
# cd mhash-0.9.9.9/
# ./configure
# make && make install

# ln -sv /usr/local/lib/libmcrypt.* /usr/lib/
# ln -sv /usr/local/lib/libmhash.* /usr/lib/
# ln -sv /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8/
# /sbin/ldconfig
# ./configure –prefix=/usr/local/www/mcrypt
# make && make install

# tar zxvf libevent-1.4.13-stable.tar.gz
# cd libevent-1.4.13-stable/
# ./configure –prefix=/usr/local/www/libevent
# make && make install

# tar tar -jxvf php-5.2.17.tar.bz2
# gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
# ./configure –prefix=/usr/local/www/php
–with-config-file-path=/usr/local/www/php/etc/
–with-mysql=/usr/local/www/mysql/
–with-mysqli=/usr/local/www/mysql/bin/mysql_config
–with-gd –enable-ftp –with-bz2
–with-jpeg-dir  –with-png-dir
–with-zlib-dir –with-ttf –with-zlib
–with-freetype-dir –enable-gd-native-ttf
–enable-gd-jis-conv  –with-xpm-dir
–with-gettext –enable-fastcgi –enable-fpm
–enable-xml –enable-force-cgi-redirect
–disable-rpath –enable-bcmath
–enable-shmop –enable-sysvsem
–enable-inline-optimization –with-curl
–with-curlwrappers –enable-mbregex
–enable-zip –enable-mbstring
–enable-pcntl –enable-sockets
–enable-soap –without-pear
–with-iconv-dir=/usr/local/www/libiconv
–disable-debug –disable-ipv6
–with-mhash  –with-fpm-conf=/usr/local/www/php/etc/php-fpm.conf
–with-mcrypt=/usr/local/www/mcrypt

# make ZEND_EXTRA_LIBS=’-liconv’
# make ZEND_EXTRA_LIBS=’-liconv’ install

# cp php.ini-dist /usr/local/www/php/etc/php.ini
# vi /etc/php-fpm.conf

==================
(1)<value name="listen_address">127.0.0.1:9000</value>
修改为<value name="listen_address">IP:9000</value>   //本机就用默认的127.0.0.1
(2)下面这两行去掉注释并修改                     
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
(3)<value name="user">nobody</value> //去注释
(4)<value name="group">nobody</value>   //去注释
(5)<value name="allowed_clients">127.0.0.1</value> //允许连接的PC,本机就用127.0.0.1
(6)<value name="max_children">128</value>
(7)<value name="StartServers">20</value>
(8)<value name="MinSpareServers">5</value>
(9)<value name="MaxSpareServers">35</value>
(10)<value name="rlimit_files">51200</value>
(11)<value name="max_requests">102400</value>

启动php-fpm
# ulimit -SHn 51200
# /usr/local/www/php/sbin/php-fpm start

注:/usr/local/www/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

添加到自启动
# echo "ulimit -SHn 51200">>/etc/rc.local
# echo "/usr/local/www/php/sbin/php-fpm start">>/etc/rc.local

通过命令查看服务器上一共开了多少的 php-cgi 进程
# ps -fe |grep "php" | grep -v "grep" | wc -l

使用如下命令查看已经有多少个php-cgi进程用来处理tcp请求
# netstat -anop | grep "php&q
uot; | grep -v "grep" | wc -l
接近配置文件中设置的数值,表明worker进程数设置太少

四、安装nginx

1.安装 pcre

# tar zxvf pcre-8.10.tar.gz
# cd pcre-8.10
# ./configure
# make && make install

2、安装nginx

# tar zxvf nginx-0.8.52.tar.gz
# cd nginx-0.8.52
# groupadd www
# useradd -g www -s /sbin/nologin -M www
# ./configure –with-http_stub_status_module
–with-http_ssl_module
–with-http_realip_module
–prefix=/usr/local/www/nginx
–user=www –group=www

# make && make install

==================

注:伪装服务器

# vi src/core/nginx.h

#define NGINX_VERSION      "1.8"
#define NGINX_VER          "Yahunet/" NGINX_VERSION

# vi src/http/ngx_http_header_filter_module.c

static char ngx_http_server_string[] = "Server: nginx" CRLF;

# vi src/http/ngx_http_special_response.c

static u_char ngx_http_error_full_tail[] =
"<hr><center>http://bbs.yahunet.com</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"<hr><center>Yahunet</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

修改nginx的配置文件
我这里是把原先的重命名然后新建了一个nginx.conf

user  www;
worker_processes  8;
pid  logs/nginx.pid;

worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}

http{
include       mime.types;
default_type  application/octet-stream;

access_log  off;
error_log  /dev/null;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
server_tokens off;
tcp_nopush     on;

keepalive_timeout 120;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

tcp_nodelay on;

gzip on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types       text/plain application/x-javascript text/css application/xml;
gzip_vary on;

include vhost/*.conf;

}

vhost/www.test.com.conf的内容

server
     {
     listen  80;
     server_name    www.test.com;
     index index.html index.htm index.php;
     root    /var/www/bbs/;

     location ~ .*.(php|php5)?$ {
         root           html;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index   index.php;
         fastcgi_param   SCRIPT_FILENAME   /var/www/bbs$fastcgi_script_name;
         include         fastcgi_params;
       }

error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

}

五、安装PHP扩展

1、安装eaccelerator加速软件

eaccelerator是php的加速软件,使用后php的执行效率会有很大幅度的提升。

# tar jxvf eaccelerator-0.9.5.3.tar.bz2
# cd eaccelerator-0.9.5.3
# /usr/local/www/php/bin/phpize
# ./configure –enable-eaccelerator=shared
–with-php-config=/usr/local/www/php/bin/php-config
# make && make install

编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,php5.2.x系列是在/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613,记住这个路径,待会要用到

修改php.ini

# vi /usr/local/www/php/php.ini

安装php扩展
在文件最后,[zend]之前,注意,这部分内容务必放在[zend]之前,不然可能会出现不可预期的服务器问题。添加下列信息:

[eaccelerator]
zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="1800"
eaccelerator.shm_prune_period="1800"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

重启apache然后在IE还是那个php测试页,zend哪又有没有变化如没有,说明这种方法没有好用。

# mkdir /tmp/eaccelerator
# chmod 777 /tmp/eaccelerator

在浏览器中打开phpinfo()那个测试页,如果出现以下内容,证明安装成功!

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator

2、安装Zend

# tar zxvf ZendOptimizer-3.3.9-linux-glibc21-i386.tar.gz
# cd ZendOptimizer-3.3.9-linux-glibc23-i386
# cp data/5_2_x_comp/ZendOptimizer.so /usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/

# vi /usr/local/php/php.ini
添加一行
zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so"

我们再输入IE看那个测试页Zend是否加载成功。
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

3、安装PDO_MYSQL

# tar zxvf PDO_MYSQL-1.0.2.tgz
# cd PDO_MYSQL-1.0.2/
# /usr/local/www/php/bin/phpize
# ./configure –with-php-config=/usr/local/www/php/bin/php-config
–with-pdo-mysql=/usr/local/www/mysql
# make && make install

# vi /usr/local/php/php.ini
添加一行
zend_extension="/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so"

4、安装memcach
e

# tar -zxvf memcache-3.0.6.tgz
# cd memcache-3.0.6
# /usr/local/www/php/bin/phpize
# ./configure –with-php-config=/usr/local/www/php/bin/php-config
# make && make install

5、安装ImageMagickcd

# tar -jxvf ImageMagick-6.6.8-10.tar.bz2
# cd ImageMagick-6.6.8-10
# ./configure
# make
# make install

# tar -zxvf imagick-3.1.0b1.tgz
# cd imagick-3.1.0b1
# /usr/local/www/php/bin/phpize
# ./configure –with-php-config=/usr/local/www/php/bin/php-config
# make
# make install

修改php.ini文件
手工修改:查找/usr/local/www/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension_dir = "/usr/local/www/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

再查找output_buffering = Off
修改为output_buffering = On

再查找; cgi.fix_pathinfo=0
修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。

六、把Nginx和PHP加到系统服务

# vi /etc/rc.d/init.d/nginx

#!/bin/bash
# Startup script for the nginx Web Server
# chkconfig: – 85 15
# description: nginx is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: nginx
# pidfile: /usr/local/www/nginx/logs/nginx.pid
# config: /usr/localcd ../www/nginx/conf/nginx.conf
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
NGINX_HOME=/usr/local/www/nginx/sbin
NGINX_CONF=/usr/local/www/nginx/conf
PHP_HOME=/usr/local/www/php/sbin
if [ ! -f "$NGINX_HOME/nginx" ]
then
    echo "nginxserver startup: cannot start"
    exit
fi
case "$1" in
    ‘start’)
        $PHP_HOME/php-fpm start
        $NGINX_HOME/nginx -c $NGINX_CONF/nginx.conf
        echo "nginx start successful"
        ;;
    ‘stop’)
        killall -TERM php-cgi
        killall -TERM nginx
        ;;
    ‘restart’)
        $PHP_HOME/php-fpm restart
        ;;
    ‘reload’)
        $NGINX_HOME/nginx -s reload
        ;;
esac

# chmod a+x /etc/rc.d/init.d/nginx
# chkconfig –add nginx
# chkconfig nginx on

Linux下的Memcached安装

最近在研究怎么让Discuz!去应用Memcache去做一些事情,记录下Memcache安装的过程。

详细的方法如下:

一、安装memcached

安装memcached,同时需要安装中指定libevent的安装位置:

# tar -zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure –prefix=/usr/local/www/memcached –with-libevent=/usr/local/www/libevent
# make
# make install

二、memcached的基本设置:

1.启动Memcache的服务器端:
/usr/local/www/memcached/bin/memcached  -d -m 256 -u root -l 127.0.0.1  -c 256 -P /tmp/memcached.pid

-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.2.185,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

2.如果要结束Memcache进程,执行:

# kill `cat /tmp/memcached.pid`

发表评论

电子邮件地址不会被公开。 必填项已用*标注