千家信息网

shell脚本安装LAMP架构(一键执行)

发表于:2024-11-14 作者:千家信息网编辑
千家信息网最后更新 2024年11月14日,一键安装代码(可ctr+c哦)1、挂载的主机IP、密码自行更改#!/bin/bash#一键自动构建LAMP架构(请使用source执行或者使用.命令执行)#数据库默认密码为123123#远程挂载df
千家信息网最后更新 2024年11月14日shell脚本安装LAMP架构(一键执行)

一键安装代码(可ctr+c哦)

1、挂载的主机IP、密码自行更改

#!/bin/bash#一键自动构建LAMP架构(请使用source执行或者使用.命令执行)#数据库默认密码为123123#远程挂载df -hT | grep -o "cifs"if [ $? -ne 0 ];thenecho "Start mount"yum install expect -yread -p "请输入提供硬盘主机IP:" gongip/usr/bin/expect <<-EOFspawn mount.cifs  //$gongip/LAMP-C7   /mnt/           ##主机IP名根据自己情况来改expect {    "Password*"    {send "\r"}}expect eofEOFfi#安装apache服务cd /mnt/tar zxf apr-1.6.2.tar.gz -C /opttar zxf apr-util-1.6.0.tar.gz -C /opt/tar jxf httpd-2.4.29.tar.bz2 -C /opt/cd /opt/mv apr-1.6.2/ httpd-2.4.29/srclib/aprmv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-utilyum -y install gcc \gcc-c++ \make \pcre-devel \expat-devel \perlcd /opt/httpd-2.4.29/./configure --prefix=/usr/local/httpd \--enable-so \--enable-rewrite \--enable-charset-lite \--enable-cgimake && make installcp /usr/local/httpd/bin/apachectl /etc/init.d/httpdsed -i -e '2a# chkconfig: 35 85 21\n# description: Apache is a World Wide Web server' /etc/init.d/httpdchkconfig --add httpdsed -i -e '197d' -e '196aServerName www.kgc.com:80' /usr/local/httpd/conf/httpd.confip=`ifconfig ens33 | awk 'NR==2{print $2}'`sed -i -e '52s/^/#/' -e '51d' -e "50aListen $ip:80" /usr/local/httpd/conf/httpd.confln -s /usr/local/httpd/conf/httpd.conf /etc/ln -s /usr/local/httpd/bin/* /usr/local/bin/systemctl stop firewalld.servicesetenforce 0service httpd startnetstat -ntuap | grep httpdif [ $? -eq 0 ];then     echo Apache服务启动else     echo 启动失败    exit 1fi#安装mysql服务echo "================================="echo "安装mysql数据库,请稍后。。。"sleep 3yum install -y ncurses-devel autoconf cmakecd /mnt/tar zxf mysql-5.6.26.tar.gz -C /opt/cd /opt/mysql-5.6.26cmake  \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DSYSCONFIDIR=/etc \-DMYSQL_DATADIR=/home/mysql/ \-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sockecho "进行编译安装,要很久,请稍后。。。"make && make installcp support-files/my-default.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldchkconfig --add /etc/init.d/mysqldchkconfig --level 235 mysqld onecho "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profilesource /etc/profileecho $PATH | grep -o "mysql"if [ $? -eq 0 ];then     echo "添加成功"else     echo "失败"    exit 1fiuseradd -s /sbin/nologin mysqlchown -R mysql:mysql /usr/local/mysql//usr/local/mysql/scripts/mysql_install_db \--user=mysql \--ldata=/var/lib/mysql \--basedir=/usr/local/mysql \--datadir=/home/mysqlsed -i -e '47d' -e '46d' -e '45abasedir=/usr/local/mysql\ndatadir=/home/mysql' /etc/init.d/mysqldservice mysqld startnetstat -ntuap | grep mysqldif [ $? -eq 0 ];then        echo Mysql数据库启动else        echo 启动失败    exit 1 fi#read -p "请输入数据库密码(自定义):" mima/usr/bin/expect < /usr/local/httpd/htdocs/index.php <<-EOFEOFservice httpd stopservice httpd startrm -rf /opt/*umount /mnt
0