今天日常备份博客,结果 100 多 m 的备份文件,小水管 50kb 下了二十多分钟,哭了。一气之下提交工单退了阿里云的 ECS,换到了轻量服务器。于是开始了漫长的搬家之路。

封面图:bilibili 拜年祭的明信片 /oO 大黄 Oo #pixiv


搬家

1.备份数据

  1. 备份网站
  2. 备份数据库
  3. 备份oh my zsh 配置

漫长的下载……

2.工单申请退款

工单提 “从学生 ECS 换到轻量,请帮忙退款”,耗时一个小时。

参考下退款成功的回复:

您好,退款操作会释放您的业务,业务内所有数据将会清空。 如您确认请继续如下操作 经特殊申请,您的服务: (已删除)
退订剩余使用时长申请已经进入流程,退款链接如下: (已删除)
请您尽快打开此链接确认提交退款,退款金额以您打开此链接时系统显示的金额为准,款项大约会在2个工作日内退回(若有代金券支付,代金券支付部分无法退回)。
注:
1、请您务必核对链接中的实例信息与您需要退款的实例是否相符。
2、关于退款费用:2017 年 8 月 12 日以后的订单,且订单支付成功后三个月内办理的退款,退款至原支付途径,订单支付三个月后的业务退款、历史订单退款以及退款至原支付途径失败的情况仍退回账户余额。如要提现请参考: https://help.aliyun.com/knowledge_detail/37095.html
3、请您不要对业务再进行升级或续费操作,退款成功后,会自动扣减您的可开发票额度,退款订单请勿申请发票,以免可开票额度为负数时影响您的提现申请。

3.购买学生轻量服务器

找不到可以在阿里云首页直接搜 “学生机”,9.9 一个月。只是放博客的话轻量服务器绝对够用。

4.重装系统

若是想要体验纯净的 Ubuntu 系统,可以重新安装系统。

参考:Debian/Ubuntu/CentOS 网络安装 / 重装系统 / 纯净安装 一键脚本

在待重装系统上安装所需文件:

#Debian/Ubuntu: apt-get install -y xz-utils openssl gawk file #RedHat/CentOS: yum install -y xz openssl gawk file

出错的话,运行

#Debian/Ubuntu: apt-get update #RedHat/CentOS: yum update

随后,安装新系统

