标签存档: 服务器安全

rsync 873 端口如何通过Linux服务器防火墙

为了允许通过防火墙使用rsync的默认端口873,你需要在服务器和/或客户端上配置防火墙规则以允许873端口的通信。以下是不同操作系统下的基本步骤:

# 允许873端口的入站连接(假设你正在使用rsync守护进程模式)
sudo ufw allow 873/tcp
# 如果需要同时允许出站连接
sudo ufw allow out 873/tcp
# 检查规则是否生效
sudo ufw status verbose

在iptables防火墙中手动配置(适用于大多数Linux发行版):

# 允许873端口的入站连接
sudo iptables -A INPUT -p tcp --dport 873 -j ACCEPT
# 可能还需要允许出站连接(如果服务器需要发起连接)
sudo iptables -A OUTPUT -p tcp --dport 873 -j ACCEPT
# 如果有防火墙策略保存机制(如firewalld或systemd-networkd),记得保存规则
sudo iptables-save

Apache2子域名配置

前提是子域名可以正常解析ip地址。

打开子域名所解析服务器的apache2配置文件,加入以下内容:

<VirtualHost *:80>
ServerAdmin 1324928751@qq.com
DocumentRoot /var/www/night
ServerName night.wp.cpxiang.tech
ServerAlias night.wp.cpxiang.tech
</VirtualHost>

重启apache2。

阿里云Centos配置腾讯SMTP邮箱

which mail
yum -y install mailx
vim /etc/mail.rc

写入:

# mail config
set from=zpmail@wp.cpxiang.tech 
set smtp=smtps://smtp.qq.com:465  
set smtp-auth-user=1324928751
set smtp-auth-password=<授权码> 
set smtp-auth=login 
set nss-config-dir=/root/.certs  
set ssl-verify=ignore
mkdir -p /root/.certs
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
echo "hallo" | mail -v -s "this is Test Mail" 1324928751@qq.com

监测阿里云CentOS服务器的shell脚本

#!/bin/bash
function cpu() {
    NUM=1
    while [ $NUM -le 3 ]; do
        util=`vmstat |awk '{if(NR==3)print 100-$15"%"}'`
        user=`vmstat |awk '{if(NR==3)print $13"%"}'`
        sys=`vmstat |awk '{if(NR==3)print $14"%"}'`
        iowait=`vmstat |awk '{if(NR==3)print $16"%"}'`
        echo -e "CPU - 使用率:"$util",等待磁盘IO响应使用率:"$iowait
        let NUM++
        sleep 1
    done
}

function memory() {
    total=`free -m |awk '{if(NR==2)printf "%.1f",$2/1024}'`
    used=`free -m |awk '{if(NR==2) printf "%.1f",($2-$NF)/1024}'`
    available=`free -m |awk '{if(NR==2) printf "%.1f",$NF/1024}'`
    echo "内存 - 总大小: ${total}G , 使用: ${used}G , 剩余: ${available}G"
}

function disk() {
    fs=$(df -h |awk '/^\/dev/{print $1}')
    for p in $fs; do
        mounted=$(df -h |awk '$1=="'$p'"{print $NF}')
        size=$(df -h |awk '$1=="'$p'"{print $2}')
        used=$(df -h |awk '$1=="'$p'"{print $3}')
        used_percent=$(df -h |awk '$1=="'$p'"{print $5}')
        echo -e "硬盘 - 挂载点:"$mounted",总大小:"$size",使用:"$used",使用率:"$used_percent
    done
}

function tcp_status() {
    summary=$(ss -antp |awk '{status[$1]++}END{for(i in status) printf i":"status[i]" "}')
    echo "TCP连接状态 - $summary"
}

function 80_port(){
    apa=`netstat -tanpl | grep 80 | awk '{print $4}' | sed -n '1p'`
    if [ $apa != "0.0.0.0:80" ];then
        echo "80端口已经停止运行"
    else
        echo "80端口运行正常"
    fi
}

echo -e $(cpu)"\n"$(memory)"\n"$(disk)"\n"$(tcp_status)"\n"$(80_port) | mail -s "huacai服务器状态" 1324928751@qq.com

监测服务器的shell脚本

#! /bin/bash
#jiance.sh

#硬盘使用率
ds=`df|awk '{if(NR==4){print int($5)}}'`
#内存使用率
used=`free -m|awk '{if(NR==2){print int($3)}}'`

tot=`free -m|awk '{if(NR==2){print int($2)}}'`

per=$(($used*100/$tot))
#apache2是否正常运行
apa=`netstat -tanpl | grep 80 | awk '{print $4}' | sed -n '1p'`
#mysql是否正常运行
mysql=`netstat -tanpl | grep 3306 | awk '{print $4}' | sed -n '1p'`
#统计
res1="硬盘使用率:"$ds"%\n内存使用率:"$per"%\n"

#echo -e $res1

if [ $apa != "0.0.0.0:80" ];then
        str1="apache2已经停止运行"
else
        str1="apache2正常运行"
fi

if [ $mysql != "127.0.0.1:3306" ];then
        str2="myqsl已经停止运行"
else
        str2="mysql正常运行"
fi
#统计输出
text=$res1$str1"\n"$str2;
#监控发邮件
if [ $ds  -gt 45 ];then
        echo -e $text|mail -s "hotsun.link的运行状态" 1324928751@qq.com
fi

if [ $per -gt 55 ];then
        echo -e $text|mail -s "hotsun.link的运行状态" 1324928751@qq.com
fi