系统环境:centos5.6--64位 2.6.18-194.el5(内核)
1.#arp -an > maclist(保存网关)
2.#ntsysv(关闭不需要的服务)
3.配置yum
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo(中科)
4.安装NTP服务,同步系统时间
#yum install ntp -y
#ntpdate 0.centos.pool.ntp.org(官方时间)
5.安装相关依赖包
#yum -y install dialog ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc \
glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel \
libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel \
libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn \
libidn-devel openssl openssl-devel openldap openldap-devel \
nss_ldap openldap-clients openldap-servers
6.添加三方扩展源
#wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
#rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
7.安装系统性能先关包(常用系统监控软件)
#yum -y install sysstat nload dstat bmon iftop mlocate
8.下载相应软件包 /ruanjian/packages(软件包存放目录)
#mkdir /ruanjian
#cd /ruanjian
#cat > list << "EOF" &&
APC-3.0.19.tgz
libevent-1.4.9-stable.tar.gz
libiconv-1.13.1.tar.gz
libmcrypt-2.5.8.tar.gz
libmemcached-0.31.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
memcached-1.0.1.tgz
memcached-1.4.1.tar.gz
mhash-0.9.9.9.tar.gz
mysql-5.1.48.tar.gz
nginx-0.8.45.tar.gz
pcre-8.10.tar.gz
php-5.2.13-fpm-0.5.14.diff.gz
php-5.2.13.tar.gz
EOF
for i in `cat list`
do
if [ -s packages/$i ]; then
echo "$i [found]"
else
echo "Error: $i not found!!!download now......"
wget http://docs.linuxtone.org/soft/lemp/packages/$i -P packages/
fi
done
9.编译安装MYSQL
1.创建mysql用户和组
#/usr/sbin/groupadd mysql -g 27
#/usr/sbin/useradd -g mysql mysql -s /sbin/nologin
2.解压,编译mysql
#tar zxvf mysql-5.1.48.tar.gz -C /usr/local/src
#cd /usr/local/mysql-5.1.48/src
#CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
-fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql-5.1.48/ --with-comment=Source --with-server-suffix=-cyops.org \
--with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl \
--with-embedded-server --enable-local-infile --with-plugins=innobase
#make -j2 && make install
3.创建数据库存放目录,修改目录权限
#mkdir -p /data/mysql/3306/{data,logs/{binlog,relaylog}}
#chown -R mysql:mysql /data/mysql
4.编辑mysql配置文件
#vi /data/mysql/3306/my.cnf
[client]
character-set-server = utf8
port = 3306
socket = /data/mysql/3306/mysql.sock
[mysqld]
user = mysql
port = 3306
socket = /data/mysql/3306/mysql.sock
character-set-server = utf8
basedir = /usr/local/mysql-5.1.48
datadir = /data/mysql/3306/data
pid-file = /data/mysql/3306/mysql.pid
#slow log
#long_query_time = 3
#log-slow-queries = /data/mysql/3306/logs/slow.log
skip-name-resolve
# ****** MyISAM Engine options******
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
thread_stack = 192K
default-storage-engine = MyISAM
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
# ****** master mysql db ******
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
binlog-do-db = netseek
server-id = 1
relay-log = /data/mysql/3306/logs/relaylog/mysql-relay-bin
relay-log-index = /data/mysql/3306/logs/relaylog/mysql-relay-bin.index
log-error = /data/mysql/3306/logs/error.log
master-info-file = /data/mysql/3306/logs/mysql-master.info
relay-log-info-file = /data/mysql/3306/logs/mysql-relay-log.info
log-slave-updates
log-bin = /data/mysql/3306/logs/binlog/mysql-bin
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
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
expire_logs_days = 1
key_buffer_size = 256M
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
# ****** InnoDB Engine options******
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
[mysqldump]
quick
max_allowed_packet = 32M
5.创建mysql启动脚本,给权限
#vi /etc/init.d/mysql
#!/bin/bash
mysql_port=3306
mysql_username="root"
mysql_password="cy2009" #mysql root密码.
mysql_ver="mysql-5.1.48"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/${mysql_ver}/bin/mysqld_safe --defaults-file=/data/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/${mysql_ver}/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/mysql/${mysql_port}/mysql.sock shutdown
printf "\n"
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef |grep 'bin/mysqld_safe' | grep ${mysql_port} |awk '{printf $2}')
kill -9 $(ps -ef |grep 'libexec/mysqld' | grep ${mysql_port} |awk '{printf $2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /data/mysql/${mysql_port}/mysql {start;stop;restart;kill}\n"
fi
6.修改数据库目录权限
#chown -R mysql:mysql /data/mysql/
7.初始化数据库
#/usr/local/mysql-5.1.48/bin/mysql_install_db --basedir=/usr/local/mysql-5.1.48/ --datadir=/data/mysql/3306/data --user=mysql --defaults-file=/data/mysql/3306/my.cnf
8.启动mysql
#chmod a+x /etc/init.d/mysql
#/etc/init.d/mysql start
9.建立软连接(轮询)
#cd /usr/local/mysql-5.1.48/bin/
#for i in *; do ln -s /usr/local/mysql-5.1.48/bin/$i /usr/bin/$i; done
10.创建mysql数据库密码(cy2009)
#mysqladmin -uroot password cy2009
11.建立软连接
#ln -s /data/mysql/3306/mysql.sock /tmp/mysql.sock(如果报错的话使用)
12.进入数据库
#mysql -uroot -p
10.编译,安装PHP及相关扩展模块
1.安装lib
#tar zxvf libiconv-1.13.1.tar.gz -C /usr/local/src/
#cd /usr/local/src/libiconv-1.13.1/
#./configure --prefix=/usr && make && make install
#tar zxvf libmcrypt-2.5.8.tar.gz -C /usr/local/src/
#cd /usr/local/src/libmcrypt-2.5.8/
#./configure --prefix=/usr && make && make install
#echo "/usr/lib" >> /usr/ld.so.config
#/sbin/ldconfig
#cd /usr/local/src/libmcrypt-2.5.8/libltdl
#./configure --enable-ltdl-install make && make install
#tar zxvf mhash-0.9.9.9.tar.gz -C /usr/local/src/
#cd /usr/local/src/mhash-0.9.9.9/
#./configure --prefix=/usr && make && make install
#tar zxvf mcrypt-2.6.8.tar.gz -C /usr/local/src/
#cd /usr/local/src/mcrypt-2.6.8/
#./configure --prefix=/usr && make && make install
#tar zxvf php-5.2.13.tar.gz -C /usr/local/src/
#cp /ruanjian/packages/php-5.2.13-fpm-0.5.14.diff.gz /usr/local/src/
#cd /usr/local/src/
#gzip -cd php-5.2.13-fpm-0.5.14.diff.gz | patch -d php-5.2.13 -p1
#cd php-5.2.13
#./configure --prefix=/usr/local/php5.2.13 --with-config-file-path=/usr/local/php5.2.13/etc --enable-fpm --enable-fastcgi --enable-force-cgi-redirect --disable-rpath --enable-discard-path --with-mysql=/usr/local/mysql-5.1.48 -with-mysqli=/usr/local/mysql-5.1.48/bin/mysql_config --with-pdo-mysql=/usr/local/mysql-5.1.48/ --with-sqlite --with-pdo-sqlite --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --with-zlib --with-libxml-dir --with-curl --with-curlwrappers --with-openssl --with-mhash --with-xmlrpc --with-mcrypt --with-ldap --with-ldap-sasl --enable-xml --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-gd-native-ttf --enable-ftp --enable-pcntl --enable-sockets --enable-zip --enable-soap --enable-pdo --disable-debug --disable-ipv6
#make ZEND_EXTRA_LIBS='-liconv' -j10
#make install (如果报错就执行下面的命令)
#ln -s /usr/local/src/libiconv-1.13.1/ /usr/lib/libiconv-1.13.1
#ldconfig ------》然后再make install就没问题了
#cd /usr/local/src/php-5.2.13
#cp php.ini-dist /usr/local/php5.2.13/etc/php.ini
安装,编译PHP cache
#tar zxvf APC-3.0.19.tgz -C /usr/local/src/
#cd /usr/local/src/APC-3.0.19/
#/usr/local/php5.2.13/bin/phpize
#./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php5.2.13/bin/php-config
#make -j2 && make install
Eaccelerator 模块安装
#tar jxvf eaccelerator-0.9.6.1.tar.bz2 -C /usr/local/src(这个包得自己下载)
#cd /usr/local/src/eaccelerator-0.9.6.1/
#/usr/local/php5.2.13/bin/phpize
#./configure --enable-eaccelerator --with-php-config=/usr/local/php5.2.13/bin/php-config
#make && make install
安装php memcache
#tar zxvf memcache-2.2.5.tgz -C /usr/local/src/
#cd /usr/local/src/memcache-2.2.5/
#/usr/local/php5.2.13/bin/phpize
#./configure --with-php-config=/usr/local/php5.2.13/bin/php-config
#make -j2 && make install
安装php memcached
#tar zxvf libmemcached-0.31.tar.gz -C /usr/local/
#cd /usr/local/libmemcached-0.31/
#./configure --prefix=/usr/local/src/libmemcached-0.31 --with-memcached
#make -j2 && make install
#tar zxvf memcached-1.0.1.tgz -C /usr/local/src/
#cd /usr/local/src/memcached-1.0.1/
#./configure --with-php-config=/usr/local/php5.2.13/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached-0.31/
#make -j2 && make install
安装imagick图片处理模块
#tar zxvf ImageMagick.tar.gz -C /usr/local(这个包得自己下)
#cd /usr/local/ImageMagick-6.5.1-2/
#./configure --enable-shared --with-modules --without-x --with-gs-font-dir=default --with-perl=yes --with-xml=yes --with-zlib=yes --with-jpeg=yes
#make -j2 && make install
#tar zxvf imagick-3.0.0.tgz -C /usr/local/
#cd /usr/local/imagick-3.0.0/
#/usr/local/php5.2.13/bin/phpize
#./configure --with-php-config=/usr/local/php5.2.13/bin/php-config
#make -j2 && make install
编辑php.ini
#cp /usr/local/php5.2.13/etc/php.ini /usr/local/php5.2.13/etc/php.ini.bak(备份)
#vim /usr/local/php5.2.13/etc/php.ini
编辑php-fpm.ini
#mv /usr/local/php5.2.13/etc/php-fpm.conf /usr/local/php5.2.13/etc/php-fpm.conf.bak
#vim /usr/local/php5.2.13/etc/php-fpm.conf
编译安装nginx
#tar zxvf pcre-8.10.tar.gz -C /usr/local/src/
#cd /usr/local/src/pcre-8.10/
#./configure && make && make install
#tar zxvf nginx-0.8.45.tar.gz -C /usr/local/src/
#cd /usr/local/src/nginx-0.8.45/
#./configure --user=daemon --group=daemon --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_gzip_static_module
#make -j2 && make install
#mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak(备份nginx.cnf)
#vim /usr/local/nginx/conf/nginx.conf(nginx主配置文件位置)
#mkdir /usr/local/nginx/conf/vhost
#chmod 777 /usr/local/nginx/conf/vhost/
#vim /usr/local/nginx/conf/vhost/test.conf
server
{
listen 80;
server_name www.xxx.com
index index.php index.html index.htm;
root /data/www/wwwroot;
location ~.*\(gif|jpg|jpeg|png|bmp|swf)$
{
expires 20d;
}
location ~ .*\.(js|css)?$
{
expires 24h;
}
location /webstatus {
stub_status on;
access_log off;
}
location ~ .*\.php?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
"/usr/local/nginx/conf/vhost/test.conf" 33L, 649C 23,17 Top
#/usr/local/nginx/sbin/nginx –t(检查语法错误)
#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf(开启nginx)
#killall -QUIT nginx主进程号(关闭)