月度归档:2021年07月

nginx的stream模块转发配置

upstream xaio443 {
  server 172.16.0.103:443;
  server 172.16.0.104:443;
}

upstream xaio80 {
  server 172.16.0.103:80;
  server 172.16.0.104:80;
}

log_format proxy '$proxy_protocol_addr $remote_addr [$time_local] '
    '$protocol $status $bytes_sent $bytes_received '
    '$session_time "$upstream_addr" '
    '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

server {
  listen 443;
  ssl_preread on;
  proxy_connect_timeout 1s;
  proxy_timeout 3s;
  proxy_pass xaio443;


  access_log /data/logs/access443.log proxy;
  error_log /data/logs/error443.log info;
}

server {
  listen 80;
  proxy_connect_timeout 1s;
  proxy_timeout 3s;
  proxy_pass xaio80;


  access_log /data/logs/access80.log proxy;
  error_log /data/logs/error80.log info;
}

sh和api服务冲突的解决方案脚本

#!/bin/bash
path_current=`pwd`
path_script=$(cd "$(dirname "$0")"; pwd)

cd ${path_script}
echo "$(date)" >> ./check.txt
podnamspace="-n test"
shpods=$(kubectl describe pods "sh-" ${podnamspace}|grep "^Name:"|awk '{print $2}')
echo ${shpods}
sh_tm_max=0
for sh in ${shpods[@]}
do
  mytime=$(kubectl describe pod ${sh} ${podnamspace}|grep "^Start Time:")&& mytime=$(echo ${mytime:11}) && mytime=$(date -d "$mytime" +%s)
  elapse=$(expr ${sh_tm_max} - ${mytime})
  if [ $? == 0 ] && [ ${elapse} -lt 0 ]; then
     sh_tm_max=${mytime}
  fi
done
echo "sh pods start time: $sh_tm_max"
apipods=$(kubectl describe pods "api-" ${podnamspace}|grep "^Name:"|awk '{print $2}')
echo ${apipods}
for api in ${apipods[@]}
do
  mytime=$(kubectl describe pod ${api} ${podnamspace}|grep "^Start Time:")&& mytime=$(echo ${mytime:11}) && mytime=$(date -d "$mytime" +%s)
  elapse=$(expr ${sh_tm_max} - ${mytime})
  howMinute=$(expr $elapse / 60)
  output="${api} pod start time: $mytime, ${sh_tm_max} - ${mytime}=[${elapse}s, ${howMinute}m]"
  echo "$output" &&  echo "$output" >> ./check.txt
  if [ $? == 0 ] && [ $howMinute -ge 0 ]; then
     echo "delete this pod $api"
     kubectl delete pod $api ${podnamspace} && echo "success to delete $api" >> ./check.txt
  fi
done