阿里云、腾讯云的服务器出厂都会自带监控组件(阿里云盾 AliYunDun / 安骑士、腾讯云云监控 / 云镜)。很多用户希望对自己的服务器拥有完全的控制权,因此需要将它们卸载。本教程整理自网络经验帖,步骤清晰、命令可直接复制使用。
SSH 连接阿里云服务器,在终端中依次输入下方命令,进行卸载操作:
wget http://update.aegis.aliyun.com/download/uninstall.sh chmod +x uninstall.sh ./uninstall.sh wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh chmod +x quartz_uninstall.sh ./quartz_uninstall.sh
pkill aliyun-service rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service rm -rf /usr/local/aegis*
执行下面命令,通过 iptables 防火墙屏蔽云盾的 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 -ef | grep AliYunDun
或者:
ps -aux | grep -E 'aliyun|AliYunDun'
使用 chkconfig --list 查看开机自启列表里这个软件的服务名,一般是 aegis:
# chkconfig --list
aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloudmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysql 0:off 1:off 2:off 3:off 4:off 5:off 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果想开机不启动,执行 chkconfig --del aegis(这个 aegis 就是查出来的 AliYunDun 后台服务名):
service aegis stop # 停止服务 chkconfig --del aegis # 删除服务
如果还有残留进程,可通过以下命令强制结束:
ps -ef | grep -v grep | grep -i aliyundun | awk '{print $2}' | xargs kill -9
腾讯云服务器默认安装的监控组件包括:云监控(安装目录 /usr/local/qcloud/stargate 和 /usr/local/qcloud/monitor)和主机安全(云镜)(安装目录 /usr/local/qcloud/YunJing)。新开的服务器如果不取消勾选,都会默认安装。
在终端中依次执行以下三个卸载脚本:
/usr/local/qcloud/stargate/admin/uninstall.sh /usr/local/qcloud/YunJing/uninst.sh /usr/local/qcloud/monitor/barad/admin/uninstall.sh
脚本卸载完监控后,腾讯云目录里可能还残留其他组件。为了保险起见,停用并删除 TAT 组件(自动化助手)与整个 qcloud 目录:
systemctl stop tat_agent systemctl disable tat_agent rm -f /etc/systemd/system/tat_agent.service rm -fr /usr/local/qcloud
以下两个脚本都可以用,第二个国内网络可访问:
wget -qO- https://raw.githubusercontent.com/littleplus/TencentAgentRemove/master/remove.sh | bash
wget -qO- https://cdn.jsdelivr.net/gh/lufei/TencentAgentRemove@master/remove.sh | bash
执行下面的命令检查残留:
ps -A | grep agent
轻量应用服务器默认使用 ubuntu 等普通账户登录,需要切换到 root 账户操作。
sudo passwd root
输入 root 的密码后按 Enter,重复输入一次再按 Enter。返回下面信息即表示设置成功:
passwd: password updated successfully
sudo vi /etc/ssh/sshd_config
sudo service ssh restart
su root
sudo -i echo root:77nn.net |chpasswd root sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config; sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; service sshd restart