centos6.4 64bit+nginx+mysql+php环境搭建

规划:

硬盘0 :20GB,硬盘1 :20GB,硬盘2: 5GB
网卡0: host-only,网卡1: bridge
声卡,USB等删除
CPU 2*2
内存1.5GB或者1GB
带宽无限制或者10Mbps
软件:centos 6.4 64bit+nginx 1.6.0+mysql 5.6.13+php 5.4.20+zend 2.5.0+php-fpm

系统安装:

安装系统时区选成上海,格式化整个硬盘,其他默认
安装完CentOS-6.4-x86_64-minimal.iso

网络配置:

vi /etc/sysconfig/network-scripts/ifcfg-eth0 编辑为如下内容(可添加多个网卡,如 ifcfg-eth1, ifcfg-eth1:0)
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:2F:80:60"
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
UUID="72050b68-cb84-4d83-a616-7b0ed37883d9"
IPADDR=142.91.131.63
PREFIX=24
GATEWAY=142.91.131.1
DEFROUTE=NO
IPV6INIT=NO
IPV6_AUTOCONF=NO
DNS1=8.8.8.8

# service network restart

用户环境配置:

# hwclock --set --date="11/17/12 09:10:30" //更新时间
# hwclock --hctosys//把硬件时钟同步到系统时钟
# vi /etc/sysconfig/clock //更改时区
ZONE=Asia/Shanghai
UTC=false
ARC=false
# rm /etc/localtime
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# /usr/sbin/groupadd www
# /usr/sbin/useradd -g www www
# passwd www #修改密码为客户VPS的密码
# echo "AllowUsers www" >> /etc/ssh/sshd_config
# service sshd restart
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
# mkdir -p /wwwroot/htdocs //以下挂载目录,根据实际规划和硬盘名字来进行操作
# mkdir -p /wwwroot/mysql
# mkfs -t ext4 /dev/sdb
# mkfs -t ext4 /dev/sdc
# mount /dev/sdb /wwwroot/htdocs
# mount /dev/sdc /wwwroot/mysql
# chown -R www:www /wwwroot/htdocs
# chown -R mysql:mysql /wwwroot/mysql
# echo "mount /dev/sdb /wwwroot/htdocs" >> /etc/rc.local
# echo "mount /dev/sdc /wwwroot/mysql" >> /etc/rc.local

安装包下载:

# yum -y install yum-fastestmirror
# yum clean all
# yum list
# yum -y install wget vixie-cron crontabs
# service crond start
# chkconfig --level 2345 crond on
# wget http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.13-1.el6.x86_64.rpm
# wget http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.13-1.el6.x86_64.rpm
# wget http://cn2.php.net/get/php-5.4.20.tar.gz/from/am1.php.net/mirror
# yum -y install vsftpd ftp telnet
# cd /etc/vsftpd/
# vi ftpusers //注释掉root,如果是只开通www用户的话,就不用处理
# vi vsftpd.conf //修改为anonymous_enable=NO 添加 local_root=/wwwroot/backup
# vi user_list //注释掉root
# setsebool -P allow_ftpd_full_access 1
# setsebool -P ftp_home_dir 1 //Centos下因为SElinux限制了vsftpd用户上传文件到主目录,所以需要执行此命令。可以用命令getsebool -a | grep ftp来检查。
# service vsftpd  restart
# yum list | grep openjdk //搜索到类似下边的安装包,然后安装
# yum install java-1.7.0-openjdk.x86_64 -y

安装mysql:

# yum install perl libaio -y
# cd ~
# yum remove mysql-libs-5.1.66-2.el6_3.x86_64 -y
# yum remove mysql-libs-5.1.67-1.el6_3.x86_64 -y
# rpm -i MySQL-server-5.6.13-1.el6.x86_64.rpm
# rpm -i MySQL-client-5.6.13-1.el6.x86_64.rpm
更改mysql路径
# mv /var/lib/mysql/* /wwwroot/mysql
# rm -fr /var/lib/mysql
# ln -s /wwwroot/mysql /var/lib/mysql
vi /etc/my.cnf如下:
[mysqld]
datadir=/wwwroot/mysql
socket=/wwwroot/mysql/mysql.sock
user=mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
修改vi /etc/init.d/mysql的datadir为datadir="/wwwroot/mysql"
vi /etc/selinux/config 修改 SELINUX=enforcing
# chcon  -t var_lib_t /wwwroot
# chcon -R -t mysqld_db_t /wwwroot/mysql
# chown mysql:mysql /wwwroot/mysql
# service mysql start
# chkconfig --level 2345 mysql on
# more /root/.mysql_secret //查看root密码
# /usr/bin/mysql_secure_installation //初始化数据库

安装nginx:

详见《nginx安装、配置反向代理配置和字符替换机制》

