#!/bin/bash
# 域名列表
domains=("www.qq.com" "www.qq.com.cn" "www.ww.cn")
#查询/etc/nginx/conf.d/*.conf配置文件中的域名,并去重,sh不支持数组,如果用这种方式 需要bash环境运行
#domains=($(grep -hroP 'server_name\s+\K\S+' /etc/nginx/conf.d/*.conf | tr -d ';' | sort -u))
# 企业微信群聊机器人的 Webhook 地址
webhook_url="https://123/123"
# 循环遍历域名列表
for domain in "${domains[@]}"; do
echo "$domain"
# 查询域名的证书有效期
expiration_date=$(openssl s_client -connect "$domain":443 -servername "$domain" 2>/dev/null | openssl x509 -noout -dates | grep notAfter | cut -d "=" -f 2)
echo "Certificate expiration for $domain: $expiration_date"
# 将日期转换为时间戳
expiration_timestamp=$(date -d "$expiration_date" +%s)
# 当前时间戳
current_timestamp=$(date +%s)
# 计算剩余天数
remaining_days=$(( (expiration_timestamp - current_timestamp) / 86400 ))
# 如果剩余天数小于等于10天,则发送警告消息到企业微信群聊机器人
if [ $remaining_days -le 10 ]; then
subject="SSL Certificate Expiration Warning - $domai
#命令备忘
#当前目录下,文件和文件夹按大小排序并显示大小
du -sh * | sort -hr
#显示当前目录下所有文件夹的大小
du --max-depth=1 -h
#查看一个进程的父进程
lsof -p <PID>
pstree -p <PID>
pstree -p | grep "<PID>"
#系统日志指定大小和保留时间
journalctl --vacuum-time=2d
journalctl --vacuum-size=500M
#npm源
npm install --registry=https://registry.npm.taobao.org
npm install --registry=https://registry.npmmirror.com
npm install --registry=https://mirrors.cloud.tencent.com/npm/
#phpinfo
<?php
phpinfo();
?>
#docker打tag并推送至远程仓库 harbor.net替换为仓库地址
docker build --tag imagename:v$BUILD_ID .
docker tag imagename:v$BUILD_ID harbor.net/imagename:v$BUILD_ID
docker push harbor.net/imagename:v$BUILD_ID
#MySQL备份脚本
#!/bin/sh
#定义数据库host及备份目录
backup_host="10.0.0.1"
backup_dir=/data/mysql_bak
# 定义数据库账号密码及备份语句
mysql_user="user"
mysql_password="passwd"
mysqldump_opts="-h $backup_host -u $mysql_user -p$mysql_password --default-character-set=utf8"
date=$(date '+%Y%m%d%H%M')
#以下为定义数据库库名,二选一
# 定义数据库库名
databases='databasename1 databasename2'
# 自动获取数据库库名
databases=$(mysql -h $backup_host -u $mysql_user -p$mysql_password -e 'SHOW DATABASES;' | grep -Ev "(Database|information_schema|performance_schema|mysql|sys)")
#测试数据库
umask 0077
test ! -d "$backup_dir" && mkdir -p "$backup_dir"
test ! -w "$backup_dir" && echo "Error: $backup_dir is un-writeable." && exit 0
# 循环备份
for database in $databases
do
/usr/local/mysql/bin/mysqldump $mysqldump_opts $database > "$backup_dir/$database-$date.sql"
done
# 打包备份文件并删除7天前的备份
cd "$backup_dir"
tar zcvf "mysqlbak_$date.tar.gz" *.sql
rm -rf *.sql
find "$backup_dir" -type f -mtime +7
#生成密钥,默认回车即可
ssh-keygen
#拷贝密钥至主机
ssh-copy-id root@192.168.47.135
ssh-copy-id root@192.168.47.136
cd /root/.SSH
cat id_rsa.pub > authorized_keys
vi /etc/ansible/hosts
[test]
192.168.47.134
192.168.47.135
192.168.47.136
yum -y install epel-release.noarch
yum -y install tree
yum -y install ansible
windows
# 安装pywinrm模块
pip install pywinrm
#在控制节点上创建或编辑Ansible的主机清单文件(例如 /etc/ansible/hosts):
[windows]
windows_host ansible_host=<windows_ip>
[windows:vars]
ansible_user=<your_username>
ansible_password=<your_password>
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
#创建一个简单的Ansible剧本(例如 win_ping.yml),测试连接到Windows主机:
---
- name: Test connection to Windows host
hosts: windows
tasks:
- name: Ping the Windows host
win_ping:
#在控制节点上运行Ansible剧本:
ansible-playbook win_ping.yml
通过tree查看ansible有哪些文件,当然还有很多文件没有列举出来
tree /etc/ansible/
/etc/ansible/
├── ansible.cfg #配置文件
├── hosts #主机清单文件
└── roles
跨域配置
单域名跨域
# 允许所有来源的跨域请求
add_header 'Access-Control-Allow-Origin' 'https://test.test.com';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,token,Authorization';
# 设置预检请求的有效期
add_header 'Access-Control-Max-Age' 1728000;
# 允许携带身份凭证(例如,cookie)
add_header 'Access-Control-Allow-Credentials' 'true';
# 处理预检请求(OPTIONS请求)
if ($request_method = 'OPTIONS') {
return 204;
}
多域名跨域
# 在http块中定义一个map,将请求的Origin映射到允许的Origin
map $http_origin $allowed_origin {
"~^(https://test1.test.com|https://test2.test.com|https://test3.test.com)$" $http_origin;
default "";
}
server {
listen 80;
listen 443 ssl http2;
server_name test.test.com;
index index.html index.htm index.php;
charset utf-8;
error_log /var/log/nginx/test.test.com-error.log error