重装服务器留档20150114
操作系统安装:CentOS 6.5 64位最小化安装。
安装包http://download.csdn.net/detail/jackqn/8360017
软件默认下载至在/opt/local/src
安装位置/opt/local下
配置好IP、DNS、网关、主机名
配置防火墙,开启80、3306端口
vi /etc/sysconfig/iptables
添加端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙
/etc/init.d/iptables restart #最后重启防火墙使配置生效
关闭SELinux
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
安装所需工具
yum install -y make apr* autoconf automake curl curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison
1、安装cmake
cd /opt/local/src
tar zxvf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./configure --prefix=/opt/local/cmake
make #编译
make install #安装
vi /etc/profile 在path路径中增加cmake执行文件路径
export PATH=$PATH:/opt/local/cmake/bin
source /etc/profile使配置立即生效
2、安装pcre
cd /opt/local/src
mkdir /opt/local/pcre #创建安装目录
tar zxvfpcre-8.36.tar.gz
cd pcre-8.36
./configure --prefix=/opt/local/pcre #配置
make && make install
3、安装libmcrypt
cd /opt/local/src
tar zxvf libmcrypt-2.5.8.tar.gz #解压
cd libmcrypt-2.5.8 #进入目录
./configure #配置
make #编译
make install #安装
4、安装gd库
cd /opt/local/src
tar zxvf gd-2.0.36RC1.tar.gz
cd gd-2.0.36RC1
./configure --enable-m4_pattern_allow —prefix=/opt/local/gd --with-jpeg=/usr/lib64 --with-png=/usr/lib --with-xpm=/usr/lib64 --with-freetype=/usr/lib64 --with-fontconfig=/usr/lib64 #配置
make #编译
make install #安装
5、安装Mysql
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
mkdir -p /opt/data/mysql/var #创建MySQL数据库存放目录
chown -R mysql:mysql /opt/data/mysql/var #设置MySQL数据库目录权限
cd /opt/local/src
tar zxvf mysql-5.5.35.tar.gz #解压
cd mysql-5.5.35
cmake . -DCMAKE_INSTALL_PREFIX=/opt/local/mysql -DMYSQL_DATADIR=/opt/data/mysql/var -DSYSCONFDIR=/etc #配置
make #编译
make install #安装
cd /opt/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
vi /etc/my.cnf #编辑配置文件,在 [mysqld] 部分增加
datadir = /opt/data/mysql/var #添加MySQL数据库路径
./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
chkconfig mysqld on #加入开机启动
vi /etc/rc.d/init.d/mysqld #编辑
basedir = /opt/local/mysql #MySQL程序安装路径
datadir = /opt/local/mysql/var #MySQl数据库存放目录
service mysqld start #启动
vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/opt/local/cmake/bin:/opt/local/mysql/bin
source /etc/profile #使配置立即生效
mkdir /var/lib/mysql #创建目录
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接
mysql_secure_installation #设置Mysql密码,根据提示按Y 回车输入2次密码
/opt/local/mysql/bin/mysqladmin -u root -p password "123456" #或者直接修改密码
到此,mysql安装完成!
6、安装 nginx
cd /opt/local/src
groupadd www #添加www组
useradd -g www www -s /bin/false #创建nginx运行账户www并加入到www组,不允许www用户直接登录系统
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/opt/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/opt/local/src/pcre-8.36
注意:--with-pcre=/opt/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错
make
make install
/opt/local/nginx/sbin/nginx #启动nginx
设置nginx开启启动
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/local/nginx/conf/nginx.conf
# pidfile: /opt/local/nginx/logs/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="/opt/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
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
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
:wq! #保存退出
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart #重新启动Nginx
service nginx restart
7、安装php
cd /opt/local/src
tar zxvf php-5.2.17.tar.gz
cd php-5.2.17
wget -c http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -d php-5.2.17-fpm-0.5.14.diff.gz
patch -p1 < php-5.2.17-fpm-0.5.14.diff
打fpm补丁
//
64位系统
装PHP过程中,编译时出现configure: error: libjpeg.(a|so) not found 错误的解决办法
ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
///
./configure --prefix=/opt/local/php --enable-fastcgi --with-config-file-path=/opt/local/php/etc --with-mysql=/opt/local/mysql --with-mysql-sock=/tmp/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
cd /usr/local/php/
mkdir etc
cp /usr/local/src/php-5.2.17/php.ini-dist /usr/local/php/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除默认配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.ini #创建链接到系统默认的位置
vi /usr/local/php5/etc/php-fpm.conf
使用www用户,把下面两行的注释去掉
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
:wq!保存退出
启动php-fpm
/usr/local/php/sbin/php-fpm start
设置 php-fpm开机启动
cp /usr/local/php/sbin/php-fpm /etc/rc.d/init.d/php-fpm
vi /etc/rc.d/init.d/php-fpm
在#!/bin/bash下面添加两行
#chkconfig:345 62 62
#description:php-fpm
:wq!保存退出
chmod 775 /etc/rc.d/init.d/php-fpm #赋予文件执行权限
chkconfig php-fpm on #设置开机启动
8、安装加速器
Zendoptimizer
cd /opt/local/src
mkdir /opt/local/zend
tar xvfz ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz #解压安装文件
cp /opt/local/src/ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /opt/local/zend/ZendOptimizer.so #拷贝文件到安装目录
rm -rf /opt/local/src/ZendOptimizer-3.3.9-linux-glibc23-x86_64 #删除安装包
配置Zend optimizer
vi /usr/local/php5/etc/php.ini #编辑文件
在最后位置添加以下内容
[Zend Optimizer]
zend_optimizer.optimization_level=15
zend_extension="/opt/local/zend/ZendOptimizer.so"
重启web服务器
/etc/init.d/nginx restart
/etc/rc.d/init.d/php-fpm restart
eaccelerator
cd /opt/local/src
tar xvfz eaccelerator-eaccelerator-42067ac.tar.gz
cd /opt/local/src/eaccelerator-eaccelerator-42067ac
#export PHP_PREFIX="/opt/local/php"
#$PHP_PREFIX/bin/phpize
#./configure --enable-shared --with-php-config=$PHP_PREFIX/bin/php-config
#make
#make install
cp /opt/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so /opt/local/zend/eaccelerator.so
目录/opt/local/php/lib/php/extensions/no-debug-zts-20060613是安装完成后提示的目录
chomd a+x /opt/local/zend/eaccelerator.so
vi /opt/local/php/etc/php.ini
加入
[Eaccelerator]
zend_extension="/opt/local/zend/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
8、配置nginx支持php
vi /opt/local/nginx/conf/nginx.conf
修改/opt/local/nginx/conf/nginx.conf 配置文件,需做如下修改
user www www; (首行user去掉注释,并与/opt/local/php/etc/php-fpm.conf中的user,group配置同)
server {
listen 80; (修改所使用的端口)
server_name localhost; (修改所使用的服务器名)
index index.php index.html index.htm;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
(取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,$fastcgi_script_name 应改为$document_root$fastcgi_script_name,或者使用绝对路径)
完成配置后启动
/etc/init.d/nginx restart
/etc/rc.d/init.d/php-fpm restart
我的安装包http://download.csdn.net/detail/jackqn/8360017