标签存档: 运维 - 第2页

阿里云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

Ubuntu通过mail发送邮件

先修改/etc/s-nail.rc中来添加外部SMTP服务器如下:

set from=zpmail@wp.cpxiang.tech
set smtp="smtps://smtp.qq.com:465"
set smtp-auth=login
set smtp-auth-user=1324928751
set smtp-auth-password=<授权码>

尝试发送

echo "nihao" | mail -s "test" 1324928751@qq.com

Httpd配置多个顶级域名

先找到httpd.conf文件后添加:

LoadModule vhost_alias_module modules/mod_vhost_alias.so
#
#
#
Include conf/extra/httpd-vhosts.conf

然后是extra目录内的httpd-vhosts.conf文件:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "/var/www/site1"
    ServerName site1.com
    ServerAlias *.site1.com
    ErrorLog "logs/localhost-error_log"
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "/var/www/site2"
    ServerName site2.com
    ServerAlias *.site2.com
    ErrorLog "logs/localhost-error_log"
</VirtualHost>