[功能] HTML 下载链接

<html>
<body>
<a href="eternalcenter-2021.txt" download="eternalcenter.txt">Download test.txt</a>
</body>
</html>

(补充:这里以下载和此 html 文件在同目录下的 eternalcenter-2021.txt 文件,且下载命名为 eternalcenter.txt 为例)

[工具] Shell 将远程服务器的 LNMP 备份在本地复原

介绍

基本信息

作者:朱明宇
名称:将远程服务器的 LNMP 备份还原到本地
作用:将远程服务器的 LNMP 备份还原到本地

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

1. tmppath=/cache #本地用于备份数据的目录
2. webpath=/usr/share/nginx/html #本地用于存放网站文件的目录
3. key=”~/.ssh/eternalcenter” #本地私钥
4. tmpfile=tmpfile.txt #用于存储记录的文件
5. dbuser=ec #网站在数据库中的用户
6. ruser=eternalcenter #用于远程服务器的用户
7. rhost=eternalcenter.com #远程服务器
8. rcache=”/cache” #远程服务器用于备份数据的目录

注意

1. 本地需要已经搭建好 LNMP 平台
2. 用于远程服务器的用户,需要能免密钥 ssh 远程服务器,且对于本地用于备份数据的目录和远程服务器用于备份数据的目录拥有读和执行的权限
3. 执行此脚本的用户需要有 sudo systemctl 权限
4. 脚本 ”mysql -uroot -p’eternalcenter’ ec < $sqlfile“ 中 “eternalcenter“ 是指本地 MariaDB 数据库 root 用户的密码,需要修改成本地 MariaDB 数据库的 root 用户密码

脚本

#!/bin/bash

####################### Separator ########################

tmppath=/cache
webpath=/usr/share/nginx/html
key="~/.ssh/eternalcenter"
tmpfile=tmpfile.txt
dbuser=ec

ruser=eternalcenter
rhost=eternalcenter.com
rcache="/cache"

####################### Separator ########################

nowdirectory=`pwd`

a=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`
sleep 10
b=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`

if [ $a -eq 0 ];then
	echo "no file"
fi

if [ $a -ne $b ];then
        echo "backup is running now"
        exit
fi

c=0

if [ -f $tmpfile ];then
        c=`cat $tmpfile`
fi

if [ $a -eq $c ];then
        echo "no new file"
        exit
fi

echo $a > $tmpfile

sqlfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep sql | tail -1" | awk '{print $NF}'`
if [ $? -eq 0 ]; then

        tarfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep tar | tail -1" | awk '{print $NF}'`
        if [ $? -eq 0 ]; then

                rm -rf $tmppath/*
                mkdir $tmppatch &> /dev/null

                echo $sqlfile
                echo $tarfile

                scp -i $key $ruser@$rhost:$rcache/$sqlfile $tmppath
                scp -i $key $ruser@$rhost:$rcache/$tarfile $tmppath

#                sudo systemctl stop nginx
#                sudo systemctl stop php-fpm

                cd $tmppath

                mysql -uroot -p'eternalcenter' -e "drop database $dbuser;"
                mysql -uroot -p'eternalcenter' -e "create database $dbuser;"
                mysql -uroot -p'eternalcenter' -e "grant all privileges on $dbuser.* to \"$dbuser\"@\"localhost\";"
                mysql -uroot -p'eternalcenter' ec < $sqlfile

                sudo rm -rf $webpath/*
                sudo tar -zxvf $tarfile -C $webpath/ &> /dev/null

#                sudo systemctl start nginx
#                sudo systemctl start php-fpm

                cd $nowdirectory

        fi
fi

[工具] Shell LNMP 没运行则重启系统 (systemctl 版)

介绍

基本信息

作者:朱明宇
名称:LNMP 没运行则重启系统
作用:LNMP 没运行则重启系统

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本

#!/bin/bash
  
systemctl status nginx | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status mariadb | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status php-fpm | grep 'active (running)'
if [ $? -ne 0 ];then
        /usr/sbin/reboot
fi

[FUN] HTML Mingyu Zhu’s Personal Web Page

中文

Code

<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<head>

<title>Mingyu Zhu</title>

</head>

<body>

<div style="position:absolute; width:100%; height:100%; z-index:-1; left:0; top:0;"> 
<img src="https://filedn.eu/ltLpz9YGUS2hi1pJmklNfDb/en_us/dimfigure.JPG" height="100%" width="100%" style="position:absolute;left:0; top:0;"> 
</div>

<div style="width:300px;height:50px;float:left"> 
<form action="http://www.google.com/search" method="get"> 
<input type="text" name="q" size="20" maxlength="255" value="" /> 
<input type="submit" name="btnG" value="Google" /> 
</form>
<a href="https://zhu-mingyu.github.io" style="right: 15px; position: absolute; font-size:25px;color:red">中文 (GitHub)</a>
<a href="https://zhumingyu.com" style="right: 215px; position: absolute; font-size:25px;color:red">中文</a>
</div> 

<div style="left: 8px; position: absolute; top: 75px;font-size:45px;">Mingyu Zhu's Personal Web Page</div>

<div style="left: 800px; position: absolute; top: 300px;font-size:15px;">"Hope everyone can achieve self achievement and self happiness fairly."</div>

<a href="http://eternalcenter.com" target="_blank" style="left: 8px; position: absolute; top: 185px;font-size:20px;color:black">Eternal Center (eternalcenter.com), Mingyu Zhu's personal website</a>
<a href="https://e.pcloud.link/publink/show?code=kZukhJZUhQq66Fxs0yg5rL1LsAgrSD3ytMk" target="_blank" style="left: 8px; position: absolute; top: 215px;font-size:20px;color:black">Mingyu Zhu's personal website data for cloning</a>
<a href="https://github.com/eternalcenter-now/eternalcenter-now" target="_blank" style="left: 8px; position: absolute; top: 245px;font-size:20px;color:black">Mingyu Zhu's personal website code for cloning</a>
<a href="http://static.eternalcenter.com" target="_blank" style="left: 8px; position: absolute; top: 275px;font-size:20px;color:black">Effect display page of Mingyu Zhu's personal website</a>
<a href="https://eternalcenter-now.github.io" target="_blank" style="left: 8px; position: absolute; top: 305px;font-size:20px;color:black">Effect display page of Mingyu Zhu's personal website (GitHub)</a>
<a href="https://e.pcloud.link/publink/show?code=kZrJhJZbVIBf8jmVFzumvaYnEwPlLLc34DX" target="_blank" style="left: 8px; position: absolute; top: 335px;font-size:20px;color:black">Public personal data of Mingyu Zhu</a>

</body>

<html/>

Background Picture

[命令] Linux 命令 set (设置 Shell 里的位置变量或者 Shell 的执行方式)

内容一:set 命令的格式

1.1 设置 Shell 的位置变量的格式

# set <Value of the first position variable> <Value of the second location variable> ......

1.2 设置 Shell 的执行方式

# set <parameter>

或者:

# set <parameter> +o

或者:

# set <parameter> -o

(补充:+o 代表打开特殊属性,-o 代表结束特殊属性)

内容二: set 的常用参数

1) -a 将已修改的变量进行标记,为将其输出至环境变量做准备
2) -b 让被中止的后台进程立刻显示退出状态代码
3) -d 取消使用杂凑表记忆中使用过的指令
4) -e 若退出状态代码不为 0 (正常退出)则立即退出,并显示错误原因
5) -f 取消通配符
6) -h 默认自动记录函数位置
7) -k 让命令的参数为此命令的环境变量
8) -l 默认自动记录 for 循环变量名
9) -m 监视模式
10) -n 测试模式(只读取不执行)
11) -p 优先顺序模式
12) -P 让文件或目录代替符号链接
13) -t 让随后的命令执行后立即退出
14) -u 使用未定义的变量时显示错误信息
15) -v 显示输入值
16) -H shell 使用感叹号 “!” + 号码的方式调用 history 命令中的历史命令
17) -x 命令指向前先显示此命令的参数或变量

(补充:将以上参数前面的 – 换成 + 则会变成相反的效果)