您的位置:首页 > 运维架构 > Shell

LNMP一键安装shell脚本

2014-11-05 10:48 435 查看
前段时间维护服务器,需要安装LNMP环境,所以就整理了一下,做为脚本,记录下来。
#!/bin/sh
#Copyright(c) 2010-2015 redapple (16325975@qq.com) 
#install LNMP
#Version 0.1.1
#Date 20140813
#------------增加yum源------------------------
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm #------------安装gcc------------------------
yum install gcc-c++  gcc ncurses-devel wget openssl openssl-devel zlib-devel -y
#--------------时间同步--------------------
ntpdate tiger.sina.com.cn
hwclock -w
#----------------下载安装pcre------------------
[ ! -f pcre-8.35.tar.gz ] && wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz tar xf pcre-8.35.tar.gz
cd pcre-8.35
./configure  --prefix=/usr/local/pcre
make && make install
#----------------下载安装nginx------------------
cd ..
groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx
[ ! -f nginx-1.6.1.tar.gz ] && wget http://nginx.org/download/nginx-1.6.1.tar.gz tar -xf nginx-1.6.1.tar.gz
cd nginx-1.6.1
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid  \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi
make && make install
#----------------设置nginx启动----------------
cd ..
cp nginx /etc/rc.d/init.d
chmod +x /etc/rc.d/init.d/nginx
chkconfig nginx on
#----------------下载安装mysql------------------
yum install cmake ncurses-devel -y
groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
[ ! -f mysql-5.5.38.tar.gz ] && wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.38.tar.gz tar xf mysql-5.5.38.tar.gz
cd mysql-5.5.38
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0
make && make install
[ -f /etc/my.cnf ] && rm -rf /etc/my.cnf
cp support-files/my-medium.cnf  /etc/my.cnf
sed -i 's#max_allowed_packet = 1M#max_allowed_packet = 16M#' /etc/my.cnf
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[ -f /etc/init.d/mysqld ] && rm -rf /etc/init.d/mysqld
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i '46s#basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
sed -i '47s#datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
service mysqld start
ps -ef |grep mysqld
#----------------下载并安装freetype------------------
cd ..
[ ! -f freetype-2.5.3.tar.gz ] && wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz tar -zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype
make && make install
#----------------下载并安装libmcrypt------------------
cd ..
[ ! -f libmcrypt-2.5.7.tar.gz ] && wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
#----------------下载并安装jpegsrc.v9------------------
cd ..
[ ! -f jpegsrc.v9a.tar.gz ] && wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz tar -xf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg
make && make install
#----------------下载并安装php------------------
cd ..
yum install -y libcurl bzip2-devel bzip2 libxml2-devel curl curl-devel gd libpng zlib
#---想让编译的php支持mcrypt、mhash扩展和libevent---------
#yum install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
[ ! -f php-5.5.15.tar.gz ] && wget http://cn2.php.net/distributions/php-5.5.15.tar.gz tar xf php-5.5.15.tar.gz
cd php-5.5.15
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--enable-fpm \
--enable-sockets \
--enable-sysvshm  \
--enable-xml  \
--enable-mbstring \
--enable-bcmath \
--enable-soap  \
--enable-shmop \
--enable-sysvsem \
--enable-pcntl \
--enable-zip \
--enable-gd-native-ttf \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir=/usr \
--with-mhash \
--with-mcrypt  \
--with-gettext \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-curl \
--with-xmlrpc \
--without-pear
make && make install
cp ./php.ini-production /usr/local/php/etc/php.ini
sed -i 's#;date.timezone =#date.timezone = PRC#' /etc/php.ini
sed -i 's#expose_php = On#expose_php = OFF#' /etc/php.ini
#----------------配置php-fpm------------------
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i 's#user = nobody#user = nginx#' /usr/local/php/etc/php-fpm.conf
sed -i 's#group = nobody#group = nginx#' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.max_children = 5#pm.max_children = 150#' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.start_servers = 2#pm.start_servers = 8#' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.min_spare_servers = 1#pm.min_spare_servers = 5#' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.max_spare_servers = 3#pm.max_spare_servers = 10#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#' /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
#----------------配置nginx支持php------------------
cd ..
cat nginx.conf >/etc/nginx/nginx.conf
mkdir -p /etc/nginx/vhosts
cp default.conf /etc/nginx/vhosts
#----------------检查php和php-fpm------------------
service php-fpm start
service nginx start
ps -ef | grep nginx
ps aux | grep php-fpm
#----------------新建index.php的测试页面------------------
cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>
EOF
echo "=============LNMP install OK !!!!============"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell LNMP 一键安装