上接一條命令搞定nginx安裝,噱頭之二,直接上命令
#!/bin/bash
dir_name=`pwd`;
mkdir -p {/data1/www,/data1/www/logs,/usr/local/myspace/etc/fpm.d};
yum install -y mysql-server mysql mysql-devel httpd-devel.x86_64 libxml2-devel.x86_64 openssl-devel.x86_64 libcurl-devel.x86_64 bzip2-devel.x86_64 sqlite-devel.x86_64 libxslt-devel.x86_64;
ln -s /usr/lib64/mysql/libmysqlclient.so /usr/lib/libmysqlclient.so;
wget http://cn2.php.net/distributions/php-5.6.21.tar.gz -P /data1/source && \
cd /data1/source && \
tar xvfz /data1/source/php-5.6.21.tar.gz && \
cd php-5.6.21 && \
./configure --prefix=/usr/local/myspace \
--exec-prefix=/usr/local/myspace \
--bindir=/usr/local/myspace/bin \
--sbindir=/usr/local/myspace/sbin \
--sysconfdir=/usr/local/myspace/etc \
--with-config-file-path=/usr/local/myspace/lib \
--with-config-file-scan-dir=/etc/php.d \
--localstatedir=/usr/local/myspace/var \
--with-curl=shared,/usr \
--with-mysql=shared,/usr \
--with-libxml-dir=/usr \
--with-gd=shared \
--with-pdo-sqlite=shared,/usr \
--with-sqlite3=shared,/usr \
--with-xsl=shared,/usr \
--enable-xmlwriter=shared \
--enable-fastcgi=shared \
--enable-fpm=shared \
--enable-json=shared \
--enable-dom=shared \
--enable-phar=shared \
--enable-xml=shared \
--enable-xmlreader=shared \
--enable-xmlwriter=shared \
--enable-zip=shared \
--enable-wddx=shared \
--enable-fileinfo=shared \
--enable-pdo=shared && \
make && \
make install;
cd $dir_name && \
cp php-fpm.conf /usr/local/myspace/etc/php-fpm.conf && \
cp php-fpm /etc/init.d/php-fpm && \
cp fpm.d.hello.yesuhuangsi.com.conf /usr/local/myspace/etc/fpm.d/hello.yesuhuangsi.com.conf && \
chmod a+x /etc/init.d/php-fpm;
php-fpm.conf
[global]
pid = run/php-fpm.pid
error_log = logs/php-fpm.log
emergency_restart_threshold = 20
emergency_restart_interval = 60s
process_control_timeout = 0
process.max = 2048
daemonize = yes
rlimit_files = 65535
rlimit_core = 67108864
events.mechanism = epoll
; auto include phpfpm configure
include = etc/fpm.d/hello.yesuhuangsi.com.conf
php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
php_fpm_BIN=/usr/local/myspace/sbin/php-fpm
php_fpm_CONF=/usr/local/myspace/etc/php-fpm.conf
php_fpm_PID=/usr/local/myspace/var/run/php-fpm.pid
prog=$(basename $php_fpm_BIN)
start() {
[ -x $php_fpm_BIN ] || exit 5
[ -f $php_fpm_CONF ] || exit 6
echo -n $"Starting $prog: "
ulimit -u 4096
daemon $php_fpm_BIN -y $php_fpm_CONF
echo -e "`date` php-fpm start ." >> /var/log/php-fpm.log
num=`iptables -L -n|grep -E "DROP|reject"|awk '$4 ~/0.0.0.0\/0/ {print}'|grep -wc 80:81`
if [ $num -ne 0 ];then
for i in `seq 1 $num`;do iptables -D INPUT -p tcp -m tcp --dport 80:81 -j DROP ;done
fi
echo
}
stop() {
[ -x $php_fpm_BIN ] || exit 5
[ -f $php_fpm_CONF ] || exit 6
echo -n $"Stopping $prog: "
iptables -I INPUT -p tcp -m tcp --dport 80:81 -j DROP
killproc $prog -TERM
usleep 1000
kill -9 `cat $php_fpm_PID` > /dev/null 2>&1
pids=`ps aux|grep [p]hp-fpm|grep -v root | awk '{print $2}'`
if [ -n "$pids" ];then
for pid in $pids;do kill -9 $pid > /dev/null 2>&1 ;done
fi
sleep 2
echo -e "`date` php-fpm stop ." >> /var/log/php-fpm.log
echo
}
configtest() {
$php_fpm_BIN -t -y $php_fpm_CONF
}
reload() {
echo -n $"Reloading $prog: "
killproc $php_fpm_BIN -USR2
}
reopen() {
echo -n $"Reopening $prog: "
killproc $php_fpm_BIN -USR1
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
status)
status php-fpm
;;
reopen)
reopen
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|reopen|configtest|status}"
exit 2
esac
fpm.d.hello.yesuhuangsi.com.conf
[hello.yesuhuangsi.com.conf]
user = www
group = www
listen = 127.0.0.1:8999
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 128
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 1500
request_terminate_timeout = 30
catch_workers_output = no
security.limit_extensions = ""
php_admin_value[include_path] = ".:/usr/local/myspace/lib/php"