- 数据库备份
• 执行db_dump.sh *****(数据库密码) • 脚本执行后会备份数据库中的所有库到/mnt/mysqldump目录中
备份文件名称为 “库名称.sql”当此文件存在时报错并询问动作
- 输入“S”跳过备份,
- 当输入“B"时备份“库名称.sql”文件为“库名称_backup.sql”
- 当输入“O”时,覆盖源文件
#!/bin/bash
password=$1##定义全局变量password
dump_dir=/mnt/mysqldump ##设置一个变量为这个目录
##自定义函数
DB_CHOICE(){
db=$1
password=$2
echo "$db.sql already exist,please :[S]skip [B]backup [O]Overwrite"
read -p "Please input you choice:" choice
case $choice in
s|S)
;;
b|B)
mv /mnt/mysqldump/$db/sql /mnt/mysqldump/$db_backup.sql
mysqldump -uroot -p$password $db > /mnt/mysqldump/$db.sql
echo "successfully!!"
;;
o|O)
mysqldump -uroot -p$password $db > /mnt/mysqldump/$db.sql
echo "successfully!!"
;;
*)
echo "Please input correct opyion!"
;;
esac
}
echo "1.-----------检测文件是否存在------"
if [ -e $dump_dir ];then
if [ ! -d $dump_dir ];then
rm -fr $dump_dir
fi
else
mkdir $dump_dir
fi
echo '2.--------获取数据库名称并且备份---------'
dbs=`mysql -uroot -p$password -e "show databases;" | grep -E "Database|schema$" -v`
for db in $dbs
do
if [ -e /mnt/mysqldump/$db.sql ];then
echo "$db.sql already exist,please :[S]skip [B]backup [O]Overwrite"
DB_CHOICE $db $password
else
mysqldump -uroot -p$password $db > /mnt/mysqldump/$db.sql
fi
done
- 服务自动部署示例
• 执行脚本lamp.sh
• 脚本执行后部署好论坛,并设定apache的网络接口为8080
dnf install -y httpd mariadb-server php php-mysqlnd
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
##或者永久的关闭selinux vim /etc/selinux/config
设置为disabled
- wget https://cn.wordpress.org/wordpress-4.9-zh_CN.tar.gz
- ##下载一个开源的博客包
- tar xf wordpress-4.7.2-zh_CN.tar.gz -C /var/www/html/
- ##将压缩包解压到/var/www/html下
- 脚本:
#!/usr/bin/bash
echo "1.-----software install-------"
dnf install -y httpd mariadb-server php php-sqlnd
echo "2.------stop firewall---------------------"
systemctl stop firewalld
systemctl disable firewalld
echo "------3.stop selinux------------------------"
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/syscondif/selinux
echo "4.------start server---------------"
systemctl start httpd
systemctl enable httpd
systemctl start mariadb
systemctl enable mariadb
echo "5.----download -----------"
wget https://cn.wordpress.org/wordpress-4.9-zh_CN.tar.gz
tar xf wordpress-4.7.2-zh_CN.tar.gz -C /var/www/html/
echo "6.--------change port ------------"
sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf
systemctl restart httpd
echo "7.---test--------- "
curl http://127.0.0.1:8080 | grep "论坛" &> /dev/null
[ $? -eq 0 ] && echo "lamp构搭建成功" || "lamp搭建失败"