您的位置:首页 > 数据库 > Memcache

LNMP+memcached 脚本

2014-02-01 18:20 477 查看
在rh6.4 版本测试通过 在centos 只要更改库文件的链接位置就可以
#!/bin/bash
NGINXDIR=/usr/local/nginx 定义了安装nginx位置
MYSQLDIR=/usr/local/mysql 定义了安装mysql位置
PHPDIR=/usr/local/php 定义了安装php位置
STARTDIR=/usr/local/bin/memcached 定义饿了安装memcached命令的位置
NGINX=nginx-1.2.0 定义了nginx源码包的版本
MYSQL=mysql-5.1.34 定义了mysql源码包的版本
PHP=php-5.4.9 定义了php源码包的版本
LIB=libmcrypt-2.5.8 提供加密功能的库文件
MHASH=mhash-0.9.9.9 定义了哈希函数库的版本
LIBICONV=libiconv-1.13 处理中文各种编码之间的转换
STABLE=libevent-2.0.21-stable 事件库
MEMCACHED=memcached-1.4.5 memcached 版本
MEMCACHE=memcache-2.2.5
TAR=.tar.gz
NGINXMBER=81 nginx配置失败后返回的值
MYSQLMBER=82 mysql配置失败后返回的值
PHPBER=83 php配置失败后返回来的值
NGINXNU=84 nginx启动失败后返回来的值
MYSQLNU=85 mysql初始化失败后返回来的值
NGINXPID=86 nginx语法错误返回来的值
MEMCACHEMBER=87 memcached配置失败后返回来的值
PHPUNMBER=88 留着备用

for PORT in {80,3306} 利用for循环检查 80端口是否被占用

do
port1=`lsof -i :$PORT | awk 'NR==2{print $1}'`
netstat -nl | grep :$PORT &>/dev/null
if [ $? -eq 0 ];then

pkill -9 $port1

else
echo " $PORT port already by release"
fi
done

for WRAP in {freetype,freetype-devel,gcc,gcc-c++,openssl,openssl-devel,pcre,pcre-devel,zlib-devel,zlib,libxml2,libxml2-devel,curl,curl-devel,libpng,libpng-devel,openldap-devel,ncurses,ncurses-devel,openldap,openldap-clients,openldap-servers,pam_ldap,openjpeg-libs,libjpeg-turbo,libjpeg-turbo-devel}
do
rpm -q $WRAP &> /dev/null
if [ $? != 0 ];then
yum -y install $WRAP
else
echo "$WRAP already install "
fi
done
sleep 3

echo "--------------------------install nginx wrap--------------------------- "

for USER in {nginx,mysql}
do
id $USER &>/dev/null

if [ $? != 0 ];then

useradd $USER
else
echo "user $USER already be"

fi
done

cd /root

tar -zxf /root/$NGINX$TAR
cd /root/$NGINX

./configure --prefix=$NGINXDIR \
--pid-path=$NGINXDIR/nginx.pid \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=$NGINXDIR/client \
--http-proxy-temp-path=$NGINXDIR/proxy \
--http-fastcgi-temp-path=$NGINXDIR/fcgi \
--http-scgi-temp-path=$NGINXDIR/scgi \
--http-uwsgi-temp-path=$NGINXDIR/uwsgi \
--with-pcre
if [ $? -eq 0 ];then
make && make install
else
echo "nginx configure failed"
exit $NGINXMBER
fi
ln -s $NGINXDIR/sbin/nginx /usr/sbin
nginx -c $NGINXDIR/conf/nginx.conf

sleep 3
echo "----------------------install libmcrypt wrap---------------------"
cd /root
tar -zxf /root/$LIB$TAR
cd /root/$LIB
./configure && make && make install
cd libltdl
./configure --with-gmetad --enable-gexec --enable-ltdl-install && make && make install

sleep 3
echo "----------------------install mysql wrap------------------------"

