#/bin/bash
#----------------------------------------------------------------
#data=2015-03-19
#auth:tongcheng
#Nginx version:1.6.2
#Php:5.4
#Mysql:5.5.0
#-----------------------------------------------------------------
#删除关于安装软件的包
delete() {
rm -rf /usr/local/nginx*
rm -rf /etc/init.d/nginx
rm -rf /etc/nginx.conf
rm -rf /usr/local/mysql-5.6.22
rm -rf /etc/init.d/mysqld
rm -rf /etc/my.cnf
rm -rf /usr/local/php*
rm -rf /etc/php.ini
}
#安装依赖包
pack() {
yum install gcc gcc-c++ make pcre-* zlib-* cmake ncurses-devel libjpeg* libpng* freetype* libcurl-devel libvpx-devel libxml2 libxml2-devel libXpm libXpm-devel libXpm.i686 libXpm.i686-devel openldap-devel -y
}
#创建用户和用户组
user() {
groupdel nginx
userdel nginx
groupadd -g 8000 nginx
useradd -u 8000 -G nginx -g nginx -s /sbin/nologin -r nginx
groupdel mysql
userdel mysql
groupadd -g 3306 mysql
useradd -u 3306 -G mysql -g mysql -s /sbin/nologin -r mysql
}
#安装nginx服务
nginx() {
dir=/opt
cd $dir &&
wget http://nginx.org/download/nginx-1.6.2.tar.gz &&
tar xvf nginx-1.6.2.tar.gz &&
cd nginx-1.6.2 &&
./configure --prefix=/usr/local/nginx-1.6.2 --user=nginx --group=nginx --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module && make && make install &&
abc=`lsof -i :80 | awk ‘{print $1}‘ | sed -n 2p`
if [ $abc ];then
killall $abc
fi
/usr/local/nginx-1.6.2/sbin/nginx
}
#安装mysql数据库
mysql(){
mysql=http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.22.tar.gz
dir=/opt
cd $dir &&
wget $mysql &&
tar xvf mysql-5.6.22.tar.gz &&
chown -R root:root mysql-5.6.22 &&
cd mysql-5.6.22 &&
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.22 \
-DMYSQL_DATADIR=/usr/local/mysql-5.6.22/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DMYSQL_GROUP=mysql && make && make install &&
chown -R root:mysql /usr/local/mysql-5.6.22 &&
chown -R mysql:mysql /usr/local/mysql-5.6.22/data &&
cp -a /usr/local/mysql-5.6.22/support-files/my-default.cnf /etc/my.cnf &&
/usr/local/mysql-5.6.22/scripts/mysql_install_db --user=mysql --group=mysql --datadir=/usr/local/mysql-5.6.22/data/ --basedir=/usr/local/mysql-5.6.22/ --defaults-file=/etc/my.cnf &&
cp -a /usr/local/mysql-5.6.22/support-files/mysql.server /etc/init.d/mysqld &&
chkconfig --add mysqld &&
chkconfig mysqld on &&
abc=`lsof -i :3306 | awk ‘{print $1}‘ | sed -n 2p`
if [ $abc ];then
killall $abc
fi
/etc/init.d/mysqld restart
}
php() {
dir=/opt
cd $dir
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
wget http://mirrors.sohu.com/php/php-5.4.28.tar.gz
tar xvf libmcrypt-2.5.7.tar.gz
tar xvf php-5.4.28.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt && make && make install
cd /opt/php-5.4.28
./configure --prefix=/usr/local/php-5.4.28 --enable-fpm --with-libxml-dir --with-zlib --with-curl --with-gd --with-vpx-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxp-dir --with-iconv --with-ldap --with-mcrypt=/usr/local/libmcrypt/ --with-mysql=/usr/local/mysql-5.6.22/ --with-mysqli=/usr/local/mysql-5.6.22/bin/mysql_config --with-pdo-mysql --with-freetype-dir && make && make install
if [ $? -ne 0 ];then
cp -frm /usr/lib64/libXp* /usr/lib64/
cp -frm /usr/lib64/libldap* /usr/lib/
fi
cp -a php.ini-development /usr/local/php-5.4.28/lib/php.ini
cp /usr/local/php-5.4.28/etc/php-fpm.conf.default /usr/local/php-5.4.28/etc/php-fpm.conf
abc=`lsof -i :9000 | awk ‘{print $1}‘ | sed -n 2p`
if [ $abc ];then
killall $abc
fi
/usr/local/php-5.4.28/sbin/php-fpm
}
delpack(){
rm -rf /opt/php*
rm -rf /opt/nginx*
rm -rf /opt/mysql*
}
delete
#调用pack函数安装依赖包
pack
if [ $? -eq 0 ];then
echo "软件依赖包全部安装好";
else
echo "软件依赖包没有安装好,请检查yum源"
exit
fi
#调用user函数创建用户
user
if [ $? -eq 0 ];then
echo "创建用户和用户组成功"
else
echo "用户创建未成功,请检查原因"
exit
fi
#安装nginx软件
nginx
if [ $? -eq 0 ];then
echo "nginx已全部安装好"
else
echo "nginx安装失败,请检查原因"
rm -rf /opt/nginx-1.6.2.tar.gz
rm -rf /usr/local/nginx-1.6.2
exit
fi
#安装mysql的数据库
mysql
if [ $? -eq 0 ];then
echo "mysql已全部安装好"
else
echo "mysql数据库安装失败,请检查原因"
rm -rf /opt/mysql-5.6.22.tar.gz
rm -rf /usr/local/mysql-5.6.22
exit
fi
#安装php
php
if [ $? -eq 0 ];then
echo "php已全部安装好"
exit
else
echo "php安装失败,请检查原因"
rm -rf /opt/php-5.4.28.tar.gz
rm -rf /usr/local/php-5.4.28
exit
fi
本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1622592
原文地址:http://tongcheng.blog.51cto.com/6214144/1622592