#!/bin/bash
#安装nginx
echo "安装nginx服务"
wget http://nginx.org/download/nginx-1.11.4.tar.gz &>/dev/null
if [ $? -eq 0 ]
thenecho "nginx-1.11.4安装包下载完成"echo "--开始安装必要的依赖文件--"yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel &>/dev/nullif [ $? -eq 0 ]thenecho "依赖文件安装完成"echo "解压nginx安装包到/usr/local目录下"tar -xf nginx-1.11.4.tar.gz -C /usr/local/srccd /usr/local/src/nginx-1.11.4/echo "创建nginx运行用户www"useradd www -s /sbin/nologinecho "预编译nginx"./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --user=www --group=www &>/dev/nullif [ $? -eq 0 ]thenecho "预编译完成"echo "编译安装"make &>/dev/null && make install &>/dev/nullif [ $? -eq 0 ]thenecho "编译安装完成"echo "启动nginx服务"/usr/local/nginx/sbin/nginx &>/dev/nullngx=`ps -ef | grep nginx | wc -l`if [ $ngx -gt 1 ]thenecho "nginx启动成功"elseecho "nginx启动失败"fielseecho "编译安装失败"fielseecho "预编译失败"fielseecho "安装依赖文件失败"fielseecho "nginx-1.11.4安装包下载失败,请检查原因"fi
cd
#安装PHP服务
wget http://cn2.php.net/distributions/php-5.6.6.tar.gz --no-check-certificate &>/dev/null
if [ $? -eq 0 ]
thenecho "PHP安装包下载完成"echo "开始安装PHP依赖文件"yum -y install gcc autoconf freetype gd libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel freetype-devel libjpeg-devel bzip2 bzip2-devel openssl openssl-devel &>/dev/nullif [ $? -eq 0 ]thenecho "依赖文件下载成功"echo "安装libmcrypt"wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz --no-check-certificate &>/dev/nullif [ $? -eq 0 ]thenecho "安装libmcrypt成功"tar xf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configure --prefix=/usr/local/libmcrypt &>/dev/null && make &>/dev/null && make install &>/dev/nullcdtar xf php-5.6.6.tar.gz -C /usr/local/srcecho "预编译PHP"cd /usr/local/src/php-5.6.6./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/usr/local/php5.6/etc/ --with-bz2 --enable-maintainer-zts &>/dev/nullif [ $? -eq 0 ]thenecho "PHP预编译成功"echo "编译安装PHP"make &>/dev/null && make install &>/dev/nullif [ $? -eq 0 ]thenecho "编译安装PHP成功"echo "生成php.ini配置文件"cp /usr/local/src/php-5.6.6/php.ini-production /usr/local/php5.6/etc/php.iniecho "修改fpm配置文件"cd /usr/local/php5.6/etc/cp php-fpm.conf.default php-fpm.confsed -i 's/user = nobody/user = www/g' php-fpm.confsed -i 's/group = nobody/group = www/g' /usr/local/php5.6/etc/php-fpm.confsed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' php-fpm.confsed -i 's/pm.max_children = 5/pm.max_children =300/g' php-fpm.confsed -i 's/pm.start_servers = 2/pm.start_servers =20/g' php-fpm.confsed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 20/g' php-fpm.confsed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 100/g' php-fpm.confsed -i 's@;pid = run/php-fpm.pid@pid = run/php-fpm.pid@g' php-fpm.conf#生成启动文件cp /usr/local/src/php-5.6.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpmchkconfig --add php-fpmchkconfig php-fpm on/etc/init.d/php-fpm start &>/dev/nullphp=`netstat -antpu | grep php-fpm | wc -l`if [ $php -gt 0 ]thenecho "php服务启动成功"echo "查看PHP是否安装mysql模块"mokuai=`/usr/local/php5.6/bin/php -m |grep mysqli |wc -l`if [ $mokuai -eq 1 ]thenecho "PHP连接mysql模块已经安装"elseecho "PHP连接mysql模块安装失败"fielseecho "PHP服务启动失败"fielseecho "编译安装失败"fielseecho "PHP预编译失败"fielseecho "安装libmcrypt失败"fielseecho "依赖文件下载失败"fi
elseecho "PHP安装包下载失败"
fi
#安装mysql服务
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-5.7.26-1.el7.src.rpm &>/dev/null
if [ $? -eq 0 ]
thenecho "mysql安装包下载完毕"echo "卸载boost"yum -y remove boost-* &>/dev/nullrpm -ivh mysql-community-5.7.26-1.el7.src.rpm &>/dev/null#下载解压工具yum install -y bzip2 &>/dev/nullif [ $? -eq 0 ]thenecho "bzip2解压缩工具下载完成"cd /root/rpmbuild/SOURCES/tar xf boost_1_59_0.tar.bz2 -C /root/echo "卸载系统自带的mysql"yum -y remove mysql* &>/dev/nullyum -y remove mariadb* &>/dev/nullecho "安装mysql依赖包"yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel &>/dev/nullif [ $? -eq 0 ]thenecho "mysql依赖包下载完成"echo "创建mysql用户和用户组"groupadd mysql && useradd -M -s /sbin/nologin -r -g mysql mysqlecho "创建mysql数据库存放位置并修改目录权限"mkdir -p /data/mysql/{data,log} && chown -R mysql:mysql /data/mysqlecho "解压源码包"cd /root/rpmbuild/SOURCES/tar xf mysql-5.7.26.tar.gz -C /root/cdcd mysql-5.7.26echo "预编译mysql"cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/data/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DDOWNLOAD_BOOST=1 \-DWITH_BOOST=/root/boost_1_59_0 &>/dev/nullif [ $? -eq 0 ]thenecho "mysql预编译成功"echo "编译mysql"make -j $( grep processor /proc/cpuinfo | wc -l) &>/dev/nullif [ $? -eq 0 ]thenecho "mysql编译完成"echo "安装mysql"make install &>/dev/nullif [ $? -eq 0 ]thenecho "mysql安装完成"echo "修改mysql目录权限"chown -R mysql:mysql /usr/local/mysql/echo "备份配置文件文件"mv /etc/my.cnf{,.bak}echo "自行创建my.cnf配置文件"echo "
[mysqld]
basedir=/usr/local/mysql #mysql安装目录
datadir=/data/mysql/data #mysql数据存放目录
port=3306 #mysql监听端口
socket=/usr/local/mysql/mysql.sock #mysql.sock文件存放目录
symbolic-links=0 #关闭mysql的符号链接
character-set-server=utf8 #指定mysql的字符集为utf8
log-error=/data/mysql/log/mysqld.log #指定mysql的错误日志存放路径
pid-file=/usr/local/mysql/mysqld.pid #mysql的pid文件存放目录" >/etc/my.cnfecho "生成服务启动脚本"cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqld #给脚本添加执行权限echo "添加mysqld开机自启动"chkconfig --add mysqld #把mysql添加到系统服务chkconfig mysqld on #把mysql添加到开机自启动echo "初始化数据库"/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/dataecho "启动数据库"/etc/init.d/mysqld startecho "添加path路径"ln -s /usr/local/mysql/bin/* /usr/local/bin/read -s -p "请修改mysql密码:" passwdmysqladmin -u root password "$passwd"elseecho "mysql安装失败"fielseecho "mysql编译失败"fielseecho "mysql预编译失败"fielseecho "mysql依赖包下载失败"fielseecho "解压缩工具安装失败"fi
elseecho "mysql安装包下载失败"
fi
注意修改自己要下载的服务版本噢!
[root@node2 ~]#vim LNMP.sh
[root@node2 ~]#bash LNMP.sh
安装nginx服务
nginx-1.11.4安装包下载完成
--开始安装必要的依赖文件--
依赖文件安装完成
解压nginx安装包到/usr/local目录下
创建nginx运行用户www
预编译nginx
预编译完成
编译安装
编译安装完成
启动nginx服务
nginx启动成功
PHP安装包下载完成
开始安装PHP依赖文件
依赖文件下载成功
安装libmcrypt
安装libmcrypt成功
预编译PHP
PHP预编译成功
编译安装PHP
编译安装PHP成功
生成php.ini配置文件
修改fpm配置文件
php服务启动成功
查看PHP是否安装mysql模块
PHP连接mysql模块已经安装
mysql安装包下载完毕
卸载boost
bzip2解压缩工具下载完成
卸载系统自带的mysql
安装mysql依赖包
mysql依赖包下载完成
创建mysql用户和用户组
创建mysql数据库存放位置并修改目录权限
解压源码包
预编译mysql
mysql预编译成功
编译mysql
mysql编译完成
安装mysql
mysql安装完成
修改mysql目录权限
备份配置文件文件
mv: cannot stat ‘/etc/my.cnf’: No such file or directory
自行创建my.cnf配置文件
生成服务启动脚本
添加mysqld开机自启动
初始化数据库
启动数据库
Starting MySQL. SUCCESS!
添加path路径
请修改mysql密码:mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.