vps基本配置,及v2ray、hexo-blog和frp等安装配置
前言
之前买的vps因为商家重构了vps虚拟化的控制平台,数据也全部清除了(还好我之前对关键配置文件做了备份),现在不得不重新配置一次vps。之前配置vps都是直接google上搜索的,但很多资料不全和过期,今天趁这个机会刚好记录下自己配置vps的一些步骤,给以后的自己做一下参考,也希望可以帮助到有需要的人。
VPS配置查看
拿到一台vps首先需要查看下机器的基本配置,比如硬盘io(建站需要关注io)、带宽、线路(针对于国外的vps,主要类型有gt、cn2和cn2gia)。查看之前我先把系统重装成了ubuntu 20,当然你也可以选择其他的。在测试完后一般会重装系统,因为测试需要安装不少软件,但这些软件在测试完后就没用了,所以之后会重装。
测试vps综合性能
1 | wget -N --no-check-certificate https://raw.githubusercontent.com/V2RaySSR/vps/master/vpstest.sh && bash vpstest.sh |
运行后输入2即可查看综合性能。(其他的测试代码参见我的另一篇文章https://www.lingan1996.top/51967.html
这是脚本返回的结果,从中可以看出vps的CPU、硬盘大小、硬盘IO和服务器带宽。
我这台vps是1G内存,120+MB/s的IO,100M带宽,虚拟化方式为kvm。
测试三网回程路由
还是使用上面那个脚本,运行后输入3即可。
我这台电信是cn2gia2,移动联通直连。是什么线路看中间的路由节点就知道了,不懂的具体google下吧
基础配置
vps的基础信息已经测试完了,下面开始重装系统开始配置。这里我选择的还是ubuntu 20。
- 命令行修改密码
重装完后首先在命令行修改密码,为什么这么做的原因是让秘密和面板上的密码不一样。命令如下
1 |
|
1.1.1.1 8.8.8.8 1
2
3
4
5
3. ***更新系统***
```bash
apt update && apt upgrade
如果出现如下报错:
1
2E: Failed to fetch https://mirrors.aliyun.com/ubuntu/pool/main/n/netplan.io/netplan.io_0.100-0ubuntu4~20.04.3_amd64.deb Undetermined Error [IP: 47.246.16.227 443]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
那就再执行下面命令:
1
2
3apt update --fix-missing && apt upgrade
# 更新完后重启下
reboot
安装bbr加速
按需选择,我选择的是第一个
1
2
3
4不卸载内核版本
wget -N "https://github.000060000.xyz/tcpx.sh" && chmod + tcpx.sh && ./tcpx.sh
卸载内核版本
wget -N "https://github.000060000.xyz/tcp.sh" && chmod + tcp.sh && ./tcp.sh然后我只选了'''BBR+CAKE加速''',这个按需选择最适合你的配置
防火墙UFW(可选
查看是否安装了ufw
1
2
3
4ufw status verbose
# 如果按照了,会有输出 Status: inactive (在没激活的时候)
# 如果没安装ufw,执行下面命令
apt install ufw开启ufw
1
ufw enable
开放常用端口和你需要的端口
1
2
3
4ufw allow 22 # ssh的端口
ufw allow 80
ufw allow 443
ufw allow xxx # xxx为你需要的端口安装fail2ban,防止暴力破解(可选
1
2
3
4
5# 安装
apt install fail2ban
# 开启服务
systemctl start fail2ban
systemctl enable fail2ban配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24vi /etc/fail2ban/jail.local
# 修改配置信息,在其中写入如下内容
[DEFAULT]
# fail2ban忽略的IP
#ignoreip = 192.168.145.23 113.168.58.39
# 客户端被禁止时长(秒)
bantime = 86400 # one day
# 客户端主机被禁止允许失败的次数
maxretry = 10
# 查找失败次数的时长(秒)
findtime = 600
#日志修改检测机制(gamin、polling和auto这三种)
backend = polling
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
# sendmail-whois[name=SSH, [email protected], [email protected]]重启服务
1
systemctl restart fail2ban
v2ray安装配置
我选择的v2ray配置是v2ray+nginx+tls的方法,安装的软件是multi-v2ray。虽然v2ray+nginx+tls的方法会慢一些,但是安全点,另外需要低延时的时候使用ss
安装nginx,multi-v2ray
1
2
3
4# nginx
apt install nginx
# v2ray
source <(curl -sL https://multi.netlify.app/v2ray.sh) --zh配置方法就不介绍了,我是直接复原之前的配置文件。这部分建议查看其他人的文章!
安装acme.sh,用来生成网站的证书,这里采用dns的方式
安装acme.sh
1
2
3curl https://get.acme.sh | sh
# 安装后运行下面命令
source ~/.bashrc认证dns
1
2
3
4# dns认证,然后在域名管理上添加相应的解析记录
acme.sh --issue -d *.lingan1996.top -d lingan1996.top --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
# 重新认证
acme.sh --renew -d *.lingan1996.top -d lingan1996.top --yes-I-know-dns-manual-mode-enough-go-ahead-please使用dns api的模式进行证书申请。获取AccessKey ID和AccessKey Secret。
这样设置以后就不用在证书到期后重新续签证书了,acme.sh会自动帮你续签
我使用的是ali dns,添加访问控制的网址为https://usercenter.console.aliyun.com/#/manage/ak
其他dns服务商的设置自行百度,或者查看https://github.com/Neilpang/acme.sh/blob/master/dnsapi/README.md?spm=a2c6h.12873639.0.0.74fb1af3xI0gCh&file=README.md
1
2
3
4export Ali_Key="key"
export Ali_Secret="key Secret"
# 执行一次即可,下次就不用再次执行这个命令了
acme.sh --issue --dns dns_ali -d *.lingan1996.top -d lingan1996.top给nginx安装证书,如果/etc/nginx/ssl路径不存在,就
mkdir /etc/nginx/ssl
1
2
3
4acme.sh --installcert -d *.lingan1996.top \
--key-file /etc/nginx/ssl/lingan1996.key \
--fullchain-file /etc/nginx/ssl/fullchain.cer \
--reloadcmd "service nginx force-reload"
配置nginx的配置文件,样例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate /etc/nginx/ssl/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/lingan1996.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
自建测速网站
speedtest脚本,自建测速网址
1 | bash <(curl -Lsk https://raw.githubusercontent.com/lingan1996/speedtest-go-script/master/install.sh) |
端口限速(可选
有时vps提供商会限制不能长时间占满带宽,所以需要对用来下载的v2ray或者ss端口进行限速。
下面的脚本将网卡ens17中的2002、2102、2101端口限速到50Mb/s。
1 | # 下面的ens17是网卡名,按需修改。 |
但上面的命令在重启之后会失效,所以要一直有效的话,需要把这些加入到rc.local中
hexo-blog站点配置
将hexo站点布置在vps上,参考文章https://brucehan.top/2020/01/21/hello-world/,https://www.azjhong.com/2020-02/%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2%E5%88%B0VPS/
创建git用户
1 | adduser git |
在其中找到以下内容:
1 | ## Allow root to run any commands anywhere |
在后面添加一行,然后保存:
1 | git ALL=(ALL) ALL |
创建git目录下的blog仓库
1 | # 先切换到git用户,再执行下面的操作 |
然后配置git hooks,新建 post-receive
1 | cd /home/git/blog/blog.git/hooks |
在其中加入:
1 |
|
添加脚本执行权限:
1 | chmod +x post-receive |
添加git在网站目录的权限
1 | chown git:git -R /var/www/blog |
添加git用户的免密登录
在本机上执行下面的命令即可
1 | ssh-copy-id [email protected] |
同步本地hexo博客到vpsuh
本机上操作。
打开 hexo 文件夹,修改站点配置文件 _config.yml,修改如下内容:
1 | deploy: |
然后在shell中正常更新博客就行了:
1 | hexo clean && hexo g && hexo d |
参考文章
1: https://www.lingan1996.top/51967.html
2: https://blog.csdn.net/weixin_43507959/article/details/102763985
3: https://blog.csdn.net/nice_really/article/details/91414435
4: https://github.com/Jrohy/multi-v2ray
5: https://usercenter.console.aliyun.com/#/manage/ak
7: https://developer.aliyun.com/article/674835
8: https://brucehan.top/2020/01/21/hello-world/
9: https://www.azjhong.com/2020-02/%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2%E5%88%B0VPS/