cd /root
tar -zxf /root/$MYSQL$TAR
cd /root/$MYSQL
./configure --prefix=$MYSQLDIR --without-debug \
--with-innodb --with-plugins=partition \
--with-extra-charsets=all --enable-assembler \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-unix-socket-path=/tmp/mysql.sock \
--with-ssl
if [ $? -eq 0 ];then
make && make install
else
echo " mysql configure failed "
exit $MYSQLMBER
fi
chown -R mysql.mysql $MYSQLDIR/*
test -f /etc/my.cnf

if [ $? != 0 ];then
cp /root/$MYSQL/support-files/my-medium.cnf /etc/my.cnf
else
mv /etc/my.cnf /etc/my.conf
cp /root/$MYSQL/support-files/my-medium.cnf /etc/my.cnf
fi
cp /root/$MYSQL/support-files/mysql.server /etc/init.d/mysql

ln -s $MYSQLDIR/bin/* /usr/bin
ln -s $MYSQLDIR/lib/mysql/* /usr/lib64/
ln -s $MYSQLDIR/include/mysql/* /usr/include/
sed -i 's/^skip-federated$/# skip-federated/' /etc/my.cnf
chmod +x /etc/init.d/mysql
mysql_install_db --user=mysql
if [ $? -eq 0 ];then
service mysql restart
chkconfig --add mysql
chkconfig mysql on
else
echo "mysql initialize failed"
exit $MYSQLNU
fi
sleep 3

echo "----------------------install mhash -------------------------------"

cd /root
tar -zxf /root/$MHASH$TAR
cd /root/$MHASH
./configure && make && make install

sleep 3

echo "----------------------install libiconv---------------------------"
cd /root
tar -zxf /root/$LIBICONV$TAR
cd /root/$LIBICONV
./configure && make && make install

sleep 3

echo"-------------------install php wrap ---------------------------------"
\cp -rfp /usr/lib64/libldap* /usr/lib/
ln -s /usr/local/lib/libmcrypt* /usr/lib/
ln -s /usr/local/lib/libmhash.* /usr/lib/
ldconfig -v &> /dev/null
cd /root
tar -zxf $PHP$TAR
cd $PHP
./configure --prefix=$PHPDIR --with-mysql=$MYSQLDIR \
--with-zlib --enable-xml --disable-rpath \
--enable-safe-mode --enable-bcmath \
--enable-shmod --enable-sysvsem \
--with-curl --with-curlwrappers \
--enable-fpm --enable-fastcgi \
--with-mcrypt --with-gd \
--with-openssl --with-mhash \
--with-mysqli=$MYSQLDIR/bin/mysql_config \
--with-iconv-dir=/usr/lcoal \
--with-png-dir --with-jpeg-dir \
--with-freetype-dir --enable-gd-native-ttf \
--with-libxml-dir=/usr \
--enable-sockets --with-ldap \
--with-ldap-sasl --with-xmlrpc --enable-zip \
--enable-soap
if [ $? -eq 0 ];then
make ZEND_EXTRA_LIBS='-liconv' && make install
# if [ $? != 0 ];then
#echo "php make install failed"
# exit $PHPUNMBER
else
echo "php configure failed"
exit $PHPMBER
fi
# fi
\cp /root/$PHP/php.ini-production $PHPDIR/php/php.ini
\cp $PHPDIR/etc/php-fpm.conf.default $PHPDIR/etc/php-fpm.conf
sed -i '/fpm.pid/s/;//' $PHPDIR/etc/php-fpm.conf
sed -i '26a error_log = log/php-fpm.log' $PHPDIR/etc/php-fpm.conf
sed -i '27a log_level = error' $PHPDIR/etc/php-fpm.conf
sed -i '/daemonize/s/;// ' $PHPDIR/etc/php-fpm.conf
sed -i '/user/s/nobody/nginx/' $PHPDIR/etc/php-fpm.conf
sed -i '/group/s/nobody/nginx/' $PHPDIR/etc/php-fpm.conf
# for FAST-CGI in {pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers}
# do
# for NUMBER in {32,15,5,32}
# do
# sed -i '/$FAST-CGI/s/[0-9]/$NUMBER/' $PHPDIR/etc/php-fpm.conf
# done
# done
cp -rf /root/$PHP/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
service php-fpm restart
chkconfig php-fpm on
sed -i '/index.php/s/#//' $NGINXDIR/conf/nginx.conf
sed -i '45c index index.php index.html index.html;' $NGINXDIR/conf/nginx.conf
sed -i '/fastcgi_pass/s/#//' $NGINXDIR/conf/nginx.conf
sed -i '/fastcgi_param/s/#//' $NGINXDIR/conf/nginx.conf
sed -i '/include/s/#//g' $NGINXDIR/conf/nginx.conf
sed -i '66a root html;' $NGINXDIR/conf/nginx.conf
sed -i '71a }' $NGINXDIR/conf/nginx.conf
sed -i '65a location ~ \.php$ { ' $NGINXDIR/conf/nginx.conf

sed -i '/nginx/s/$nginx_version//' $NGINXDIR/conf/fastcgi_params
sed -i '4a fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' $NGINXDIR/conf/fastcgi_params

pkill -9 nginx
nginx -t

if [ $? -eq 0 ];then
nginx
else
echo "configure file have failed"
exit $NGINXPID
fi
sleep 3

echo "-------------------install libevent--------------------------"
cd /root
tar -zxf /root/$STABLE$TAR
cd /root/$STABLE
./configure && make && make install

echo /usr/local/lib/ >> /etc/ld.so.conf.d/libevent.conf
# ldconfig $>/dev/null

sleep 3

echo "----------------------install memcached--------------------------"
cd /root
tar -zxf /root/$MEMCACHED$TAR
cd /root/$MEMCACHED
./configure && make && make install
$STARTDIR -u root -m 100 -c 200 -n 10 -f 2 -d

sleep 3
echo "----------------------install memcache----------------------------"
cd /root
tar -zxf /root/$MEMCACHE.tgz
cd /root/$MEMCACHE
$PHPDIR/bin/phpize
./configure --with-php-config=$PHPDIR/bin/php-config \
--enable-memcache
if [ $? -eq 0 ];then
make && make install
else
echo "memcache install failed"
exit $MEMCACHEMBER
fi
sed -i '728a extension_dir=鈥?usr/local/php5nginx/lib/php/extensions/no-debug-non-zts-20100525/鈥? $PHPDIR/php/php.ini
sed -i '729a extension=memcache.so'
service php-fpm reload
echo "http {" >> $NGINXDIR/conf/nginx.conf
echo " upstream web {" >> $NGINXDIR/conf/nginx.conf
echo " server 200.1.1.20:80;" >> $NGINXDIR/conf/nginx.conf
echo " server 200.1.1.30:80;" >> $NGINXDIR/conf/nginx.conf
echo " }" >> $NGINXDIR/conf/nginx.conf
echo " server {" >> $NGINXDIR/conf/nginx.conf
echo " listen 80;" >> $NGINXDIR/conf/nginx.conf
echo " server_name www.baidu.com;" >> $NGINXDIR/conf/nginx.conf
echo " location / {" >> $NGINXDIR/conf/nginx.conf
echo ' set $memcached_key $uri;' >> $NGINXDIR/conf/nginx.conf
echo ' memcached_pass 127.0.0.1:11211;' >> $NGINXDIR/conf/nginx.conf
echo " default_type text/html;" >> $NGINXDIR/conf/nginx.conf
echo " error_page 404 @fallback;" >> $NGINXDIR/conf/nginx.conf
echo " }" >> $NGINXDIR/conf/nginx.conf
echo " location @fallback {" >> $NGINXDIR/conf/nginx.conf
echo " proxy_pass http://web;" >> $NGINXDIR/conf/nginx.conf
echo " }" >> $NGINXDIR/conf/nginx.conf
echo " } " >> $NGINXDIR/conf/nginx.conf
echo " }" >> $NGINXDIR/conf/nginx.conf
pkill -9 nginx
nginx -t
if [ $? -eq 0 ];then
nginx
else
echo "because of memcached configure file failed "
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LNMP+memcached脚本