Chinaunix首页 | 论坛 | 博客
  • 博客访问: 405714
  • 博文数量: 60
  • 博客积分: 1082
  • 博客等级: 上士
  • 技术积分: 648
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-24 18:24
个人简介

奋斗的人,交心的人,碰见喷子,绝对不手软。

文章分类
文章存档

2015年(1)

2014年(18)

2013年(17)

2012年(21)

2011年(3)

分类: LINUX

2012-10-29 17:43:15

一、安装所需软件包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers


二、安装扩展库

1、下载libiconv
wget
下载完成后
tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14
./configure --prefix=/usr/local
make && make install

2、安装libmcrypt
wget %3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2F&ts=1304912647&use_mirror=nchc

下载完成后

tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8
./configure &&  make && make install
/sbin/ldconfig && cd libltdl
./configure --enable-ltdl-install
make && make install

3、安装mhash
wget
完成后
tar -zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9
./configure && make && make install
4、软链接
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

5、安装mcrypt
wget
现在完成后tar -zxvf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
./configure && make && make install

三、安装MySQL
wget
tar -zxvf mysql-5.5.25.tar.gz
cd mysql-5.5.25
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql -M -s /sbin/nologin mysql
为防止出现下面的报错:

Could NOT find Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline.cmake:83 (MESSAGE):

  Curses library not found.  Please install appropriate package,

 

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

首先安装:
yum -y install ncurses-devel

cmake -DCMAKE_INSTALL_PREFIX=/your_path/mysql/ \

-DMYSQL_DATADIR=/yourpath/mysqldata/ \

-DSYSCONFDIR=/etc/mysqld/ \

-DDEFAULT_CHARSET=utf8\

-DEXTRA_CHARSETS=all\

-DDEFAULT_COLLATION=utf8_general_ci\

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,all\

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_ARCHIVE_STORAGE_ENGINE=1\

-DWITH_MEMORY_STORAGE_ENGINE=1\

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\

-DWITH_READLINE=1\

-DENABLED_LOCAL_INFILE=1\

-DMYSQL_USER=mysql\

-DMYSQL_TCP_PORT=3306\

-DMYSQL_UNIX_ADDR=/yourpath/mysql/run/mysql.sock
make && make install
chmod +w /usr/local/mysql/
chown -R mysql.mysql /usr/local/mysql/
cd ..
/your_install_path/mysql/bin/mysql_install_db --basedir=/your_path/mysql --datadir=/your_path/data --user=mysql

cp ./support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chmod u+x /etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=
datadir=
更改为:
basedir=/your_path/mysql
datadir=/your_path/data

conf=/etc/my.cnf
更改为:
conf=/your_conf_path/my.cnf

vi /usr/local/mysql/my.cnf
#增加以下内容
[client]
character-set-server = utf8
port    = 3306
socket  = /tmp/mysql.sock