bash <(wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh') -u 18.04 -v 64 -a

Ubuntu 的脚本不行了,换用 De­bian

bash <(wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh') -d 10 -v 64 -a

全自动安装默认用户名:root,密码:MoeClub.org, 安装完成后立即更改密码。

5.修改Linux密码

试试看是不是 root 登录

sudo su root

看来是 root,继续修改密码

passwd root

连续输入两次相同的密码,输入时不会显示

Enter new UNIX password: Retype new UNIX password:

下次连接服务器生效,所以要是一时忘记了密码,保持登陆的话就可以再次修改密码。

6.安装 oh my zsh

安装 zsh

apt install -y zsh

可能需要安装 git

apt-get install git

安装 Oh My Zsh

bash -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

国内服务器用这个方法安装:

git clone https://ghproxy.com/https://github.com/ohmyzsh/ohmyzsh.git .oh-my-zsh cd .oh-my-zsh/tools sh install.sh

下面配置参考:我的 zsh 终端配置

安装需要的插件
zsh-syn­tax-high­light­ing

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

国内机

git clone https://ghproxy.com/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

zsh-au­to­sug­ges­tions

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

国内机

git clone https://ghproxy.com/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

au­to­jump

apt install -y autojump

增加常用命令快捷方式

alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080" //设置系统代理 alias unsetproxy="unset ALL_PROXY" //关闭系统代理 alias ip="curl -i https://ip.cn" //查看当前ip alias pc="proxychains" //便于使用proxychains alias setwww="chmod 755 -R /home/wwwroot && chown www:www -R /home/wwwroot" //设置网站目录的所有者与权限

里头有个 setwww,可能会提示

chown: changing ownership of `/home/wwwroot/default/.user.ini’: Operation not permitted

执行:

chattr -i /home/wwwroot/domain.com/.user.ini

setwww

7.使用SSH key登录Ubuntu

ssh-keygen -t rsa

这里可以一路回车

Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.#这是私钥 Your public key has been saved in /root/.ssh/id_rsa.pub.#这是公钥 The key fingerprint is:

私钥下载到本地电脑妥善保存,为安全起见,删除服务器端的私钥。
将公钥导入到系统中:

cd .ssh cat id_rsa.pub >> authorized_keys

修改 SSH 的配置文件 /etc/​ssh/​sshd_­con­fig

56 # To disable tunneled clear text passwords, change to no here! 57 PasswordAuthentication #默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录 58 #PermitEmptyPasswords no

重启以生效

#ubuntu service ssh restart #debian /etc/init.d/ssh restart

8.修改端口

修改 /etc/​ssh/​sshd_­con­fig,在 Port 22 下添加你的端口

#Port 22 Port YOUR_PORT

重启 ssh

service ssh restart

ssh 成功连接新的端口后,把 22 端口注释掉

9.安装lnmp

直接安装 lnmp 1.7,参考:lnmp 1.7
安装 screen

apt-get install screen

安装完毕,执行

screen -S lnmp

如果网络掉线,可以重新连接 SSH,再执行 screen -r lnmp 就会看到你的 lnmp 安装进程。
接着开始安装 lnmp 1.7

wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh lnmp

配置略过,MySQL 选择默认,PHP 选择最新。数据库密码与原 ECS 相同方便恢复博客。
这里又是漫长的等待…
lnmp 安装完毕,开始恢复站点。

10.恢复站点

把备份好的网站上传到服务器

上传的时候实在纳闷,明明图片不在服务器里备份文件为什么这么大,才发现是 Exsearch 插件的静态缓存,有 110M…

11.恢复数据库

导入备份的 SQL 文件
恢复数据库时可能会出现

变量 $cfg['TempDir'] (./tmp/)无法访问

只要给 tmp 正确的权限就好了,重启 Ng­inx 使改动生效

lnmp nginx restart

12.申请泛域名证书

安装 acme.sh

curl https://get.acme.sh | sh

使用 dns 方式验明域名所有权,这里以 dns­pod 为例

export DP_Id="123456"\ export DP_Key="sADDsdasdgdsf"

签发泛域名证书

acme.sh --issue --dns dns_dp -d '*.example.com' -d example.com

签发的证书一般是默认生成在 root/.acme.sh/ 下,为安全起见,不要直接使用这里的证书,而是复制到 ng­inx 下的 ssl 目录,需要手动新建 ssl 目录和存放证书的目录

acme.sh --installcert -d '*.example.com' --key-file /usr/local/nginx/conf/ssl/example.com/example.com.key \ --fullchain-file /usr/local/nginx/conf/ssl/example.com/fullchain.cer \ --reloadcmd "lnmp nginx restart"

如要申请 ECC 证书,只要在末尾添加 --keylength ec-256

acme.sh --issue --dns dns_dp -d '*.example.com' -d example.com --keylength ec-256

复制证书只要加个 --ecc

acme.sh --installcert -d '*.example.com' --ecc \ --key-file /usr/local/nginx/conf/ssl/example.com/example.com_ecc.key \ --fullchain-file /usr/local/nginx/conf/ssl/example.com/fullchain_ecc.cer \ --reloadcmd "lnmp nginx restart"

证书在 60 天以后会自动更新,无需任何操作。今后有可能会缩短这个时间,不过都是自动的
可以用这个命令检查

acme.sh --renew-all

建议开启自动更新

acme.sh --upgrade --auto-upgrade

具体参考:https://github.com/Neilpang/acme.sh/wiki/ 说明

额外的东西

1.网站备份至又拍云

使用半吊子的静树的脚本:备份网站至又拍云

直接使用 git clone 整个库

git clone https://github.com/kzw200015/backup2upyun.git

安装 python 环境

apt install -y python3

进入脚本目录

cd /root/backup2upyun

安装依赖

apt install -y python3-pip pip3 install upyun progressbar

把配置文件复制一份

cp config.py.example config.py

按照 config.py 内的说明进行配置

赋予执行权限

chmod +x main.py

执行脚本

./main.py

cron 实现 执行 crontab -e,加入以下内容

LANG='en_US.UTF-8' LC_ALL='en_US.UTF-8' 0 2 * * * /root/backup2upyun/main.py

2.安装Aria2

先安装 Aria2 后端,用的是逗比的脚本

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/aria2.sh && chmod +x aria2.sh && bash aria2.sh

按照指示做,再下载管理面板,Ar­i­aNg 是一个前端 (HTML+JS 静态) 控制面板

https://github.com/mayswind/AriaNg

3.安装H5ai

下载 h5ai 安装包,这里使用大佬的修改版:https://github.com/Pearlulu/h5ai_dplayer_hls
安装 imagemagick 以开启 PDF 预览

apt install -y imagemagick

安装 ffmpeg

apt install -y ffmpeg

去除被禁用的 PHP 函数:

vim /usr/local/php/etc/php.ini

搜索 scandir、exec、passthru,将其从被禁用的函数中删除

不重装 PHP 安装 EXIF 扩展,具体参考:h5ai 一个简洁强大的网页列目录程序

记不住的命令

1. 压缩

tar cvfz xxx.tar.gz /xxx/

2. 解压

tar -zxvf xxx.tar.gz tar -jxvf ×××.tar.bz2

大功告成,写篇水文备份留着下次搬家用…