LAMP自动安装脚本
程序员文章站
2022-03-28 19:22:51
1 #!/bin/bash 2 # 功能描述:LAMP自动安装脚本 3 4 # 初始化 5 if [ "$(cat /etc/system-release | awk '{print $(NF-1)}' | awk -F"." '{print $1}')" -ne 7 ] 6 then 7 echo... ......
1 #!/bin/bash 2 # 功能描述:lamp自动安装脚本 3 4 # 初始化 5 if [ "$(cat /etc/system-release | awk '{print $(nf-1)}' | awk -f"." '{print $1}')" -ne 7 ] 6 then 7 echo "当前程序只支持centos 7系统!" 8 exit 1 9 fi 10 if [ "$(whoami)" != root ] 11 then 12 echo "当前用户为:$(whoami),请使用管理员身份运行" 13 exit 2 14 fi 15 ping -c1 mirrors.aliyun.com 16 if [ "$?" -ne 0 ] 17 then 18 echo "当前网络不通" 19 exit 2 20 fi 21 iptables -f 22 yum -y install wget net-tools 23 dbpasswd=`date | md5sum | cut -b 1-6` 24 25 # 更改yum源 26 mv /etc/yum.repos.d/*.repo /tmp/ 27 wget -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo 28 sed -i '/aliyuncs/d' /etc/yum.repos.d/centos-base.repo 29 yum clean all && yum makecache 30 31 # 安装主程序 32 yum -y install httpd mariadb mariadb-server php php-mysql 33 34 # 安装所需插件 35 yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap libjpeg* gd 36 37 # 更改默认网站目录 38 mkdir /usr/local/wwwweb 39 chown apache. /usr/local/wwwweb 40 sed -i 's/\/var\/www\/html/\/usr\/local\/wwwweb/g' /etc/httpd/conf/httpd.conf 41 42 # 添加测试页面 43 cat > /usr/local/wwwweb/phpinfo.php <<eof 44 <?php 45 phpinfo(); 46 ?> 47 eof 48 49 # 启动程序并设置开机自启 50 systemctl start httpd.service 51 systemctl start mariadb.service 52 systemctl enable httpd.service 53 systemctl enable mariadb.service 54 55 # 更改mysql密码 56 mysqladmin -uroot password $dbpasswd 57 58 # 完成 59 echo "已完成安装lamp安装,数据库密码为$dbpasswd"