设为首页 收藏本站
查看: 1674|回复: 0

Centos6.5系统Lnmp一键安装脚本

  [复制链接]
累计签到:407 天
连续签到:1 天
发表于 2017-1-16 17:11:11 | 显示全部楼层 |阅读模式
首先上传以下软件包到root目录下
libmcrypt-2.5.8.tar.bz2
mysql-5.5.20.tar.gz
pcre-8.37.tar.bz2
php-5.6.13.tar.bz2
脚本信息:
#!/bin/bash
#auto by xiaohua
dbrootpwd="123456"
soft_path=/usr/local/src
nginx_ver="nginx-1.8.0"
nginx_path=/usr/local/nginx
php_path=/usr/local/php
mysql_path=/usr/local/mysql
function install_nginx {
clear
wget http://nginx.org/download/${nginx_ver}.tar.gz
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel -y
useradd -M -u 8001 -s /sbin/nologin  nginx
tar xf pcre-8.37.tar.bz2 -C $soft_path
tar xvf ${nginx_ver}.tar.gz -C $soft_path
cd $soft_path/$nginx_ver
./configure --prefix=$nginx_path \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module  \
--with-http_flv_module \
--with-http_spdy_module \
#--with-http_v2_module  \
--with-http_mp4_module \
--with-http_ssl_module \
--with-pcre=$soft_path/pcre-8.37
make && make install
if [  $? -ne 0 ]
then
    echo "install nginx faild"
    exit 1
fi
cat >$nginx_path/conf/nginx.conf<<EOF
user  nginx nginx;

worker_processes auto;

error_log  /date/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

    #include blocksip.conf; #denyip
        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone \$binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name www.xiaohua.top;
        index index.php index.html index.html;
        root  /date/www;

        #error_page   404   /404.html;
        #include enable-php.conf;
        
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
                include fastcgi.conf;
                }

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  off;
    }
#include vhost/*.conf;
}
EOF

cat >/etc/init.d/nginx<<EOF
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
        echo -n $"Starting \$prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon \$NGINX_SBIN -c \$NGINX_CONF
        RETVAL=\$?
        echo
        return \$RETVAL
}
stop() {
        echo -n $"Stopping \$prog: "
        killproc -p \$NGINX_PID \$NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=\$?
        echo
        return \$RETVAL
}
reload(){
        echo -n $"Reloading \$prog: "
        killproc -p \$NGINX_PID \$NGINX_SBIN -HUP
        RETVAL=\$?
        echo
        return \$RETVAL
}
restart(){
        stop
        start
}
configtest(){
    \$NGINX_SBIN -c \$NGINX_CONF -t
    return 0
}
case "\$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit \$RETVAL
EOF
mkdir -p /date/wwwlogs/
touch /date/wwwlogs/nginx_error.log
mkdir -p /date/www
echo "you are install nginx successfull">/date/www/index.html
echo "<?php phpinfo();?>" >/date/www/index.php
chmod +x /etc/init.d/nginx
/etc/init.d/nginx restart
chkconfig nginx on
}

function install_mysql(){
clear
cd
yum install gcc-c++ cmake ncurses-devel -y
tar xf mysql-5.5.20.tar.gz -C $soft_path/
useradd -M -s /sbin/nologin mysql
cd $soft_path/mysql-5.5.20/
cmake -DCMAKE_INSTALL_PREFIX=$mysql_path \
      -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  \
      -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
      -DDEFAULT_CHARSET=utf8  \
      -DDEFAULT_COLLATION=utf8_general_ci  \
      -DWITH_EXTRA_CHARSETS=all \
      -DWITH_MYISAM_STORAGE_ENGINE=1  \
      -DWITH_INNOBASE_STORAGE_ENGINE=1  \
      -DWITH_MEMORY_STORAGE_ENGINE=1  \
      -DWITH_READLINE=1  \
      -DENABLED_LOCAL_INFILE=1  \
      -DMYSQL_DATADIR=$mysql_path/data  \
      -DMYSQL-USER=mysql
make && make install
if [  $? -ne 0 ]
then
    echo "install mysql faild"
    exit 1
fi
chown -R mysql:mysql $mysql_path/
cat $mysql_path/support-files/my-small.cnf >/etc/my.cnf
cat $mysql_path/support-files/mysql.server >/etc/init.d/mysqld
sed -i '46,+1d' /etc/init.d/mysqld
sed -i '46ibasedir='$mysql_path'' /etc/init.d/mysqld
sed -i '47idatadir='$mysql_path/data'' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
$mysql_path/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=$mysql_path --datadir=$mysql_path/data --user=mysql &
ln -s $mysql_path/bin/* /bin/
chkconfig mysqld on
service mysqld start
rm -rf $mysql_path/data/test/.empty
mysqladmin -u root password '123456'
$mysql_path/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
$mysql_path/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "flush privileges;"
#$mysql_path/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
}

function install_libxml (){
cd
yum install -y libxml2-devel
tar xf libmcrypt-2.5.8.tar.bz2 -C $soft_path/
cd $soft_path/libmcrypt-2.5.8/
./configure --prefix=/usr/local/libmcrypt
make && make install
cd
echo "/usr/local/libmcrypt/lib" >> /etc/ld.so.conf
echo "$mysql_path/lib" >>/etc/ld.so.conf
ldconfig
echo "ldconfig">> /etc/rc.local
}
function install_php (){
clear
yum install -y  libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel php-pear
cd
tar xf php-5.6.13.tar.bz2 -C $soft_path
cd $soft_path/php-5.6.13
./configure --prefix=$php_path \
--with-config-file-path=$php_path \
--with-mysql=$mysql_path \
--with-mysqli=$mysql_path/bin/mysql_config \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--with-mcrypt=/usr/local/libmcrypt
make && make install
if [  $? -ne 0 ]
then
    echo "install php faild"
    exit 1
fi
cp $soft_path/php-5.6.13/php.ini-production /$php_path/php.ini
cp $php_path/etc/php-fpm.conf.default $php_path/etc/php-fpm.conf
sed -i '149,+1s/nobody/nginx/' $php_path/etc/php-fpm.conf
cp $soft_path/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
/etc/init.d/php-fpm start
}
install_nginx
install_mysql
install_libxml
install_php
echo "LNMP install successfull"
注:脚本中个模块都是根据实际生产环境写的,可用于实际生产环境。更多信息请点击www.tchua.top。




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-329295-1-1.html 上篇帖子: 在lnmp上部署phpMyAdmin 下篇帖子: XAMP安装Apacher无法启动 软件包 信息
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表