centos5.9安装nginx1.2.4+php5.3.18+mysql5.1.66

因为之前装了apache,所以要先卸载

1、卸载已装的apache mysql php
rpm -qa|grep httpd 找出包,挨个rpm -e 删除,有依赖关系的rpm -e –allmatches卸载

2、升级必备的软件
sudo -s
LANG=C
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 libevent libevent-devel mysql-devel

3、安装php
多语言转换包
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure –prefix=/usr/local
make
make install
cd ../

加密库
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
cd ../../

哈希库
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

建立一些软连接
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

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

还是加密相关库
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

cd /usr/lib64
ln -s /usr/lib64/mysql/libmysqlclient.so
cp -rp /usr/lib64/mysql/libmysqlclient.so /usr/lib/libmysqlclient.so
cp -rp /usr/lib64/mysql/* /usr/lib/mysql/
/sbin/ldconfig

cp -frp /usr/lib64/libldap* /usr/lib/

cd /usr/local/src

安装php5.3.18
tar zxvf php-5.3.18.tar.gz
cd php-5.3.18
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-config-file-scan-dir=/usr/local/webserver/php/etc/php.d –with-mysql=/usr/local/webserver/mysql –with-mysqli –with-pdo-mysql –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-soap –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fpm –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini
cd ../

安装php加速引擎
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

安装phpmysl库
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-pdo-mysql
make
make install
cd ../

 

mkdir /usr/local/webserver/php/etc/php.d/
cd /usr/local/webserver/php/etc/php.d/

一些配置文件,新建或修改
vi pdo.ini
###############################
extension = “pdo_mysql.so”
###############################

mkdir -p /tmp/eaccelerator_cache
chmod -R 777 /tmp/eaccelerator_cache
vi eaccelerator.ini
###############################
[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/tmp/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″
###############################
vi php.ini
#######################################
extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/”

disable_functions = crc32,chdir,getcwd,eval,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

session.gc_maxlifetime = 3600

short_open_tag = On
display_errors = Off
magic_quotes_gpc = On
output_buffering = On
cgi.fix_pathinfo=0
memory_limit = 128M
#######################################

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

cd /usr/local/webserver/php/etc
mv php-fpm.conf.default php-fpm.conf

vi php-fpm.conf
++++++++++++++
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 128
pm.max_requests = 500
user = www
group = www
pid = /usr/local/webserver/php/var/run/php-fpm.pid
++++++++++++++

ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm

vi /root/.bashrc
加入
ulimit -SHn 65535

安装nginx
安装TCMalloc,优化mysql,64位机先装libunwind
tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

安装google-perftools:(本机没装这个)
wget http://google-perftools.googlecode.com/files/google-perftools-0.97.tar.gz
tar zxvf google-perftools-0.97.tar.gz
cd google-perftools-0.97/
./configure
make && make install

echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

安装perl库
tar zxvf pcre-8.32.tar.gz
cd pcre-8.32/
./configure
make && make install
cd ../

安装etag
git clone git://github.com/mikewest/nginx-static-etags.git ./nginx-static-etags

安装nginx
tar zxvf nginx-1.2.4.tar.gz
cd nginx-1.2.4/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/usr/local/src/nginx-static-etags
make && make install
cd ../

mkdir -p /usr/local/webserver/nginx/logs
chmod +w /usr/local/webserver/nginx/logs
chown -R www:www /usr/local/webserver/nginx/logs

编辑配置文件
vi /usr/local/webserver/nginx/conf/nginx.conf

###############################################
user www www;

worker_processes 8;

error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;

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

google_perftools_profiles /var/tmp/tcmalloc;

#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_disable “MSIE [1-6]\.”;
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 text/xml;
gzip_vary on;

FileETag on;
#limit_zone crawler $binary_remote_addr 10m;

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

#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;
etag_format “%X%X”;
}

location ~ .*\.(js|css)?$
{
expires 1h;
etag_format “%X%X”;
}

location ^~ /data/bin/
{
deny all;
}

location ^~ /data/backup/
{
deny all;
}

#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 /data1/logs/access.log access;
}

}
###############################################
vi /usr/local/webserver/nginx/conf/fcgi.conf
###############################################
if ($request_filename ~* (.*)\.php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403;
}
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;
###############################################

vi /etc/rc.local

ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm
/usr/local/webserver/nginx/sbin/nginx

vi /etc/sysctl.conf
################################
# Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

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

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

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

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535

################################

sysctl -p

安装mysql

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.66.tar.gz
cd mysql-5.1.66/
./configure –prefix=/usr/local/webserver/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=partition,innobase,myisammrg
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../

①、创建MySQL数据库存放目录

mkdir -p /data/mysql/data/
mkdir -p /data/mysql/binlog/
mkdir -p /data/mysql/relaylog/
chown -R mysql:mysql /data/mysql/
②、以mysql用户帐号的身份建立数据表:

/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/data/mysql/data –user=mysql
③、创建my.cnf配置文件:

vi /data/mysql/data/my.cnf

注:Centos6.2之后要把my.cn放在/etc目录
vi /etc/my.cnf
ln -s /etc/my.cn /data/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/webserver/mysql
datadir = /data/mysql/data
log-error = /data/mysql/mysql_error.log
pid-file = /data/mysql/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 = /data/mysql/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data/mysql/relaylog/relaylog
relay-log-info-file = /data/mysql/relaylog/relaylog
relay-log = /data/mysql/relaylog/relaylog
expire_logs_days = 30
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

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 = /data/mysql/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M
########################################################################

 

cd /usr/local/src/mysql-5.1.66/support-files
cp mysql.server /etc/init.d/mysqld
//修改mysqld
basedir=/usr/local/webserver/mysql
datadir=/data/mysql/data
pid_file=/data/mysql/mysql.pid

chmod a+x /etc/init.d/mysqld
chkconfig –level 35 mysqld on

ln -s /usr/local/webserver/mysql/bin/mysql_config /usr/bin/mysql_config
ln -s /usr/local/webserver/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/webserver/mysql/bin/mysql_dump /usr/bin/mysql_dump

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

创建管理MySQL数据库的shell脚本:

vi /data/mysql/mysql

输入以下内容(这里的用户名root和密码12345678接下来的步骤会创建):
########################################################################
#!/bin/sh

mysql_port=3306
mysql_username=”root”
mysql_password=”C^%^R&*&S123″

function_start_mysql()
{
printf “Starting MySQL…\n”
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/data/mysql/data/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
printf “Stoping MySQL…\n”
/usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}

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 {start|stop|restart|kill}\n”
fi
########################################################################
chmod a+x /data/mysql/mysql

启动MySQL:

/data/mysql/mysql start
通过命令行登录管理MySQL服务器(提示输入密码时直接回车
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ IDENTIFIED BY ‘C^%^R&*&S123’;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ IDENTIFIED BY ‘C^%^R&*&S123’;

停止mysql
/data/mysql/mysql stop

注意:mysql有个问题,无法使用localhost连接,只能用127.0.0.1

发表评论