VPS重建记

VPS重新部署日常环境,及hexo博客快速重建

VPS受灾记

大早上来发现stackoverflow首页都打不开,对于天天科学上网的我来说,简直莫名其妙。

本地网络原因

本地windows PC机,控制台ping IP:

1
ping VPS_IP

直接就超时了,匪夷所思。。VPS服务器 ping自己:

1
ping 127.0.0.1

好歹能通,那就是中间路由断了。

手机下载个网络工具,尝试在手机端ping VPS的IP(排除公司DNS搞的鬼),手机上ping也直接超时了,好吧,可以去检查是不是在某个不知名的时候自己把防火墙开了,还把22等端口关了。。

VPS排查

我的VPS是在LA的CENTOS7主机,centos7查看防火墙状态:

1
firewall-cmd    --state

发现是关着的。。。为了排除自己之前装过iptables的服务,查看iptables.service

1
systemctl status iptables.service

这个果然是开着的,查看启用的端口:

1
cat /etc/sysconfig/iptables

该开的端口也都开了,好吧,无语了。

大环境排查

基于大家都懂的网络环境,怀疑是IP被墙了,检测:

1
http://ping.chinaz.com

果然,除了香港和国外,其他都ping不通VPS,好吧,可以下结论了:IP被墙了…

真的很想骂人啊!到底是哪个JR没事瞎玩,搞出个异常流量,害的无辜躺枪!!!
hexo还在VPS上,小飞机也在VPS上,没有梯子,科学上网个鬼啊!!!

骂人几轮,该弄得还是得弄,方案嘛,无非就是换IP,还好Vultr重建台服务还是很方便的。

VPS重建

Vultr重买服务器,这次比较幸运,居然有$2.5的,直接买:
Vultr官网
拿到IP之后,第一件事,肯定是ping IP,还好,可以ping通,就是你了!

VPS简单设置

防火墙设置

xshell远程连接上VPS之后,习惯性操作,第一步,更新yum

1
yum update
firewall设置

由于centos7默认的防火墙服务时firewalld的,很不习惯,改!

查看防火墙状态

1
firewall-cmd    --state

关闭防火墙

1
systemctl  stop   firewalld.service

禁止开机启动启动防火墙

1
systemctl   disable   firewalld.service
iptables设置

安装iptables服务:

1
yum install  iptables-services

开启iptables防火墙:

1
systemctl  start  iptables.service

开启特定端口:
编辑文件:/etc/sysconfig/iptables,加入想要开放的端口即可,例如开放8090端口:

1
-A INPUT -p tcp -m tcp --dport 8090 -j ACCEPT

保存,退出之后,重启防火墙完成设置:

1
systemctl  restart  iptables.service

ShadowsocksR(小飞机)配置

科学上网必不可少的工具,ShadowsocksR

安装:

1
2
3
wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR.sh
chmod +x shadowsocksR.sh
./shadowsocksR.sh 2>&1 | tee shadowsocksR.log

完成配置:

1
2
3
4
5
服务器端口:自己设定(如不设定,默认为 8989)
密码:自己设定(如不设定,默认为 teddysun.com)
加密方式:自己设定(如不设定,默认为 aes-256-cfb)
协议(Protocol):自己设定(如不设定,默认为 origin)
混淆(obfs):自己设定(如不设定,默认为 plain)

附上我的配置,仅供参考:

1
2
3
4
5
6
Your Server IP        :  ***.***.***.*** 
Your Server Port : *****
Your Password : *******
Your Protocol : auth_sha1_v4
Your obfs : tls1.2_ticket_auth
Your Encryption Method: aes-256-cfb

配置完成之后就可以在本地PC机使用客户端进行梯子配置,完了就可以科学上网啦!!!
客户端度娘盘链接

Hexo重建

预备动作:原来VPS上面的hexo所在目录,直接打成压缩包scp出来

安装node.js

首先安装gcc用于编译:

1
yum -y install gcc gcc-c++ kernel-devel

开始安装node.js

1
2
wget https://nodejs.org/dist/v4.5.0/node-v4.5.0.tar.gz
tar -xf node-v4.5.0.tar.gz

解压缩之后,进入目录,编译:

1
2
3
4
cd node-v4.5.0
./configure
make
make install

完成!
验证:

1
2
node -v
npm

安装完成的是4.5的版本,升级:

1
2
npm install -g n
n stable

安装git

由于买的VPS已经集成了git,所以怎么安装,怎么配置环境变量啥的就不废话了。
1、VPS设置git:

1
2
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

邮箱和用户名都对应于github

2、生成ssh秘钥

1
ssh-keygen -t rsa -C example@163.com

默认保存路径是/root/.ssh下:

1
cat /root/.ssh/id_rsa.pub

获取秘钥,然后到github的web页面将秘钥配置进去,完成!

安装hexo

1、安装hexo
创建目录

1
mkdir blog

安装

1
2
3
4
cd blog
npm install -g hexo-cli
#初始化
hexo init

2、安装插件

1
2
3
4
5
6
7
8
9
10
11
12
13
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-deployer-heroku --save
npm install hexo-deployer-rsync --save
npm install hexo-deployer-openshift --save
npm install hexo-renderer-marked --save
npm install hexo-renderer-stylus --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save

3、修改Hexo配置文件,完成!

或者,直接把原来VPS上面hexo的压缩包解压,再配置安装hexo即可

1
2
3
cd /home/blog
npm install hexo --save
npm install -g hexo-cli

环境测试

1
2
hexo new "安装测试"
hexo g -d

执行不报错,进入博客可以看见安装测试该文章,部署成功!

真的是坑啊,又重布环境,国内的网络环境啊,ε=(´ο`*)))唉~

参考链接

centos搭建hexo博客

文章目录
  1. VPS受灾记
    1. 本地网络原因
    2. VPS排查
    3. 大环境排查
  2. VPS重建
    1. 防火墙设置
      1. firewall设置
      2. iptables设置
    2. ShadowsocksR(小飞机)配置
  3. Hexo重建
    1. 安装node.js
    2. 安装git
    3. 安装hexo
    4. 环境测试
  4. 参考链接
|