阿里云服务器学习笔记

1、卸载阿里云盾(安骑士)

wget http://update.aegis.aliyun.com/download/uninstall.sh && chmod +x uninstall.sh && bash uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh && chmod +x quartz_uninstall.sh && bash quartz_uninstall.sh

删除残留

pkill aliyun-service
rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*

屏蔽云盾IP

iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP

检查阿里云盾是否卸载干净

ps -aux | grep -E 'aliyun|AliYunDun' | grep -v grep

[疑问] 如何强制卸载阿里云盾(安骑士)监控及屏蔽云盾IP

如何完全卸载阿里云盾

2、国内vps设置代理

# 国外vps下载v2ray内核压缩包
curl -fsSL https://ghproxy.com/https://github.com/v2fly/v2ray-core/releases/download/v5.7.0/v2ray-linux-64.zip -o v2ray.zip
# 解压文件,并指定解压的目录
unzip v2ray.zip -d v2ray

v2rayN软件导出节点配置信息,存为config.json,并且上传到服务器上的v2ray文件夹,替换掉原本默认的config.json。

# 测试v2ray
./v2ray test
# 在后台启动v2ray程序并使其在退出终端后仍然运行
nohup /root/v2ray/v2ray run > /dev/null 2>&1 &
# 查找与v2ray相关的所有正在运行的进程
ps -ef | grep v2ray
# 使用socks5代理访问google,测试能否科学上网
curl --socks5 127.0.0.1:10808 https://www.google.com

或者将v2ray设置为系统服务

# 使用 nano 编辑器打开并编辑位于 /etc/systemd/system/ 目录下的 v2ray.service 文件
nano /etc/systemd/system/v2ray.service

[Unit]
Description=V2Ray Service
Documentation=https://www.v2fly.org/
After=network.target nss-lookup.target

[Service]
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/root/v2ray/v2ray run
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 重新加载 systemd 的配置文件
sudo systemctl daemon-reload
# 启动名为 "v2ray" 的 systemd 服务
sudo systemctl start v2ray
# 使 "v2ray" 服务在系统启动时自动运行
sudo systemctl enable v2ray
  • 永久生效型:
# 使用 vim 文本编辑器打开当前用户的 bash 配置文件
vim ~/.bashrc
# 定义 HTTP 代理服务器的地址
export http_proxy=socks5://127.0.0.1:10808
# ​重新加载当前用户的 .bashrc 文件
source ~/.bashrc
  • 仅在当前终端生效:
# 注:只能设置一种代理socks5或者http代理
# 设置socks5代理
export http_proxy=socks5://localhost:10808
export https_proxy=socks5://localhost:10808
# 设置http代理
export http_proxy="http://localhost:10809"
export https_proxy="http://localhost:10809"
# 使得代理失效
unset http_proxy
unset https_proxy

3、wget下载走代理的方式

# 编辑wget 命令的用户配置文件
vim ~/.wgetrc
# 告诉 wget 默认使用代理服务器。如果没有这个设置,即使你指定了 http_proxy 或 https_proxy,wget 也不会使用代理服务器
use_proxy=yes
# 设置了 wget 对于 HTTP 请求的默认代理服务器地址和端口
http_proxy=127.0.0.1:10809
# 设置了 wget 对于 HTTPS 请求的默认代理服务器地址和端口
https_proxy=127.0.0.1:10809

4、国内服务器搭建xray

# 国外vps下载v2ray内核压缩包
curl -fsSL https://gh-hk.gujiakai.top/https://github.com/XTLS/Xray-core/releases/download/v1.8.6/Xray-linux-64.zip -o xray.zip
# 解压文件,并指定解压的目录
unzip xray.zip -d xray
# 删除xray压缩包
rm -rf xray.zip
# 进入xray目录
cd xray 
# 编辑配置文件,并将客户端到处的xray的配置粘贴进去
vim config.json
# 编辑xray的系统服务文件
vim /etc/systemd/system/xray.service

[Unit]
Description=Xray Service
Documentation=https://xtls.github.io/
After=network.target nss-lookup.target

[Service]
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/root/xray/xray run
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 重新加载内核
systemctl daemon-reload
# 设置xray开机自启,并且立即启动xray
systemctl enable --now xray
# 编辑bash配置文件
vim .bashrc
# 设置http代理
export http_proxy="http://localhost:10809"
export https_proxy="http://localhost:10809"
# 或者设置全局代理
export ALL_PROXY=socks5://127.0.0.1:10808
# 使bash配置生效
source .bashrc