LNMP(nginx+mysql+php)环境/架构 一键安装脚本

LNMP(nginx+mysql+php)环境/架构 一键安装脚本,该脚本已经在CentOS 7.1 上测试通过,用时27分,硬件环境(1G,1U)。该脚本有安装PHP加速器xcache:

#!/bin/bash

#该脚本的作用 :在线一键部署LNMP
#Write      :King
#Date      :2015-03-19

#mysql      数据存放目录为/data/mysql
#php        主配置文件在 /usr/local/php/etc
#nginx      web 程序目录/usr/local/nginx/html/index,主配置目录 /usr/local/nignx/conf/nginx.conf

#源码下载目录
SoftDir='/usr/local/src'

#定义安装日志路径
LOG_INS='/var/log/install.log'

#定义Mysql 源码目录:
MysqlS='/usr/local/mysql'

#define make
function MAKE(){
    if [ `echo $?` -eq 0 ];then
            make >> $LOG_INS 2>&1
        else
            exit
    fi
}

#define make install
function MAKE_INS(){
    if [ `echo $?` -eq 0 ];then
            make install >> $LOG_INS 2>&1
        else
            exit
    fi
}

#安装系统扩展源:Fedoraproject.org/pub/epel
if [ `awk '{print $3}' /etc/RedHat-release |awk -F '.' '{print $1}'` -eq 6 ];then
                rpm -ivh >> $LOG_INS 2>&1
        elif [ `awk '{print $4}' /etc/redhat-release |awk -F '.' '{print $1}'` -eq 7 ];then
                rpm -ivh >> $LOG_INS 2>&1
fi

#安装系统运维包:
yum install -y lrzsz gcc gcc-c++  bzip2 bzip2-devel make man vim tree unzip wget lua-devel lua-static patch libxml2-devel libxslt libxslt-devel gd gd-devel ntp ntpdate screen sysstat tree rsync lsof autoconf gettext  gettext-devel automake libtool git >> $LOG_INS 2>&1

#升级系统:
yum update -y >> $LOG_INS 2>&1

#替换selinux 配置:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#下载安装Mysql: 
cd $SoftDir && wget -q

#解压:
tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

#移动解压目录病重命名Mysql:
mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql

#添加mysql 系统用户:
if [ -z `grep mysql /etc/passwd` ] ;then
        useradd -s /sbin/nologin mysql
fi

#创建mysql 初始化数据目录:
if [ ! -d "/data/mysql" ] ;then
        mkdir -p /data/mysql
fi

#将mysql 初始化目录所属主和组修改为mysql:
chown -R mysql.mysql /data/mysql/

#初始化
cd $MysqlS && ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql  >> $LOG_INS 2>&1

#备份系统默认的my.cnf 文件:
mv /etc/my.cnf{,.bak}

#复制mysql 的 主配置文件到etc 目录下病重命名为my.cnf
 \cp support-files/my-default.cnf /etc/my.cnf

#复制mysql 的启动脚本到/etc/init.d 目录下:
 \cp support-files/mysql.server /etc/init.d/mysqld

#赋予启动755 权限:
chmod 755 /etc/init.d/mysqld

#修改my.cnf 文件配置如下:
cat << EOF > /etc/my.cnf
[mysqld]
pid-file=/data/mysql/mysql.pid
log-error=/var/log/mysql.log
datadir = /data/mysql
basedir = /usr/local/mysql
character-set-server=utf8
port = 3306
socket = /tmp/mysql.sock
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 16M
thread_concurrency = 8
binlog_format=mixed
server-id = 1
slow-query-log = 1
slow-query-log-file = /data/mysql/mysql-slow.log
log-bin = mysql-bin
log-bin-index = mysql-bin.index
symbolic-links = 0
skip-name-resolve

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8

[mysqldump]
quick
max_allowed_packet = 16M

#[mysqld_safe]

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

#启动mysql:
service mysqld start

if [ `echo $?` -eq 0 ] ;then
        echo "Mysql started"
else
        exit
fi

#将Mysqld 设置为随机启动:
chkconfig --add mysqld && chkconfig mysqld on

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d0933e1d682ca29d7899c318d103eb3e.html