系统环境说明:
os:CentOS 5.6
nginx:nginx-1.0.11
php:php-5.3.9
mysql:mysql-5.5.20
文档导读:
一 准备工作
二 基础软件包安装
三 安装Nginx
四 MySQL安装
五 安装PHP
六 企业网站部署
七 压力测试webbench
八 优化mysql,nginx,php配置及防火墙配置(略)
九 维护常用命令
一、准备工作(仅作参考)
1、删除系统自带软件
rpm -qa httpd mysql php nginx
先停止服务,卸载软件命令:rpm -e httpd --nodeps
2、yum源
vim /etc/yum.repos.d/CentOS-Base.repo
服务器需要yum的时候也不多,所以并不需要去设置。
国内镜像:http://mirrors.163.com http://mirrors.sohu.com
3、设置CentOS默认语言
cp /etc/sysconfig/i18n /etc/sysconfig/i18n_bak
vi /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
默认的语言是英文,如果把第一行改为"LANG=”zh_CN.UTF-8”",则本机上的shell可以看到正常的中文,但通过ssh连上就会发现所有的汉字变成乱码了;则再改为"LANG="zh_CN.GB18030"",重新登陆即可发现一切OK。
4、安装vim
Centos里的VI只默认安装了vim-minimal-7.x。所以无论是输入vi或者 vim查看文件,syntax功能都无法正常启用。因此需要用yum安装另外两个组件:vim-common-7.x和vim-enhanced- 7.x
yum -y install vim*
查看最近yum安装过的软件包
more /var/log/yum.log
5、时间同步
#当前时区调整为上海就是+8区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#利用ntpdate同步标准时间
ntpdate us.pool.ntp.org
注意:需要安装ntp-4.2.2p1-9.el5.centos.2.1.i386.rpm
或yum install -y ntp
加入定时计划任务,每隔10分钟同步一下时钟
crontab -e
0 23 * * * /bin/bash /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP
(升级系统软件包,服务和用户安全设置在此不涉及)
二 基础软件包安装
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
yum -y install make crontabs wget
其中wget看你使用情况,可以不装,openssl-devel对于不需要ssl安全连接的也可以不装,libtool一般在安装到nginx\php\mysql前会安装上去,所以这里也不用安装。make是编译所用,cmake是编译MySQL时用到,ncurses-devel也是。autoconf是编译eaccelerator时用到,crontabs为计划任务,日志分割所用。
附带介绍:
#检查是否安装gcc
gcc -v
#查询SELinux开启情况
getenforce
三、安装Nginx
1.创建nginx所需用户及目录
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/htdocs/html
chmod +w /data0/htdocs/html
chown -R www:www /data0/htdocs/html
mkdir -p /data0/htdocs/web
chmod +w /data0/htdocs/web
chown -R www:www /data0/htdocs/web
mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs
2.安装nginx所需pcre
tar zxvf pcre-8.21.tar.gz && cd pcre-8.21/
./configure
make
make install
cd ../
3.开始安装nginx
tar zxvf nginx-1.0.11.tar.gz && cd nginx-1.0.11/
./configure --user=www --group=www \
--prefix=/usr/local/webserver/nginx \
--with-http_stub_status_module \
--with-http_ssl_module
make
make install
cd ../
4.配置nginx
cd /usr/local/webserver/nginx/conf/
mv nginx.conf nginx.conf_bak
vim nginx.conf
输入以下内容:
user www www;
worker_processes 8;
error_log /data1/logs/nginx_error.log crit;
pid /usr/local/webserver/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 default;
server_name _;
# index index.html index.htm index.php;
return 404;
}
server
{
listen 888;
server_name _;
# index index.html index.htm index.php;
return 404;
}
include vhost/*.conf;
include vhost/admin/*.conf;
include vhost/html/*.conf;
}
5.前后台分离配置文件
cd /usr/local/webserver/nginx/conf
#前台配置文件
vim server.html.conf
输入以下内容:
index index.html index.htm index.php;
location ~ /\.ht {
deny all;
}
location ~ .*\.(sqlite|sq3)$ {
deny all;
}
location ~ .*\.(php|php5)?$ {
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
#后台配置文件
vim server.conf
输入以下内容:
index index.html index.htm index.php;
location ~ /\.ht {
deny all;
}
location ~ .*\.(sqlite|sq3)$ {
deny all;
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}