首页
📈统计
📬留言
💘关于
更多
💞友链
📺直播
🎠壁纸
Search
1
docker部署chromium
5 阅读
2
prometheus+alertmanager告警
2 阅读
3
minio部署以及使用挂载
2 阅读
4
typecho背景透明设置
2 阅读
5
httpd文件服务器
1 阅读
🎑Linux
centos
ubuntu
deepin
debian
🎉Typecho
🎻小程序
🍕生活
🍞其他
☸k8s
🤖监控配置
登录
Search
标签搜索
shell
脚本
文档
doc
存储
typecho
chromium
lazy-balancer
Typecho
累计撰写
57
篇文章
累计收到
37
条评论
首页
栏目
🎑Linux
centos
ubuntu
deepin
debian
🎉Typecho
🎻小程序
🍕生活
🍞其他
☸k8s
🤖监控配置
页面
📈统计
📬留言
💘关于
💞友链
📺直播
🎠壁纸
搜索到
57
篇与
的结果
2025-10-29
linux批量创建、删除、更新用户密码
创建存放用户的文件userscat users test01 test02 test03#!/usr/bin/env bash # 定义的函数 some_function() { # 操作逻辑 return } # 函数:创建用户 create_user() { my_array=() while IFS= read -r i # 使用while循环和read更安全并且兼容空格 do id "$i" > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "The user $i already exists!" my_array+=("$i") else useradd -m -s /bin/bash "$i" > /dev/null 2>&1 fi done < ./users if [ "${#my_array[@]}" -eq 0 ];then some_function else exit 1 fi } # 函数:生成随机密码 generate_password() { local length="$1" if [ -z "$length" ]; then length=16 fi tr -dc 'A-Za-z0-9!@#$%^&*()_+{}|:<>?' < /dev/urandom | head -c "$length" | xargs } # 函数:更新用户密码 rm -rf password.txt update_passwd() { while IFS= read -r i do id "$i" > /dev/null 2>&1 if [ $? -eq 0 ]; then # 生成新的密码 new_password=$(generate_password 16) # 更改用户的密码 echo "$i:$new_password" | chpasswd # 输出新密码 echo "新的 $i 密码已设置为: $new_password" >> password.txt echo "用户 $i 密码已存放到./password.txt文件中" else echo "$i User creation failed!" exit 1 fi done < ./users } # 确认是创建用户还是删除用户 del_arry=() if [ "${1}" = "delete" ];then while IFS= read -r i # 使用while循环和read更安全并且兼容空格 do id "$i" > /dev/null 2>&1 if [ $? -eq 0 ]; then userdel "$i" > /dev/null 2>&1 del_arry+=("$i") else echo "${i} user does not exist" fi done < ./users echo "已删除用户: ${del_arry[@]}" exit 0 elif [ "${1}" = "create" ];then # 创建用户 create_user # 更改用户密码 update_passwd elif [ "${1}" = "update" ];then # 更改用户密码 update_passwd else echo "ureate user or delete user or update user password? create/delete/update" exit 1 fi执行脚本# 创建用户 bash user.sh create # 删除用户 bash user.sh delete # 更新用户密码 bash user.sh update
2025年10月29日
0 阅读
0 评论
0 点赞
2025-10-10
jmeter linux部署
安装javayum install -y java-1.8.0-openjdk-devel.x86_64 [root@centos-02 yace]# java -version openjdk version "1.8.0_412" OpenJDK Runtime Environment (build 1.8.0_412-b08) OpenJDK 64-Bit Server VM (build 25.412-b08, mixed mode)下载:apache-jmeter-3.2.tgzwget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.6.3.tgz tar -zxvf apache-jmeter-5.6.3.tgz mv apache-jmeter-5.6.3 jmeter配置环境变量vim /etc/profile export JMETER_HOME=/opt/jmeter export PATH=$PATH:$JMETER_HOME/bin验证安装jmeter -v参数说明jmeter.bat(Windows)/jmeter.sh(Linux) -? # 列出所有命令行选项;在命令提示符中输入jmeter.bat(Windows)/jmeter.sh(Linux) -? ,可以获取 JMeter 所有可用的命令行参数说明,方便用户了解和使用 jmeter.bat(Windows)/jmeter.sh(Linux) [-p property-file] # GUI 模式运行:使用jmeter.bat(Windows)/jmeter.sh(Linux) [-p property-file] 命令,其中-p参数可选,用于指定属性文件。该模式下会弹出 JMeter 的图形化界面,便于用户直观地创建、编辑和运行测试计划 jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] # 非 GUI 模式运行:jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] ,-n表示非 GUI 模式,-t指定测试计划文件,-p指定属性文件(可选),-l指定结果文件用于记录测试结果,-j指定日志文件。适用于批量运行测试、持续集成环境等场景 jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to output folder] # 非 GUI 模式运行并在结束时生成报告:jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to output folder] ,在非 GUI 模式基础上,-e表示测试结束后生成 HTML 报告,-o指定报告输出文件夹(文件夹必须为空) jmeter.bat(Windows)/jmeter.sh(Linux) -g [csv results file] -o [path to output folder (empty or not existing)] # 从现有 CSV 文件生成报告:jmeter.bat(Windows)/jmeter.sh(Linux) -g [csv results file] -o [path to output folder (empty or not existing)] ,-g指定已有的 CSV 格式测试结果文件,-o指定输出报告的文件夹(需为空或不存在) jmeter.bat(Windows)/jmeter.sh(Linux) -H [your.proxy.server] -P [your proxy server port] # 设置代理服务器:jmeter.bat(Windows)/jmeter.sh(Linux) -H [your.proxy.server] -P [your proxy server port] ,-H指定代理服务器地址,-P指定代理服务器端口,用于在测试时通过代理服务器进行网络访问运行压测以非 GUI 模式(命令行模式)运行 JMeter 测试jmeter -n -t test.jmx -l result.jtl指定并发数和持续时间jmeter -n -t test.jmx -l result.jtl -Jthreads=100 -Jduration=600生成 HTML 报告test.jmx 文件可以在windows系统部署jmeter,然后配置好线程组,再保存jmxtest.jmx: 压测文件report_folder: 输出目录result.jtl: 结果树jmeter.log: 聚合报告jmeter -n -t test.jmx -l result.jtl -e -o report_folder [root@centos-02 daemon]# ll 总用量 1012 lrwxrwxrwx 1 root root 48 3月 20 11:34 jmeter -> /data/yace/jmeter/apache-jmeter-5.6.3/bin/jmeter -rw-r--r-- 1 root root 1586 3月 20 11:37 jmeter.log drwxr-xr-x 4 root root 84 3月 20 11:34 report_folder -rw-r--r-- 1 root root 3730 3月 20 11:34 result.jtl -rw-r--r-- 1 root root 4815 3月 20 11:30 test.jmx [root@centos-02 daemon]# tar -zcvf report_folder.tar.gz report_folder # 将report_folder.tar.gz 解压到windos本地,然后点击index.html文件,即可查看测试报告windows jmeter配置
2025年10月10日
0 阅读
0 评论
0 点赞
2025-09-29
自定义证书生成
创建证书脚本 create-cert.sh#!/usr/bin/env bash #set -x # 输出目录 output_dir=$(date "+%Y-%m-%d-%H-%M")-certificate inst_msg() { # 绿色 echo -e "\033[32mINFO: [$(date +"%Y-%m-%d %H:%M:%S")] $1\033[0m" } create_secret(){ mkdir -p "$output_dir" || { echo "无法创建目录 $output_dir"; exit 1; } # 使用第一个域名作为CA证书的CN local primary_domain="${domains[0]}" openssl genrsa -out "$output_dir/ca.key" 4096 openssl req -x509 -new -nodes -sha512 -days 365000 \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=*.${primary_domain}" \ -key "$output_dir/ca.key" -out "$output_dir/ca.crt" openssl genrsa -out "$output_dir/server.key" 4096 # 使用第一个域名作为CSR的CN openssl req -sha512 -new \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=${primary_domain}" \ -key "$output_dir/server.key" -out "$output_dir/server.csr" } create_ext(){ # 初始化v3.ext文件 cat > "$output_dir/v3.ext" <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] EOF # 添加域名 local dns_count=1 for domain in "${domains[@]}"; do echo "DNS.${dns_count}=${domain}" >> "$output_dir/v3.ext" echo "DNS.$((dns_count+1))=*.${domain}" >> "$output_dir/v3.ext" # 添加泛域名 ((dns_count+=2)) done # 添加IP地址 local ip_count=1 for ip in "${ips[@]}"; do echo "IP.${ip_count}=${ip}" >> "$output_dir/v3.ext" ((ip_count++)) done } create_zs(){ openssl x509 -req -sha512 -days 365000 \ -extfile "$output_dir/v3.ext" \ -CA "$output_dir/ca.crt" -CAkey "$output_dir/ca.key" \ -CAcreateserial -in "$output_dir/server.csr" \ -out "$output_dir/server.crt" openssl x509 -inform PEM -in "$output_dir/server.crt" -out "$output_dir/server.cert" } create_st(){ create_secret create_ext create_zs } # 检查是否安装了openssl if ! command -v openssl &> /dev/null; then echo "错误: 需要安装openssl才能运行此脚本" exit 1 fi # 读取用户输入 read -p "输入证书IP地址(多个IP用空格分隔,如: 192.168.4.4 10.0.0.1): " ip_input read -p "输入域名(多个域名用空格分隔,如: example.com demo.com): " domain_input # 将输入转换为数组 IFS=' ' read -ra ips <<< "$ip_input" IFS=' ' read -ra domains <<< "$domain_input" # 验证IP地址格式 ip_count=0 for ip in "${ips[@]}"; do if [[ ! "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "错误: 输入的IP地址格式不正确: $ip" exit 1 fi ((ip_count++)) done # 验证域名输入 if [[ ${#domains[@]} -eq 0 ]]; then echo "错误: 至少需要输入一个域名" exit 1 fi # 验证域名格式 for domain in "${domains[@]}"; do if [[ ! "$domain" =~ ^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$ ]]; then echo "错误: 域名格式不正确: $domain" exit 1 fi done inst_msg "开始生成证书到目录 $output_dir..." inst_msg "包含的IP地址: ${ips[*]}" inst_msg "包含的域名: ${domains[*]}" create_st # 生成证书 # 使用第一个域名作为目录名 primary_domain="${domains[0]}" if [ -d "${primary_domain}" ]; then rm -rf "${primary_domain}" fi mv "${output_dir}" "${primary_domain}" # 查询证书到期时间 certificate=$(openssl x509 -in "${primary_domain}/server.crt" -text -noout | grep -A 1 "Not After" | awk -F': ' 'NR==1{print $2}') echo "" inst_msg "######## 证书生成完成! ########" inst_msg "CA证书路径: ${primary_domain}/ca.crt" inst_msg "服务器证书: ${primary_domain}/server.crt" inst_msg "服务器密钥: ${primary_domain}/server.key" inst_msg "包含的IP地址: ${ips[*]}" inst_msg "包含的域名: ${domains[*]}" inst_msg "泛域名: *.${domains[0]}, *.${domains[1]}, ..." inst_msg "证书到期时间: ${certificate}" inst_msg "验证证书命令: openssl x509 -in ${primary_domain}/server.crt -text -noout"添加权限chmod +x create-cert.sh执行脚本create-cert.sh
2025年09月29日
0 阅读
0 评论
0 点赞
2025-08-19
kk 部署k8s
部署参考如下连接kubekey部署kubernetes集群: https://packages.emal.cc/package/softinstall/produce/KubeKey/v2.26.12/%e9%83%a8%e7%bd%b2%e8%af%b4%e6%98%8e.htmlkubekey官网
2025年08月19日
0 阅读
0 评论
0 点赞
2025-08-18
cloudreve云盘部署
docker-compose 部署 cloudreve云盘version: '3.8' services: cloudreve: image: cloudreve/cloudreve:latest container_name: cloudreve restart: always ports: - "5212:5212" volumes: - ./cloudreve/uploads:/cloudreve/uploads - ./cloudreve/data:/cloudreve/data - ./cloudreve/conf:/cloudreve/conf - ./cloudreve/db:/cloudreve/db - ./cloudreve/avatar:/cloudreve/avatar environment: - TZ=Asia/Shanghai - DB_TYPE=mysql # 启用MySQL时取消注释 - DB_HOST=mysql # 启用MySQL时取消注释 - DB_PORT=3306 # 启用MySQL时取消注释 - DB_USER=cloudreve # 启用MySQL时取消注释 - DB_PASS=password # 修改为你的密码 - DB_NAME=cloudreve # 启用MySQL时取消注释 - REDIS_SERVER=redis:6379 # 启用Redis时取消注释 depends_on: - mysql # 启用MySQL时取消注释 - redis # 启用Redis时取消注释 networks: - cloudreve-net # MySQL数据库(生产环境推荐) mysql: image: mysql:8.0 container_name: mysql restart: always environment: MYSQL_ROOT_PASSWORD: password # 修改为你的root密码 MYSQL_DATABASE: cloudreve MYSQL_USER: cloudreve MYSQL_PASSWORD: password # 与上方DB_PASS一致 volumes: - ./cloudreve/mysql:/var/lib/mysql networks: - cloudreve-net # Redis缓存(提升性能) redis: image: redis:alpine container_name: redis restart: always volumes: - ./redis:/data networks: - cloudreve-net # Aria2离线下载(可选) aria2: image: p3terx/aria2-pro container_name: aria2 restart: unless-stopped environment: - RPC_SECRET=password # 修改为你的密码 - DISK_CACHE=128M - UMASK_SET=022 volumes: - ./aria2/config:/config - ./aria2/downloads:/downloads ports: - "6800:6800" networks: - cloudreve-net networks: cloudreve-net: driver: bridge创建对应的文件和目录mkdir -p ./cloudreve/{uploads,data,conf,db,avatar,mysql} mkdir -p ./aria2/{config,downloads} mkdir ./redis部署docker-compose up -d网站:https://cloudreve.emal.cc/账户:demo@163.com密码:demo1234
2025年08月18日
0 阅读
0 评论
0 点赞
2025-08-01
Linux ssh免密登录脚本
免密登录脚本提前生成公钥和私钥,将脚本中的公钥替换成你生成后的公钥#!/usr/bin/env bash # --------------------------- # 颜色定义 # --------------------------- YELLOW='\e[93m' # 黄色(信息提示) GREEN='\033[32m' # 绿色(成功提示) RED='\033[31m' # 红色(错误提示) RESET='\e[0m' # 重置颜色 YELLOWS='\033[1;33m' RESETS='\033[0m' # --------------------------- # 日志输出函数 # --------------------------- inst_msg() { local msg="$1" local datetime=$(date +"%Y-%m-%d %H:%M:%S") echo -e "${YELLOW}INFO: [${datetime}] ${msg}${RESET}" } infos_msg() { local msg="$1" local datetime=$(date +"%Y-%m-%d %H:%M:%S") echo -e "${YELLOWS}\033[5mINFO: [${datetime}] ${msg}\033[25m${RESETS}" } info_msg() { local msg="$1" local datetime=$(date +"%Y-%m-%d %H:%M:%S") echo -e "${GREEN}INFO: [${datetime}] ${msg}${RESET}" } err_msg() { local msg="$1" local datetime=$(date +"%Y-%m-%d %H:%M:%S") echo -e "${RED}ERRO: [${datetime}] ${msg}${RESET}" >&2 #exit 1 } create_sshd(){ # 确保.ssh目录存在 mkdir -p /root/.ssh chmod 700 /root/.ssh # 检查公钥是否已存在 if grep -q "kexinzz@163.com" ~/.ssh/authorized_keys 2>/dev/null; then info_msg "公钥已存在" else # 添加公钥 echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDkuyj2g8wMMebOPJSz4QvL4KR2HctUbTE1KEjLDCmMknlnALAO3bWPygQxYyi9SnDnKVhFiWfvyWZzRi8rASv0dYpfrIBsqrhtqvGgN1iteJPs+xqbgIq9KFTDPPbznOZjaGMAOySbqHT6/JtZd1Jtn7SEA146sdI/Hkrt9mNM3dAHp5E+ppSoJ8TzRq+rr+RGJ4raypCouniQZ7mbXqkCr3tGZLx+0beaTltm4Sm3qU6ChULc8sUBx14Zd40KZJb6Jgf7G6O6fw7tieeioZ0XaKvV8JvYHSQI43cXol+TG6rWFW/Kgh0nUYdVqaVtNg00ZCFnoQjlY/VD6kD0MNxhXwCGQ6nRsjVqiVTaDKPmOwMWPk3B25CbRTLc4aK4KfbqjCYWkK7huXzUBSeQPedvgjEPaw5ME6O/NwxIfOHiaSoIiFfsor01iM9sRihPO2xgcj4yw5i9L1s0/yJrhFIPLCNlUGxCFaXKitVUCWC4d1g8YyZgxyixgnaXwYqjKLsNsVIhfe294WBjI+T0iMy6T9iYcVk8J7Joe4ulIrhMs6eyAU7SpAcH5EpeUSxmvG1lScuviukZfC3QuPh45YRdEA3m2BEahkcAynxl1z1hXYyB0dGREXmAQmu42c+JjKQbUeGnCgre3MMpy9mgmloINSNBtW1Z0gztkz6R8jQeGw== kexinzz@163.com" >> ~/.ssh/authorized_keys info_msg "公钥添加成功" fi # 确保权限正确 chmod 600 ~/.ssh/authorized_keys } update_config(){ # 备份原始配置文件 cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak # 删除所有冲突的配置项 sed -i -E "/^(#\s*)?(PubkeyAuthentication|PasswordAuthentication|ChallengeResponseAuthentication|UsePAM|PermitRootLogin)/d" /etc/ssh/sshd_config # 添加新的安全配置 echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config echo "PasswordAuthentication no" >> /etc/ssh/sshd_config echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config echo "UsePAM no" >> /etc/ssh/sshd_config echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config # 修改完配置文件后,需要重启 SSH 服务使配置生效 if systemctl restart sshd; then info_msg "SSH服务重启成功" else err_msg "SSH服务重启失败" return 1 fi } print_ssh_config_table() { # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' RESET='\033[0m' # 检查是否有root权限,因为需要读取/etc/ssh/sshd_config if [ "$(id -u)" -ne 0 ]; then echo -e "${RED}错误: 需要root权限运行此脚本。请使用sudo命令。${RESET}" exit 1 fi # 从配置文件获取数据 config_data=$(grep -E "^(PubkeyAuthentication|PasswordAuthentication|ChallengeResponseAuthentication|UsePAM|PermitRootLogin)" /etc/ssh/sshd_config) # 检查是否找到了配置项 if [ -z "$config_data" ]; then echo -e "${RED}错误: 在/etc/ssh/sshd_config中未找到匹配的配置项。${RESET}" exit 1 fi # 计算配置项和值的最大长度 max_key_length=0 max_value_length=0 while IFS= read -r line; do key=$(echo "$line" | awk '{print $1}') value=$(echo "$line" | awk '{print $2}') key_length=${#key} value_length=${#value} if [ $key_length -gt $max_key_length ]; then max_key_length=$key_length fi if [ $value_length -gt $max_value_length ]; then max_value_length=$value_length fi done <<< "$config_data" # 确保列宽足够显示标题 if [ $max_key_length -lt 6 ]; then max_key_length=6 fi if [ $max_value_length -lt 3 ]; then max_value_length=3 fi # 添加一些边距 max_key_length=$((max_key_length + 2)) max_value_length=$((max_value_length + 2)) # 计算表格总宽度 table_width=$((max_key_length + max_value_length + 3)) # 3个竖线 # 生成横线 hline=$(printf '%*s' "$table_width" '' | tr ' ' '-') # 打印表头 echo -e "\n${BLUE}SSH 安全配置信息:${RESET}" echo -e "${BLUE}+${hline}+${RESET}" printf "${YELLOW}| ${BLUE}%-${max_key_length}s${YELLOW} | ${BLUE}%-${max_value_length}s${YELLOW} |${RESET}\n" "配置项" "值" echo -e "${BLUE}+${hline}+${RESET}" # 打印每一行配置 while IFS= read -r line; do key=$(echo "$line" | awk '{print $1}') value=$(echo "$line" | awk '{print $2}') # 根据值设置颜色 if [ "$value" = "yes" ] || [ "$value" = "without-password" ]; then value_color="${GREEN}" else value_color="${RED}" fi # 打印行 printf "${YELLOW}| ${RESET}%-${max_key_length}s${YELLOW}| ${value_color}%-${max_value_length}s${YELLOW}|${RESET}\n" "$key" "$value" done <<< "$config_data" # 打印表尾 echo -e "${BLUE}+${hline}+${RESET}\n" | column -t } # 主执行流程 create_sshd update_config print_ssh_config_table if [ $? -eq 0 ]; then info_msg "SSH密钥登录设置成功" # 验证配置 inst_msg "验证配置:" echo -e "公钥认证: $(grep -q '^PubkeyAuthentication yes' /etc/ssh/sshd_config && echo -e "${GREEN}已启用${RESET}" || echo -e "${RED}未启用${RESET}")" echo -e "密码认证: $(grep -q '^PasswordAuthentication no' /etc/ssh/sshd_config && echo -e "${GREEN}已禁用${RESET}" || echo -e "${RED}未禁用${RESET}")" exit 0 else err_msg "SSH密钥登录设置失败" # 恢复备份 mv /etc/ssh/sshd_config.bak /etc/ssh/sshd_config systemctl restart sshd err_msg "已恢复原始SSH配置" exit 127 fi
2025年08月01日
0 阅读
0 评论
0 点赞
1
...
5
6
7
...
10