[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit    = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

interactive_timeout = 120
wait_timeout = 120

skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

#master-host     =   192.168.1.2
#master-user     =   username
#master-password =   password
#master-port     =  3306

server-id = 1

innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0

#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M


启动MySQL
service mysqld start

四、安装PHP及扩展

1、安装php
64位操作系统先拷贝一下LDAP,执行以下命令:
cp /usr/lib64/libldap* /usr/lib/

tar jxvf php-5.3.14.tar.bz2 && cd cd php-5.3.14
./configure --prefix=/usr/local/php \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-mhash \
--enable-sockets \
--enable-ftp \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization --with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--enable-fpm \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear

make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini

2、安装PHP扩展模块
wget
tar zxvf memcache-2.2.5.tgz && cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure - --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../


wget 
tar jxvf eaccelerator-0.9.6.1.tar.bz2 && cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../

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

#先安装perl-CPAN,为防止出现以下错误:
yum -y install yum -y install perl-CPAN
错误如下:
perl /usr/lib/perl5 /usr/share/perl5 .) at Makefile.PL line 24.
BEGIN failed--compilation aborted at Makefile.PL line 24.
make[1]: *** [PerlMagick/Makefile] 错误 2
make[1]: Leaving directory `/data0/software/ImageMagick-6.5.1-2'
make: *** [all] 错误 2


wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz && cd ImageMagick-6.5.1-2
./configure
make && make install
cd ../


wget
tar zxvf imagick-3.1.0.tgz && cd imagick-3.1.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../

3、修改php.ini文件

sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini
sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/php/etc/php.ini
sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/php/etc/php.ini

4、配置eAccelerator加速
mkdir /your/path/
vi /usr/local/php/etc/php.ini
在最后增加以下内容:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/data0/mysql/3306/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

5、创建用户及组和虚拟目录
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir /data0/www/html -p
chmod +w /data0/www/html/ && chown /data0/www/html/ -R

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
去掉下面的注释
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024
user = www
group = www

测试
/usr/local/php/sbin/php-fpm -t
如出现以下就代表成功
NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
启动
/usr/local/php/sbin/php-fpm &

五、安装Nginx

1、安装pcre
wget
tar zxvf pcre-8.10.tar.gz && cd pcre-8.10
./configure
make && make install
cd ..

wget
tar zxvf nginx-0.8.46.tar.gz && cd nginx-0.8.46
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
创建日志存放目录
mkdir /data0/logs
chmod +w /data0/logs/ && chown /data0/logs/
vi /usr/local/nginx/conf/nginx.conf
#增加以下内容
user  www www;

worker_processes 8;

error_log  /data0/logs/nginx_error.log  crit;

pid        /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
  use epoll;
  worker_connections 65535;
}

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

  #charset  gb2312;

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

  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

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

  #limit_zone  crawler  $binary_remote_addr  10m;

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

    #limit_conn   crawler  20;

    location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data0/logs/access.log  access;
      }


  server
  {
    listen  80;
    server_name  status.test.com;

    location / {
    stub_status on;
    access_log   off;
    }
  }
}

vi /usr/local/nginx/conf/fcgi.conf
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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

启动Nginx
/usr/local/nginx/sbin/nginx
添加到自启动
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm


六、优化内核

vi /etc/sysctl.conf
#################################################################
#
#优化内核参数
#
#################################################################
# 增加以下:
##每个网络接口接收数据包的速率比内核处理这些包的速度快时,允许送到队列的数据包的最大数目;
net.core.netdev_max_backlog =  32768

#web应用中linten函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的
#NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值;
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

#时间戳可以避免序列号的卷绕.一个1Gbps的链路肯定会遇到以前用过的序列号.时间戳能够让内核接受这种"异常"
#的数据包.这里需要将其关掉.
net.ipv4.tcp_timestamps = 0

#为了打开对端的连接,内核需要发送一个SYN并附带一个回应前面一个SYN的ACK,也就是三次握手中的第二次握手
#,这个设置决定了内核放弃连接之前发送SYN+ACK包的数量;
net.ipv4.tcp_synack_retries = 2

#在内核放弃建立之前发送SYN包数量;
net.ipv4.tcp_syn_retries = 2

#当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
net.ipv4.tcp_syncookies = 1

#开启TCP连接中TIME_WAIT scokets的快速回收,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

#允许TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#系统默认的TIMEOUT时间;
#net.ipv4.tcp_fin_timeout = 30
#当keeplive起用的时候,TCP发送keeplive消息的频度.缺省2小时,可以更改为2分钟;
#net.ipv4.tcp_keepalive_time = 1200

#表示用于向外连接的端口范围,缺省32768--61000,改为1024--65000
net.ipv4.ip_local_port_range = 1024  65535

#表示SYN队列的长度,默认1024,加大到65536,可容纳更多等待连接的网络连接数;
net.ipv4.tcp_max_syn_backlog = 65536

#系统同时保持TIME_WAIT的最大数量,如果超过这个数字,TIME_WAIT将立刻被清除并打印警告信息,
#默认180000,现更改为5000,对于Apache、Nginx等服务器,上几行的参数可以很好地减少TIME_WAIT套接字数量,但
#对于Squid,效果却不大.此项参数可以控制TIME_WAIT的最大数量,避免Squid服务器被大量的TIME_
#WAIT拖死;
net.ipv4.tcp_max_tw_buckets = 5000

vi /etc/security/limits.conf
#增加以下内容
*       soft    nofile  65536
*       hard    nofile  65536

到此结束
阅读(3057) | 评论(0) | 转发(0) |
0

上一篇:centos 6.2关闭tty

下一篇:weberp研究资料

给主人留下些什么吧!~~