安装php:(php 5.5运行CRM会出现邮件无法显示的现象,并且不支持xcache,所以安装php 5.4)

# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel gd-devel make unzip patch

# tar -zxf php-5.4.20.tar.gz
# cd php-5.4.20
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mysql --with-mysql-sock --with-mysqli --enable-pcntl --with-pdo-mysql --enable-shmop --enable-sockets --enable-zip --with-pear
# dd if=/dev/zero of=/swap bs=1024 count=1M
# mkswap /swap
# swapon /swap
# echo "/swap swap swap sw 0 0" >> /etc/fstab //增加swap,防止出现虚拟内存不够的报错

# make && make install
# cp php.ini-production /usr/local/php/etc/php.ini
# mkdir -p /usr/local/php/etc/php.d

配置php-fpm:

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --level 2345 php-fpm on
vi /usr/local/php/etc/php-fpm.conf修改以下参数:
request_terminate_timeout = 30s
pm.max_children = 50
pm.start_servers = 16
pm.min_spare_servers = 16
pm.max_spare_servers = 50

安装xcache 3.0.3:

# cd ~
# wget http://xcache.lighttpd.net/pub/Releases/3.0.3/xcache-3.0.3.tar.gz
# gunzip xcache-3.0.3.tar.gz; tar -xf xcache-3.0.3.tar; cd xcache-3.0.3
# /usr/local/php/bin/phpize --clean
# /usr/local/php/bin/phpize
#./configure --enable-xcache -enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/local/php/bin/php-config
# make && make install
# echo -n "123456" | md5sum
# e10adc3949ba59abbe56e057f20f883e //这个字符串后边要用到,是网页访问需要的加密过的密码123456
# touch /tmp/xcache
# chmod 777 /tmp/xcache
# vi /usr/local/php/etc/php.d/xcache.ini 为如下内容
[xcache-common]
extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so"
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "5a826e6cb0418ad239d4c79915e28cd5"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 128M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 32M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
[xcache.coverager]
xcache.coverager = Off
xcache.coveragedump_directory = ""

安装mcrypt

# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install php-mcrypt libmcrypt libmcrypt-devel mcrypt mhash -y
# cd ~/php-5.4.20/ext/mcrypt/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
# cd /usr/local/php/etc/php.d
# vi mcrypt.ini
内容为extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/mcrypt.so"

安装openssl

# yum install openssl openssl-devel -y
# ln -s /usr/lib64/libssl.so /usr/lib/
# cd ~/php-5.4.20/ext/openssl/
# cp config0.m4 config.m4
# /usr/local/php/bin/phpize
# ./configure --with-openssl  --with-php-config=/usr/local/php/bin/php-config
# make && make install
# cd /usr/local/php/etc/php.d
# vi openssl.ini
内容为extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/openssl.so"

调整mysql, php, nginx配置文件位置:

# mkdir -p /wwwroot/htdocs/script
# mv /etc/my.cnf /wwwroot/htdocs/script/mysql.my.cnf
# ln -s /wwwroot/htdocs/script/mysql.my.cnf /etc/my.cnf
# chcon -t etc_t /wwwroot/
# chcon -u system_u /wwwroot/
# chcon -t etc_t /wwwroot/htdocs
# chcon -u system_u /wwwroot/htdocs
# chcon -t etc_t /wwwroot/htdocs/script
# chcon -u system_u /wwwroot/htdocs/script
# service mysql restart
# mv /etc/nginx/conf.d /wwwroot/htdocs/script/nginx.conf.d
# ln -s /wwwroot/htdocs/script/nginx.conf.d /etc/nginx/conf.d
# service nginx restart
# mv /usr/local/php/etc /wwwroot/htdocs/script/php.etc
# ln -s /wwwroot/htdocs/script/php.etc /usr/local/php/etc
# service php-fpm restart
# echo "service mysql restart" >> /etc/rc.local
# echo "service php-fpm restart" >> /etc/rc.local
# echo "service nginx restart" >> /etc/rc.local
# echo "service vsftpd restart" >> /etc/rc.local
# /sbin/iptables -F
# service iptables save
# service iptables restart
# reboot

配置测试网站:

# su - www
# cd /wwwroot/htdocs
# wget http://download.comsenz.com/DiscuzX/3.0/Discuz_X3.0_SC_GBK.zip
# unzip Discuz_X3.0_SC_GBK.zip
# rm -fr Discuz_X3.0_SC_GBK.zip readme utility
# mv upload discuz
# mysql -u root -p
# mysql> create database discuz;
# mysql> exit
# su -
在/etc/nginx/conf.d/目录里边添加discuz.conf文件

确认网站的水印和URL转发没有问题后,删除网站:
# rm -rf /wwwroot/htdocs/discuz
# rm -rf /etc/nginx/conf.d/discuz.conf
# mysql -u root -p
# mysql> drop database discuz;
# mysql> exit