debian 通过 apt 方式安装 PHP7.4

sudo apt update
sudo apt install -y curl wget gnupg2 ca-certificates lsb-release apt-transport-https
wget https://packages.sury.org/php/apt.gpg
sudo apt-key add apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list
sudo apt update
sudo apt install -y php7.4 php7.4-cli php7.4-common php7.4-fpm php7.4-curl php7.4-bcmath php7.4-bz2 php7.4-dba php7.4-dom php7.4-enchant php7.4-gd php7.4-gmp php7.4-igbinary php7.4-imagick php7.4-zip php7.4-xsl php7.4-curl php7.4-xmlwriter php7.4-xmlrpc php7.4-xmlreader php7.4-xml php7.4-xdebug php7.4-tidy php7.4-swoole php7.4-soap php7.4-snmp php7.4-SimpleXML php7.4-redis php7.4-amqp php7.4-apcu php7.4-imap  php7.4-intl php7.4-ldap php7.4-mbstring php7.4-mcrypt php7.4-memcached php7.4-mongodb php7.4-pspell php7.4-pgsql php7.4-odbc php7.4-dev

systemctl start  php7.4-fpm
systemctl enable  php7.4-fpm
systemctl status  php7.4-fpm

参考文章: https://www.itzgeek.com/how-tos/linux/debian/how-to-install-php-7-3-7-2-7-1-on-debian-10-debian-9-debian-8.html

Nginx 源码安装脚本(debian版本)

#!/bin/bash
## install nginx
WORK_DIR=`mktemp -d`
apt install wget libpcre3 libpcre3-dev zlib1g-dev \
    openssl libssl-dev libxml2 libxml2-dev libxslt-dev  \
    gcc  make libgd-dev  libgeoip-dev libpcre3-dev libperl-dev -y
cd $WORK_DIR
wget http://nginx.org/download/nginx-1.27.2.tar.gz

tar zxvf nginx-1.27.2.tar.gz && cd nginx-1.27.2
./configure --prefix=/opt/nginx --user=apache --group=apache \
    --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module \
    --with-pcre --with-http_v2_module --with-http_dav_module \
    --with-http_flv_module --with-http_realip_module --with-http_addition_module \
    --with-http_xslt_module --with-http_sub_module --with-http_random_index_module \
    --with-http_degradation_module --with-http_secure_link_module --with-http_perl_module \
    --with-debug --with-file-aio --with-stream --with-ld-opt=-Wl,-E
make && make install
[ -d $WORK_DIR ] && rm $WORK_DIR -rf

## 添加nginx运行账户
cat /etc/passwd | grep apache
if [ $? -ne 0 ];then
    groupadd apache
    useradd -g apache -s /sbin/nologin -c "apache" apache
fi

python3 监控域名证书到期时间,并实现叮叮的及时报警

# _*_coding=utf-8 _*_
# @author 云深沾衣
# @date 2021/11/5 16:33

import re
import subprocess
from datetime import datetime
import requests


class DomainCheck:
    def __init__(self, domain_file='domain_file.txt', log_file='log.txt'):
        self.domain_file = domain_file
        self.log_file = log_file

    check_days = 5
    dingding_token = 'your_dingding_token'
    dingding_url = 'https://oapi.dingtalk.com/robot/send?access_token='

    def check_domain_ssl_status(self):
        with open(self.domain_file) as f:
            self.write_log_to_file('<------  ' + str(datetime.now()) + '    ------>' + '\n')
            for line in f:
                line = line.replace('\n', '').replace('\r', '').strip()
                if not line.startswith("#") and len(line) > 0:
                    expire_date = self.get_cert_expire_date(line)
                    content = line + ' :    ' + str(expire_date) + '\n'
                    self.write_log_to_file(content)
                    if expire_date <= self.check_days:
                        self.send_to_dingding(content)

    def send_to_dingding(self, content):
        content_data = {
            "msgtype": "text",
            "text": {
                "content": content
            }
        }
        requests.post(self.dingding_url + self.dingding_token, json=content_data)

    def write_log_to_file(self, content):
        with open(self.log_file, mode='a') as f:
            f.write(content)

    @staticmethod
    def parse_time(date_str):
        return datetime.strptime(date_str, "%b %d %H:%M:%S %Y GMT")

    @staticmethod
    def get_re_match_result(pattern, string):
        match = re.search(pattern, string)
        return match.group(1)

    def get_cert_info(self, domain):
        """获取证书信息"""
        cmd = f"curl -Ivs https://{domain} --connect-timeout 10"  # 这儿的 curl 应该使用最新版
        exitcode, output = subprocess.getstatusoutput(cmd)
        try:
            expire_date = self.get_re_match_result('expire date: (.*)', output)
        except:
            content = domain + ": This domain check failed , please check reason"
            self.send_to_dingding(content)
            expire_date = "Aug  7 00:28:51 2020 GMT"
        expire_date = self.parse_time(expire_date)
        return expire_date

    def get_cert_expire_date(self, domain):
        """获取证书剩余时间"""
        expire_date = self.get_cert_info(domain)
        # 剩余天数
        return (expire_date - datetime.now()).days


domain_check = DomainCheck('/opt/sh/text.txt', '/opt/sh/log.txt')
domain_check.check_domain_ssl_status()