[root@localhost ~]# vim liang.sh
#!/bin/bash# LAMP终极部署cat <<-EOF+-------------------------------------------------------------------------+| LAMP终极部署 V1.0 |+-------------------------------------------------------------------------+| a. 部署Apache服务 || b. 部署php服务 || c. 部署Mysql服务 || d. 一键部署LAMP || q. 按q键退出程序 |+-------------------------------------------------------------------------+EOF# 安装Apacheinstall_Apache(){systemctl stop firewalldsystemctl disable firewalldsetenforce 0"liang.sh" 475L, 6051C
#!/bin/bash# LAMP终极部署cat <<-EOF+-------------------------------------------------------------------------+| LAMP终极部署 V1.0 |+-------------------------------------------------------------------------+| a. 部署Apache服务 || b. 部署php服务 || d. 一键部署LAMP || q. 按q键退出程序 |+-------------------------------------------------------------------------+EOF# 安装Apacheinstall_Apache(){systemctl stop firewalldsystemctl disable firewalldsetenforce 0sed -i '/^\bSELINUX\b/c SELINUX=disabled' /etc/selinux/configmkdir /usr/local/apr &> /dev/nullmkdir /usr/local/apr-util &> /dev/nullmkdir /usr/local/apache &> /dev/nullcd /usr/local/srcecho "正在下载Apache服务,请稍等!!!"wget http://archive.apache.org/dist/apr/apr-1.6.5.tar.gz &> /dev/nullwget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz &> /dev/nullif [ $? -eq 0 ]thenecho "download success"elseecho "download failed"exitfitar xf apr-1.6.5.tar.gztar xf apr-util-1.6.1.tar.gztar xf httpd-2.4.37.tar.gzecho "正在安装所需的依赖包"yum -y install gcc gcc-c++ openssl openssl-devel expat-devel &> /dev/nullthenecho "依赖包安装成功"elseecho "依赖包安装失败"exitficd /usr/local/src/apr-1.6.5/echo "正在配置和编译安装apr,请喝口水稍等!!!"./configure --prefix=/usr/local/apr/ &> /dev/nullmake &> /dev/null && make install &>/dev/nullif [ $? -eq 0 ]elseecho "apr installed failed"exitficd /usr/local/src/apr-util-1.6.1/make &> /dev/null && make install &> /dev/nullif [ $? -eq 0 ]thenecho "apr-util installed"elseecho "apr-util installed failed"exitficd /usr/local/src/httpd-2.4.37/echo "正在配置Apache"make &> /dev/null && make install &> /dev/nullif [ $? -eq 0 ]thenecho "Apache installed"echo "Apache installed failed"exitficd /usr/local/apache/bin/echo ServerName www.fangxi.com >> /usr/local/apache/conf/httpd.conf./apachectl startif [ $? -eq 0 ]thenecho "Apache安装成功并启动"elseecho "Apache启动失败"exitfi}#安装phpinstall_php(){echo "正在安装php服务"php-mbstring php-xml php-dom &> /dev/nullif [ $? -eq 0 ]thenelseecho "php安装失败"exitfisystemctl start php-fpm &> /dev/nullif [ $? -eq 0 ]thenecho "php安装成功"elseecho "php安装失败"fi}#编译安装Mysqlinstall_mysql(){echo "开始安装mysql"echo "正在准备编译环境,wait a minute"&> /dev/nullif [ $? -eq 0 ]thenecho "编译环境已准备好"elseecho "编译环境准备失败"exitfiecho "正在下载源码包----请稍稍等一下"groupadd mysqluseradd -r -g mysql -s /bin/nologin mysqltar xf mysql-boost-5.7.26.tar.gzcd mysql-5.7.26/echo "正在配置中,请再喝口水,小憩一下"cmake . \-DWITH_BOOST=boost/boost_1_59_0/ \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DSYSCONFDIR=/etc \-DMYSQL_DATADIR=/usr/local/mysql/data \-DINSTALL_MANDIR=/usr/share/man \-DMYSQL_TCP_PORT=3306 \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DEXTRA_CHARSETS=all \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_READLINE=1 \-DWITH_SSL=system \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 &> /dev/nullif [ $? -eq 0 ]thenecho "mysql配置成功"elseecho "mysql配置失败"fiecho "----------正在安装编译安装Mysql请稍等-----------"make &> /dev/null && make install /dev/nullif [ $? -eq 0 ]thenecho "mysql编译安装成功"elseecho "mysql编译安装失败"exitfiecho [mysqld] > /etc/my.cnfecho basedir=/usr/local/mysql >> /etc/my.cnfecho datadir=/usr/local/mysql/data >> /etc/my.cnfecho "mysql配置文件successed"cd /usr/local/mysql/mkdir mysql-fileschown -R mysql.mysql /usr/local/mysqlecho "-------------正在初始化Mysql请稍等--------------"--datadir=/usr/local/mysql/data &> mima.txtmima=awk '/password/ {print $NF}' mima.txtecho "初始密码为:$mima"if [ $? -eq 0 ]thenecho "mysql初始化成功"elseecho "mysql初始化失败"exitfibin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data#给数据库加密cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld on#添加到开机启动项systemctl start mysqldif [ $? -eq 0 ]thenecho "mysql启动成功"elseecho "mysql启动失败"exitfiecho "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profilesource /etc/profileecho "----------修改数据库初始密码----------"read -p "请输入你要设置的数据库密码" new_mimamysqladmin -uroot -p${mima} password "$new_mima"if [ $? -eq 0 ]thenecho "mysql初始密码修改成功,mysql部署完成"elseecho "mysql初始密码修改失败"exitfi}while :doread -p "请输入你要选择的参数: " varcase $var ina)install_Apache;;
mima=awk '/password/ {print $NF}' mima.txtecho "初始密码为:$mima"if [ $? -eq 0 ]thenecho "mysql初始化成功"elseecho "mysql初始化失败"exitfibin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data#给数据库加密cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld on#添加到开机启动项systemctl start mysqldif [ $? -eq 0 ]thenecho "mysql启动成功"elseecho "mysql启动失败"exitfiecho "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profilesource /etc/profileecho "----------修改数据库初始密码----------"read -p "请输入你要设置的数据库密码" new_mimamysqladmin -uroot -p${mima} password "$new_mima"if [ $? -eq 0 ]thenecho "mysql初始密码修改成功,mysql部署完成"elseecho "mysql初始密码修改失败"exitfi}while :doread -p "请输入你要选择的参数: " varcase $var ina)install_Apache;;b)install_php;;c)install_mysql;;d)install_Apacheinstall_phpinstall_mysql;;q)exit;;*)printf "请按照上方提供的选项输入!!!\n";;esacdone[root@localhost ~]# chmod +x liang.sh
[root@localhost ~]# bash liang.sh +-------------------------------------------------------------------------+| LAMP终极部署 V1.0 |+-------------------------------------------------------------------------+| a. 部署Apache服务 || b. 部署php服务 || c. 部署Mysql服务 || d. 一键部署LAMP || q. 按q键退出程序 |+-------------------------------------------------------------------------+请输入你要选择的参数: