阿里云centos 安装PHP+Mysql+Nginx步骤

安装步骤:

//查看当前文件系统
[root@localhost ~]# df -h
//查找分区
[root@localhost ~]# fdisk /dev/sda
Command (m for help): p //选择
Command (m for help): n //选择
Command action
e extended
p primary partition (1-4)
P //选择
p primary partition (1-4) 1 //选择
Command (m for help): w //选择
[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l
[root@localhost ~]# mkfs.ext3 /dev/sda
PS:这里可能要写 sda1
[root@localhost ~]# fdisk -l
[root@localhost ~]# mkdir -p /data
[root@localhost ~]# vi /etc/fstab
/dev/sda1 /data ext3 defaults 0 0
[root@localhost ~]# mount –a
[root@localhost ~]# df -h

更新升级源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget http://blog.s135.com/soft/linux/centos/5.2/CentOS-Base.repo

网易开通了一个开源软件的镜像站点,网址为:

http://mirrors.163.com/

第一步:
#—————————————-
|利用CentOS Linux系统自带的yum命令安装、升级所需的程序库
|(RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包,进行安装)
#—————————————-

#设置默认语言为中文
LANG=C

#运行yum命令 安装程序 yum -y insall
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

#—————————————-
*RedHat AS4 系统环境
#—————————————-
I.i386 系统 wget ->下载
rpm ->rmp原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎。
-i  显示套件的相关信息。
-h或–hash  套件安装时列出标记。
-v  显示指令执行过程。

#————————————————————————————–+
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/libjpeg-devel-6b-33.i386.rpm
# rpm -ivh libjpeg-devel-6b-33.i386.rpm
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/freetype-devel-2.1.9-1.i386.rpm
# rpm -ivh freetype-devel-2.1.9-1.i386.rpm
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/libpng-devel-1.2.7-1.i386.rpm
# rpm -ivh libpng-devel-1.2.7-1.i386.rpm
#————————————————————————————–+

#—————————————-
II.x86_64 系统
#—————————————-
#—————————————————————————————-+
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/libjpeg-devel-6b-33.x86_64.rpm
# rpm -ivh libjpeg-devel-6b-33.x86_64.rpm
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/freetype-devel-2.1.9-1.x86_64.rpm
# rpm -ivh freetype-devel-2.1.9-1.x86_64.rpm
# wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/libpng-devel-1.2.7-1.x86_64.rpm
# rpm -ivh libpng-devel-1.2.7-1.x86_64.rpm
#—————————————————————————————-+

第二步:
#—————————————-
|下载程序源码包|
#—————————————-
#——————————————————————————————–+

# mkdir -p 若所要建立目录的上层目录目前尚未建立,则会一并建立上层目录
mkdir -p /data0/software
cd /data0/software

#可以把下载好的的语言包复制到/data0/software目录

wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.15.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.38.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-7.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.5.3.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.2.2.tgz
#———————————————————————————————+


第三步:
#—————————————-
|编译安装PHP 5.2.10所需的支持库|
#—————————————-
# tar z(通过gzip指令处理备份文件)x(从备份文件中还原文件)v(显示指令执行过程)f(指定备份文件)
# make && make install 编译并运行

tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install
cd ../

#ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享

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 对源文件建立符号连接,而非硬连接
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

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
#——————————END 编译安装PHP 5.2.10所需的支持库——————–+

第四步:
#—————————————-
|编译安装MySQL 5.1.38|
#—————————————-

## 新建用户组mysql
/usr/sbin/groupadd mysql

## useradd -g指定用户所属的群组
/usr/sbin/useradd -g mysql mysql

tar zxvf mysql-5.1.38.tar.gz
cd mysql-5.1.38/
./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=innobase
make && make install

# chmod r:读取权限,数字代号为”4″。
w:写入权限,数字代号为”2″。
x:执行或切换权限,数字代号为”1″。
-:不具任何权限,数字代号为”0″。
s:特殊?b>功能说明:变更文件或目录的权限。
权限范围的表示法如下:
u:User,即文件或目录的拥有者。
g:Group,即文件或目录的所属群组。
o:Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围。
a:All,即全部的用户,包含拥有者,所属群组以及其他用户。

chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../
#—————————————————————————–+

①、创建MySQL数据库存放目录
#———————————+
mkdir -p /data0/mysql/3306/data/

# chown -R 递归处理,变更文件或目录的拥有者或所属群组。
chown -R mysql:mysql /data0/mysql/
#———————————+

②、以mysql用户帐号的身份建立数据表:
#———————————+
/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/data0/mysql/3306/data –user=mysql
#———————————+

③、创建my.cnf配置文件:
#——————————–+
vi /data0/mysql/3306/my.cnf
#——————————–+

my.cnf输入以下内容:

[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock

[mysql]
prompt=”(\u:by superaj@msn.cn :)[\d]> ”
no-auto-rehash

[mysqld]
#default-character-set = utf8
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
open_files_limit = 10240
back_log = 600
max_connections = 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 1
log_long_format
log-bin = /data0/mysql/3306/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
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_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

server-id = 1

innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M
innodb_data_file_path = ibdata1:1024M: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

④、创建管理MySQL数据库的shell脚本:
#—————————-+
vi /data0/mysql/3306/mysql
#—————————-+

输入以下内容(这里的用户名admin和密码12345678接下来的步骤会创建):

#!/bin/sh

mysql_port=3306
mysql_username=”admin”
mysql_password=”admin123456@mysql”

function_start_mysql()
{
printf “Starting MySQL…\n”
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/data0/mysql/${mysql_port}/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: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n”
fi
#—————————-

⑤、赋予shell脚本可执行权限:
#——————————+
chmod +x /data0/mysql/3306/mysql
#——————————+

⑥、启动MySQL:
#——————————+
/data0/mysql/3306/mysql start
#——————————+

⑦、通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
#—————————————————————-+
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
#—————————————————————-+

ll / 的权限 设置chmod -R 777 /tmp
⑧、输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’localhost’ IDENTIFIED BY ‘admin123456@mysql’;
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’127.0.0.1’ IDENTIFIED BY ‘admin123456@mysql’;

exit;
⑨、(可选)停止MySQL:
/data0/mysql/3306/mysql stop

/data0/mysql/3306/mysql start

#————————-END 编译安装MySQL 5.1.35———————+

第五步:
#—————————————-
|编译安装PHP(FastCGI模式)|
#—————————————-

tar zxvf php-5.2.10.tar.gz

#——————将5.2.10的 fast-cgi补丁包导入源码目录下———–
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1

cd php-5.2.10/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –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-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –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 –enable-soap –without-pear
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../

curl http://pear.php.net/go-pear | /usr/local/webserver/php/bin/php
//文本行模式访问页面
#————————————————————+

第六步:
#—————————————-
|编译安装PHP5扩展模块|
#—————————————-

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

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=/usr/local/webserver/mysql
make
make install
cd ../

#————-开源的图像处理软件————————–
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
——————————————————

#———-imagick 的安装建立在ImageMagick基础上 —————————
tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
#—————————————END 编译安装PHP5扩展模块———————+

第六步:
#———————————————————————————–
|修改php.ini 加入扩展模块,如果不适用下面的shell的话,也可以手动修改配置文件|
#———————————————————————————–

sed -i ‘s#extension_dir = “./”#extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”\nextension = “memcache.so”\nextension = “pdo_mysql.so”\nextension = “imagick.so”\n#’ /usr/local/webserver/php/etc/php.ini
sed -i ‘s#output_buffering = Off#output_buffering = On#’ /usr/local/webserver/php/etc/php.ini
sed -i “s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g” /usr/local/webserver/php/etc/php.ini

#—————————————END 加入扩展模块——————————-+

第七步
#—————————————-+
#配置eAccelerator加速PHP:
#—————————————-+

mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini

#====================================================
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
#========配置文件===========================================================================
[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/webserver/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″
#=====================================================

第八步

#———————————————+
#创建www用户和组以及供虚拟主机使用的目录:
#———————————————+

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/htdocs/zqer
chmod +w /data0/htdocs/zqer
chown -R www:www /data0/htdocs/zqer

mkdir -p /data0/htdocs/nwww
chmod +w /data0/htdocs/nwww
chown -R www:www /data0/htdocs/nwww

#———————————————————+
第九步
#————————————————————————————————–+
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
#————————————————————————————————–+

rm -f /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf

#———————————————————–

输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的<value name=”display_errors”>0</value>改为<value name=”display_errors”>1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):
<?xml version=”1.0″ ?>
<configuration>

All relative paths in this config are relative to php’s install prefix

<section name=”global_options”>

Pid file
<value name=”pid_file”>/usr/local/webserver/php/logs/php-fpm.pid</value>

Error log file
<value name=”error_log”>/usr/local/webserver/php/logs/php-fpm.log</value>

Log level
<value name=”log_level”>notice</value>

When this amount of php processes exited with SIGSEGV or SIGBUS …
<value name=”emergency_restart_threshold”>10</value>

… in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator’s shared memory.
<value name=”emergency_restart_interval”>1m</value>

Time limit on waiting child’s reaction on signals from master
<value name=”process_control_timeout”>5s</value>

Set to ‘no’ to debug fpm
<value name=”daemonize”>yes</value>

</section>

<workers>

<section name=”pool”>

Name of pool. Used in logs and stats.
<value name=”name”>default</value>

Address to accept fastcgi requests on.
Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’
<value name=”listen_address”>127.0.0.1:9000</value>

<value name=”listen_options”>

Set listen(2) backlog
<value name=”backlog”>-1</value>

Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
<value name=”owner”></value>
<value name=”group”></value>
<value name=”mode”>0666</value>
</value>

Additional php.ini defines, specific to this pool of workers.
<value name=”php_defines”>
<value name=”sendmail_path”>/usr/sbin/sendmail -t -i</value>
<value name=”display_errors”>1</value>
</value>

Unix user of processes
<value name=”user”>www</value>

Unix group of processes
<value name=”group”>www</value>

Process manager settings
<value name=”pm”>

Sets style of controling worker process count.
Valid values are ‘static’ and ‘apache-like’
<value name=”style”>static</value>

Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
<value name=”max_children”>128</value>

Settings group for ‘apache-like’ pm style
<value name=”apache_like”>

Sets the number of server processes created on startup.
Used only when ‘apache-like’ pm_style is selected
<value name=”StartServers”>20</value>

Sets the desired minimum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
<value name=”MinSpareServers”>5</value>

Sets the desired maximum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
<value name=”MaxSpareServers”>35</value>

</value>

</value>

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when ‘max_execution_time’ ini option does not stop script execution for some reason
‘0s’ means ‘off’
<value name=”request_terminate_timeout”>0s</value>

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
‘0s’ means ‘off’
<value name=”request_slowlog_timeout”>0s</value>

The log file for slow requests
<value name=”slowlog”>logs/slow.log</value>

Set open file desc rlimit
<value name=”rlimit_files”>65535</value>

Set max core size rlimit
<value name=”rlimit_core”>0</value>

Chroot to this directory at the start, absolute path
<value name=”chroot”></value>

Chdir to this directory at the start, absolute path
<value name=”chdir”></value>

Redirect workers’ stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name=”catch_workers_output”>yes</value>

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
<value name=”max_requests”>102400</value>

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
<value name=”allowed_clients”>127.0.0.1</value>

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<value name=”environment”>
<value name=”HOSTNAME”>$HOSTNAME</value>
<value name=”PATH”>/usr/local/bin:/usr/bin:/bin</value>
<value name=”TMP”>/tmp</value>
<value name=”TMPDIR”>/tmp</value>
<value name=”TEMP”>/tmp</value>
<value name=”OSTYPE”>$OSTYPE</value>
<value name=”MACHTYPE”>$MACHTYPE</value>
<value name=”MALLOC_CHECK_”>2</value>
</value>

</section>

</workers>

</configuration>
第十步
#————————————————————————-+
启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
#————————————————————————-+

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

注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
#————————————–END—————————————-+

第十一步
#————————-+
安装Nginx 0.8.15
#————————-+

1、安装Nginx所需的pcre库:

tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ../

2、安装Nginx

tar zxvf nginx-0.8.15.tar.gz
cd nginx-0.8.15/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
cd ../

3、创建Nginx日志目录

mkdir -p /data0/logs
chmod +w /data0/logs
chown -R www:www /data0/logs
4、创建Nginx配置文件
①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:

rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

将nginx.conf文件中的内容复制过去。

#——————-内容如下———————————-
user www www;
worker_processes 8;
error_log /data0/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;
server_name www.zhengqianer.com;
index index.html index.htm index.php;
root /data0/htdocs/zqer/web;
#limit_conn crawler 20;
error_page 404 = /404.htm;
error_page 403 = /404.htm;

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;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
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 /data0/logs/access.log access;
}
server
{
listen 80;
server_name api.zhengqianer.com;
index index.html index.htm index.php;
root /data0/htdocs/zqer/api;

location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

log_format wwwlogs ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /data0/logs/wwwlogs.log wwwlogs;
}

server
{
listen 80;
server_name wap.zhengqianer.com;
index index.html index.htm index.php;
root /data0/htdocs/nwww/wap/;

location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

}

}
#———————–内容结束———————————–

②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:

vi /usr/local/webserver/nginx/conf/fcgi.conf

#————————写入以下内容 ———————
#pathinfo BUG 修正代码
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;

#———————————————————

第十二步
#————————
启动Nginx
#————————
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx

第十四步
#—————————-
配置开机自动启动Nginx + PHP
#—————————-
vi /etc/rc.local

在末尾增加以下内容:

# ulimit用于设置shell启动进程所占用的资源.
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
/data0/mysql/3306/mysql start
/usr/local/bin/memcached -d -m 10 -l 122.227.23.180 -p 11211 -u root -P /tmp/mecache.pid

 

#————————————END———————–+
第十五步
#—————————————————————+
优化Linux内核参数
#—————————————————————+
#打开配置文件
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

使配置立即生效:

#——————————–
/sbin/sysctl -p
#——————————–

#————————————–END———————————–+
在不停止Nginx服务的情况下平滑变更Nginx配置

1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:

/usr/local/webserver/nginx/sbin/nginx -t

如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
2、这时,输入以下命令查看Nginx主进程号:
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

屏幕显示的即为Nginx主进程号,例如:
6098
这时,执行以下命令即可使修改过的Nginx配置文件生效:

kill -HUP 6098
或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`

# 测试服务器安装是否正确
vi /data0/htdocs/zqer/index.php
写入以下内容:
#————————————–START———————————+
<?php
echo phpinfo();
?>
#————————————–END———————————–+

1.创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
编写每天定时切割Nginx日志的脚本
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path=”/data0/logs/”
mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
mv ${logs_path}wwwlogs.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/wwwlogs$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

 
2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
crontab: command not found解决方法
yum -y install vixie-cron crontabs
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
05 01 * * * /bin/bash /data0/logs/bakdb.sh
05 12 * * * /bin/bash /data0/logs/bakdb2.sh
05 20 * * * /bin/bash /data0/logs/bakdb3.sh
*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org
*/10 * * * * /bin/bash /data0/bak/shell/day.sh
01 00 * * * /bin/bash /data0/bak/shell/make.sh
00 02 * * * /bin/bash /data0/bak/shell/mon.sh
00 03 * * 0 /bin/bash /data0/bak/shell/year.sh

 
#—–如果不支持 crontab 命令的话,需要执行下面命令安装———–
# yum -y install gcc gcc-c++ autoconf vixie-cron
# yum -y install gcc gcc-c++ autoconf crontabs
#—————————————————————–
安装lftp用于同步文件
yum -y install lftp

lftp -v 查看版本
TOMCAT安装
加入NGINX支持
Lighttpd
阿里云RDS设置
GW=$(route -n | grep “10.0.0.0” | awk ‘{print $2}’ )
/sbin/route del -net 223.6.224.0/20
/sbin/route add -net 223.6.224.0/20 gw $GW
/sbin/route del -net 42.120.112.0/20
/sbin/route add -net 42.120.112.0/20 gw $GW

 

解压缩两个压缩包
tar zxvf libevent-1.4.14b-stable.tar.gz
tar zxvf memcached-1.4.0.tar.gz

先安装libevent
cd libevent-1.4.14b-stable
./configure
make
make install

cd ../memcached-1.4.0
./configure
make
make install

ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

启动
/usr/local/bin/memcached -d -m 10 -l 127.0.0.1 -p 11211 -u root -P /tmp/mecache.pid
/usr/local/bin/memcached -d -m 10 -l 110.76.42.61 -p 11211 -u root -P /tmp/mecache.pid
-d 以守护进程启用
-m 多大内存
-l 服务器ip地址
-u 以那个用户启动
-p 端口 一般默认为11211
-P 指定一个进程的id,一个标示
查看是否启动 netstat -tnl

 

————————————-安装流量监控iftop————————————————-
如果采用编译安装可以到iftop官网下载最新的源码包。
安装前需要已经安装好基本的编译所需的环境,比如make、gcc、autoconf等。安装iftop还需要安装libpcap和libcurses。
CentOS上安装所需依赖包:
yum install flex byacc libpcap ncurses ncurses-devel libpcap-devel
Debian上安装所需依赖包:
apt-get install flex byacc libpcap0.8 libncurses5
下载iftop
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
tar zxvf iftop-0.17.tar.gz
cd iftop-0.17
./configure
make && make install

configure: error: can’t find pcap.h
You’re not going to get very far without libpcap.
那你需要先安装libpcap,找到相应的rpm文件,比如:
-rw-r–r– 1 root root 108987 Apr 3 08:21 libpcap-0.9.4-8.1.i386.rpm
-rw-r–r– 1 root root 119062 Apr 3 08:21 libpcap-devel-0.9.4-8.1.i386.rpm
安装方法2:(懒人办法,最简单)
直接省略上面的步骤
flibpcap-0.9.4-14.el5.x86_64.rpm
CentOS系统:
yum install flex byacc libpcap ncurses ncurses-devel
wget ftp://fr2.rpmfind.net/linux/dag/redhat/el5/en/i386/dag/RPMS/iftop-0.17-1.el5.rf.i386.rpm
rpm -ivh iftop-0.17-1.el5.rf.i386.rpm
Debian系统 运行:apt-get install iftop
运行iftop
直接运行: iftop

1、iftop界面相关说明
界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。
中间的<= =>这两个左右箭头,表示的是流量的方向。
TX:发送流量
RX:接收流量
TOTAL:总流量
Cumm:运行iftop到目前时间的总流量
peak:流量峰值
rates:分别表示过去 2s 10s 40s 的平均流量
2、iftop相关参数
常用的参数
-i设定监测的网卡,如:# iftop -i eth1
-B 以bytes为单位显示流量(默认是bits),如:# iftop -B
-n使host信息默认直接都显示IP,如:# iftop -n
-N使端口信息默认直接都显示端口号,如: # iftop -N
-F显示特定网段的进出流量,如# iftop -F 10.10.1.0/24或# iftop -F 10.10.1.0/255.255.255.0
-h(display this message),帮助,显示参数信息
-p使用这个参数后,中间的列表显示的本地主机信息,出现了本机以外的IP信息;
-b使流量图形条默认就显示;
-f这个暂时还不太会用,过滤计算包用的;
-P使host信息及端口信息默认就都显示;
-m设置界面最上边的刻度的最大值,刻度分五个大段显示,例:# iftop -m 100M
进入iftop画面后的一些操作命令(注意大小写)
按h切换是否显示帮助;
按n切换显示本机的IP或主机名;
按s切换是否显示本机的host信息;
按d切换是否显示远端目标主机的host信息;
按t切换显示格式为2行/1行/只显示发送流量/只显示接收流量;
按N切换显示端口号或端口服务名称;
按S切换是否显示本机的端口信息;
按D切换是否显示远端目标主机的端口信息;
按p切换是否显示端口信息;
按P切换暂停/继续显示;
按b切换是否显示平均流量图形条;
按B切换计算2秒或10秒或40秒内的平均流量;
按T切换是否显示每个连接的总流量;
按l打开屏幕过滤功能,输入要过滤的字符,比如ip,按回车后,屏幕就只显示这个IP相关的流量信息;
按L切换显示画面上边的刻度;刻度不同,流量图形条会有变化;
按j或按k可以向上或向下滚动屏幕显示的连接记录;
按1或2或3可以根据右侧显示的三列流量数据进行排序;
按<根据左边的本机名或IP排序;
按>根据远端目标主机的主机名或IP排序;
按o切换是否固定只显示当前的连接;
按f可以编辑过滤代码,这是翻译过来的说法,我还没用过这个!
按!可以使用shell命令,这个没用过!没搞明白啥命令在这好用呢!
按q退出监控。

 

————————–安装svn服务器端———————-
yum install subversion 从镜像下载安装svn服务器端
cd /data0 //进入目录,准备创建svn目录
mkdir svn //创建一个svn目录
chmod -R 777 svn //修改目录权限为777
svnadmin create /data0/svn/zqer //创建一个svn版本仓库sunny(sunny可以随便起名字)
cd /data0/svn/zqer/conf //进入sunny版本仓库下的配置文件目录

下面要修改这个目录下的三个配置文件
(1)vi svnserve.conf //配置版本库信息和用户文件和用户密码文件的路径、版本库路径
[

# anon-access = read
# auth-access = write
# password-db = passwd
//这四行,前面的#号和空格去掉,变成
anon-access = none //改成none
auth-access = write
password-db = passwd
realm = zqer //改成自己的版本库
保存

(2)vi authz //文件,创建svn组和组用户的权限
[group]
sunny = gep,wce //创建一个sunny的组,并制定两个用户gep和wce

[/] //制定根目录下的权限
@sunny = rw //sunny组用户权限为读写
* = r //其他用户只有读权限
保存退出

(3) vi passwd //创建或修改用户密码
[users]
gep = 123456 //用户名为gep的用户的密码为123456
wce = 123456 //。。。
保存退出

然后要设置自启动
vi /etc/rc.local 打开自启动文件
文件内容如下
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/webserver/mysql/3306/mysql start
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
svnserve -d -r /data0/svn/zqer
#/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

 

svn命令:
lsof -i :3690 查看svn是否启动
ps aux |grep ‘svn’ 查找所有svn启动的进程
kill -9 2505 杀死2505这个查找到的svn进程
svnserve -d -r /data0/svn/zqer 启动svn(可以把这个放到/etc/local/rc.local文件中,实现开机自启动)

 
svn up //更新文件
#svn commit -m “注释” xxx.php //提交文件
svn ci -m’aaa’ test.php //提交文件

#svn add file //新建文件并添加到svn
svn add *.php //(添加当前目录下所有的php文件)
svn delete test.php //删除test.php
svn log test.php //查看test文件的log信息
svn cleanup //清理当前目录

svn co svn://172.19.5.12 ./ //检出一份版本库文件到当前目录

svn switch –relocate svn://192.168.1.253 svn://172.19.10.250 //重新定位SVN版本库地址

 
// SVN版本库起动方式,现在SVN下面有 sunny、test 两个版本库
1:单版本库起动 svnserve -d -r /usr/local/svn/sunny
2:多版本库起动 svnserve -d -r /usr/local/svn
区别在于起动svn时候的命令中的启动参数-r指定的目录。

限制不同的用户对不同的版本库操作权限,修改版本库中的conf目录下的 authz文件

以配置 sunny 版本库为例
vi authz
[groups]
teacher = sunny,sunny1
[sunny:/] //指定版本库跟目录下的权限
@teacher = rw //teacher组用户权限为读写
* = r //其他用户只有读权限
保存退出

vi passwd 设置组中用户的账号和密码
[users]
sunny = 123456
sunny1 = 123456

 

 

备份数据库
———————————
#!/bin/bash
echo ‘Wating…’
mUser=root
mPassword=’123123′
mMySQLDump=/alidata/server/mysql-5.1.57/bin/mysqldump
mBakDir=/alidata/bak
mFileName=db.sql
mFolder=`date “+%Y%m%d%Hdian”`
[ -d $mBakDir/$mFolder ] || mkdir $mBakDir/$mFolder
date >> $mBakDir/$mFolder/log.log
$mMySQLDump -h localhost -u$mUser -p$mPassword –databases yuyuexianmian > $mBakDir/$mFolder/$mFileName
gzip $mBakDir/$mFolder/$mFileName
date >> $mBakDir/$mFolder/log.log
echo ‘Done’

 

评论关闭