centos6:lnmp一键搭建脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos6:lnmp一键搭建脚本相关的知识,希望对你有一定的参考价值。

1.把需要的脚本下载放到/root 目录下,然后运行本脚本即可自动化安装lnmp环境:

#!/bin/bash
#lnmp环境搭建自动化脚本 
#date 2017/8/22
#author vaedit
yum install epel-release -y
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ cmake ncurses-devel libtool zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel mysql-devel openldap openldap-* libmcrypt-devel mhash mcrypt function mysql_install(){ cd /root useradd -M -s /sbin/nologin mysql tar xf mysql-5.5.57.tar.gz cd mysql-5.5.57 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 make install ln -s /usr/local/mysql/bin/* /usr/bin cp support-files/my-large.cnf /etc/my.cnf -f cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/init.d/mysqld echo "开始初始化mysql实例" /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql echo "开始启动mysql" service mysqld start mysqladmin -u root password "52linux" } function php_install(){ cd /root tar xf php-5.6.31.tar.gz tar xf libiconv-1.15.tar.gz cd libiconv-1.15 ./configure --prefix=/usr/local/libiconv make && make install ln -sf /usr/lib64/libldap* /usr/lib cd /root/php-5.6.31 ./configure --prefix=/usr/local/php --with-mysql --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-gettext --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no --with-ldap --with-ldap-sasl make && make install cp php.ini-production /usr/local/php/etc/php.ini cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf cd /root/php-5.6.31 cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm chmod a+x /etc/rc.d/init.d/php-fpm } function nginx_install(){ useradd www -s /sbin/nologin cd /root tar xf nginx-1.10.3.tar.gz cd nginx-1.10.3 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre make && make install mkdir /data/www -p chown www.www /data/www cat >/usr/local/nginx/conf/nginx.conf <<EOF user www www; worker_processes 1; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /data/www; index index.html index.htm index.php; } location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www/$fastcgi_script_name; include fastcgi_params; } } } EOF } #检查是否安装已安装过lnmp环境 if [ -d /usr/local/mysql -o -d /usr/local/nginx -o -d /usr/local/php ];then read -p "改机器已安装过lnmp程序,是否继续安装【yes/no】" enter else enter="yes" fi if [ "$enter" == "yes" ];then mysql_install if [ $? -eq 0 ];then echo -e ‘\e[32;40;1mmysql安装成功\e[0m‘ else echo -e ‘\e[31;40;1mmysql安装失败\e[0m‘ exit 1 fi nginx_install if [ $? -eq 0 ];then echo -e ‘\e[32;40;1mnginx安装成功\e[0m‘ else echo -e ‘\e[31;40;1mnginx安装失败\e[0m‘ exit 1 fi php_install if [ $? -eq 0 ];then echo -e ‘\e[32;40;1mphp安装成功\e[0m‘ else echo -e ‘\e[31;40;1mphp安装失败\e[0m‘ exit 1 fi else echo -e ‘\e[31;40;1mlnmp安装失败\e[0m‘ exit 2 fi #程序启动判断: /usr/local/nginx/sbin/nginx if [ $? -eq 0 ];then echo -e ‘\e[32;40;1mnginx安装成功\e[0m‘ else echo -e ‘\e[31;40;1mnginx安装失败\e[0m‘ exit 1 fi /usr/local/php/sbin/php-fpm if [ $? -eq 0 ];then echo -e ‘\e[32;40;1mphp安装成功\e[0m‘ else echo -e ‘\e[31;40;1mphp安装失败\e[0m‘ exit 1 fi

 

以上是关于centos6:lnmp一键搭建脚本的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6/7一键安装LNMP(基于yum)

一键搭建LNMP脚本

Centos6.8下一键安装Lamp环境

Python实现一键安装部署LNMP环境

Centos6.8下一键安装Lamp环境

使用 shell 脚本实现 LANMP 一键安装