linux脚本部署动力社区CentOS7
作者:互联网
脚本练习实践
请提前设置好Yum源和ping通网络
脚本代码展示
[root@ybt ~]# cat discuz.sh
#!/bin/bash
#脚本实践一键部署"动力站点"
#进度条函数
ybt1=0
ke1='###'
ybt2(){
printf "\t\t进度:[%-s]%d%%\r" "$ke1" "$ybt1"
ybt1=$[ $ybt1 +20 ]
ke1="###$ke1"
}
echo
echo
ybt2
#判断是否为root用户
ybt=`whoami`
ke="/dev/null"
if [ "$ybt" == root ];then
echo -n
else
echo "不是root用户,请切换root用户执行脚本,脚本已退出"
fi
#检测是否有需要的命令未安装,没有则安装
if which wget unzip &> "$ke" ;then
echo -n
else
yum -y install wget unzip > "$ke"
fi
if which wget unzip &> "$ke" ;then
echo -n
else
echo "脚本终止,无法安装wget和unzip,请检查是否有可用的yum源"
exit
fi
ybt2
#检测是否能ping通动力网站地址,通则下载
>ybt.txt
if ls Discuz_X2.5_SC_UTF8.zip &> "$ke" ;then
echo -n
elif ping -c 3 -i 1 download.comsenz.com &> "$ke" ;then
wget http://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip &> "$ke"
elif ls Discuz_X2.5_SC_UTF8.zip &> "$ke" ;then
echo -n
else
echo "动力站点安装包下载失败,请手动下载“Discuz_X2.5_SC_UTF8.zip”"
fi
ybt2
#安装php php-mysql mariadb mariadb-server gd php-gd httpd
for i in php php-mysql mariadb mariadb-server gd php-gd httpd;do
yum -y install $i > "$ke"
echo $? >> ybt.txt ;done
if grep -v 0 ybt.txt ;then
echo "php php-mysql mariadb mariadb-server gd php-gd httpd安装失败,请手动安装,程序即将退出,安装后,可重新执行"
exit
else
echo -n
fi
ybt2
#调试和安装
mkdir /discuz &> "$ke" #随意创建目录
unzip -n Discuz_X2.5_SC_UTF8.zip > "$ke" #解压 yum -y install unzip
\cp -rf upload/* /discuz/ #复制/upload目录所有文件 -f覆盖已经存在的目标文件而不给出提示
chown -R apache.apache /discuz/ #给/discuz/目录apache权限
#apache配置和设置端口,设置动力网站配置文件
if grep "Listen 8080" /etc/httpd/conf/httpd.conf &> "$ke" ;then
echo -n
else echo "Listen 8080" >> /etc/httpd/conf/httpd.conf
fi
cat >/etc/httpd/conf.d/discuz.conf <<EOP
<VirtualHost *:8080> #设置主机为全部端口为8080
ServerName www.ybt.com
DocumentRoot /discuz
</VirtualHost>
<Directory "/discuz">
Require all granted
</Directory>
EOP
ybt2
#启动mysql和http
if systemctl status mariadb &> "$ke";then
echo -n
else systemctl start mariadb &> "$ke"
fi
if systemctl status mariadb &> "$ke" ;then
echo -n
else
echo "请手动启动mariadb,脚本已退出,手动启动后重新执行即可"
exit
fi
if systemctl status httpd &> "$ke" ;then
echo -n
else systemctl start httpd &> "$ke"
fi
if systemctl status httpd &> "$ke" ;then
echo -n
else
echo "请手动启动httpd,脚本已退出,手动启动后重新执行即可"
exit
fi
ybt2
echo
#设置在mysql创建discuz库
ybt=`which mysql`
$ybt -e 'create database if not exists discuz'
$ybt -e 'show databases' >> ybt.txt
if grep "discuz" ybt.txt &> "$ke" ;then
echo
echo -e "\t\t\033[47;31m脚本执行成功,请使用ip加8080端口访问,或设置hosts域名访问,进行动力社区设置\033[0m"
else
echo "请手动创建discuz库后,重新执行脚本"
fi
执行结果展示
[root@ybt ~]# ./discuz.sh
进度:[##################]100%
脚本执行成功,请使用ip加8080端口访问,或设置hosts域名访问,进行动力社区设置
标签:httpd,社区,ke,discuz,ybt,echo,CentOS7,linux,else 来源: https://www.cnblogs.com/ybt-kexiao/p/16194200.html