Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86941
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-12 22:31
文章分类

全部博文(26)

文章存档

2016年(26)

我的朋友

分类: 系统运维

2016-06-03 15:35:19

#!/bin/bash
#auto install_lnmp 
#autor by yn 2016-4
if [ ! -d /opt/local -o ! -d /opt/src ];then
mkdir -pv /opt/src
mkdir -pv /opt/local
fi


SOURCE=/opt/src
INSTALL_DIR=/opt/local
NGINX_CODE=nginx-1.6.3.tar.gz
NGINX_DIR=nginx-1.6.3
PHP_CODE=php-5.6.20.tar.gz
PHP_DIR=php-5.6.20
CMAKE_CODE=cmake-2.8.8.tar.gz
CMAKE_DIR=cmake-2.8.8
MYSQL_CODE=mysql-5.6.5-m8.tar.gz
MYSQL_DIR=mysql-5.6.5-m8
######################################installnginx##############################################


function nginx_install()
{
yum -y install gcc* openssl* pcre*
cd $SOURCE 
#wget
tar -zxvf nginx-1.6.3.tar.gz;cd $NGINX_DIR ;./configure --prefix=$INSTALL_DIR/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre && make && make install
$INSTALL_DIR/nginx/sbin/nginx
NGINX_PRO=$(ps -ef |grep nginx |grep -v grep)
if [ -n "$NGINX_PRO" ];then 
echo -e "\033[32m nginx is running \033[0m "
else
echo -e "\033[32m nginx is not ok,please check......... \033[0m "
exit 3
fi
}
#nginx_install




#####################################installphp##############################################
function php_install()
{
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel  curl curl-devel gcc* -y
cd $SOURCE
wget
tar -zxvf $PHP_CODE
cd $PHP_DIR
./configure --prefix=$INSTALL_DIR/php \
--with-config-file-path=$INSTALL_DIR/php/etc --with-bz2 --with-curl \
--enable-ftp --enable-sockets --disable-ipv6 --with-gd \
--with-jpeg-dir=$INSTALL_DIR --with-png-dir=$INSTALL_DIR \
--with-freetype-dir=$INSTALL_DIR --enable-gd-native-ttf \
--with-iconv-dir=$INSTALL_DIR --enable-mbstring --enable-calendar \
--with-gettext --with-libxml-dir=$INSTALL_DIR --with-zlib \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd \
--enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make && make install
cp php.ini-production $INSTALL_DIR/php/etc/php.ini
cp $INSTALL_DIR/php/etc/php-fpm.conf.default $INSTALL_DIR/php/etc/php-fpm.conf
$INSTALL_DIR/php/sbin/php-fpm
PHP_PRO=$(ps -ef |grep php-fpm |grep -v grep)
if [ -n "$PHP_PRO" ];then
      echo -e "\033[32m php-fpm is running \033[0m "
else
      echo -e "\033[32m php-fpm is not ok,please check......... \033[0m "
exit 2
fi
cd $INSTALL_DIR/nginx/conf
sed -i '45s/html/& index.php/' nginx.conf  #匹配添加字段
sed -i  '65,71s/.*#//g' nginx.conf
sed -i '69s/\/scripts/\/opt\/local\/nginx\/html/g' nginx.conf
cd $INSTALL_DIR/nginx/html
cat > index.php < phpinfo();
?>
EOF
killall nginx
killall php-fpm
$INSTALL_DIR/nginx/sbin/nginx
$INSTALL_DIR/php/sbin/php-fpm
echo -e "\033[32m you can http:\\IP\index.php. Check php....... \033[0m"
exit 0
}
#php_install


#################################install mysql############################


function mysql_install()
{
yum -y install  autoconf automake imake libxml2-devel ncurses-devel \
expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel
cd $SOURCE
#wget --no-check-certificate
tar -zxvf $CMAKE_CODE;cd $CMAKE_DIR;./bootstrap && gmake && gmake install


cd $SOURCE
wget
tar -zxvf $MYSQL_CODE;cd $MYSQL_DIR
cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=UTF8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_INNODB_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306


make && make install
cd $SOURCE/$MYSQL_DIR
groupadd mysql
useradd -r -g mysql mysql
cd $INSTALL_DIR
ln -s /opt/src/mysql-5.6.5-m8.tar.gz mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql       #初始化数据库
chown -R root .
chown -R mysql data
# Next command is optional
cp support-files/my-medium.cnf /etc/my.cnf  #复制配置文件
./bin/mysqld_safe &
# Next command is optional
cp support-files/mysql.server /etc/init.d/mysql.server   #初始化数据库
chmod 755 /etc/init.d/mysql.server
chkconfig --add mysql.server            #添加启动服务
service mysql.server start 
echo 'PATH=/opt/local/mysql/bin:$PATH'>>/etc/profile   #设置环境变量,只会在子shell中生效
source /etc/profile
export PATH
MYSQL_PRO=$(ps -ef |grep mysql |grep -v grep)
if [ -n "$MYSQL_PRO" ];then
echo -e "\033[32m mysql is running \033[0m"
exit 0
else
echo -e "\033[32m mysql is not ok,please check.......\033[0m"
exit 2
fi
            
}
#mysql_install
echo -e "\033[32m please wait install...... \033[1m"
PS3="please choose the service you need:"                  #注意这里的PS3是专门为select,作为输出提示符信息用的
select i in "nginx_install" "php_install" "mysql_install"  #select循环和for循环有些类似,只不过更加人性化一些,交互性更好,适合功能比较多的大型脚本。
do
case $i in
nginx_install)
nginx_install
;;
php_install)
php_install
;;
mysql_install)
mysql_install
;;
*)
  echo -e "Usage $0 1|2|3|4|help"
exit 1
esac
done

阅读(1538) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~