页面“运维规划2018-2024”与“Redis批量删除key”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
→‎k8s
 
 
第1行: 第1行:
=2020=
+
[[category:ops]] [[category:redis]] 
==english==
 
  
==lua==
+
[[Redis-bigkeys]]
[[Lua基础]]
+
=redis cluster 批量删除key=
 
 
==golang==
 
 
 
=k8s=
 
搞个国内的吧 
 
[[Install and Configure Kubernetes (k8s) on debian10]]
 
 
 
[[2018k8s]]
 
 
 
=服务器费用=
 
自动续费 ?
 
 
 
=cmdb=
 
搞在xk intra 然后 frp到外面
 
 
 
[https://www.linuxprobe.com/cmdb-things.html 前聚美优品运维负责人谈CMDB]
 
 
 
[https://www.jianshu.com/p/f3a70cddccc5 CMDB和运维自动化]
 
 
 
[http://www.yunweipai.com/archives/6856.html (深度好文)重构CMDB,避免运维之耻]
 
 
 
[https://segmentfault.com/q/1010000003838760 开源CMDB]
 
 
 
=运维自动化=
 
 
 
[http://os.51cto.com/art/201806/576802.htm 小团队如何从零搭建一个自动化运维体系]
 
 
 
[http://os.51cto.com/art/201806/576888.htm 如何做好自动化运维?自动化运维必备技能有哪些]
 
 
 
 
 
[[category:ops]] [[category:生活与情感]]
 
==python 自动化 ==
 
 
 
[https://blog.csdn.net/aeolus_pu/article/details/52605109 利用python实现批量自动化运维脚本案例]
 
 
 
早下班时回家记得看书和动手例子
 
 
 
=监控=
 
==zabbix==
 
 
 
[[Zabbix报警]]
 
 
 
[https://blog.csdn.net/wyl9527/article/details/73928853 action_email 还有报警前执行脚本]
 
 
 
email 报警
 
短信报警
 
wechat 报警
 
 
 
zabbix new server docker 化
 
[https://blog.csdn.net/heyongluoyao8/article/details/51413668 服务器监控(包括性能指标与web应用程序)]
 
 
 
pinpoint
 
 
 
=python=
 
[https://blog.csdn.net/chengxuyuanyonghu/article/details/59486631 python常用运维脚本实例]
 
 
 
 
 
[https://blog.csdn.net/hardywang/article/details/51536510  python用于系统运维管理和灰度发布部署]
 
 
 
[http://www.voidcn.com/article/p-poyppygk-ng.html 基于python的一个运维自动化的项目(进度更新)【已开源】]
 
 
 
=django=
 
 
 
Gunicorn
 
 
 
=tomcat=
 
[http://blog.51cto.com/jowin/1739400 Linux运维 第三阶段 (十九) tomcat]
 
 
 
[https://blog.csdn.net/lifetragedy/article/details/7708724 通向架构师的道路(第四天)之Tomcat性能调优]
 
 
 
[https://www.jianshu.com/p/d45e12241af4 Tomcat性能调优-JVM监控与调优]
 
 
 
[https://blog.csdn.net/xyang81/article/details/51530979 Tomcat配置与优化(内存、并发、管理)]
 
 
 
 
 
[https://www.centos.bz/2017/08/tomcat-jvm-performance-tuning/ Tomcat和JVM的性能调优总结]
 
 
 
[https://www.oschina.net/translate/tomcat-performance-tuning Tomcat 生产服务器性能优化 【已翻译100%】]
 
 
 
[http://yunzhu.iteye.com/blog/953387 监控Tomcat解决方案(监控应用服务器系列文章)]
 
 
 
==tomcat优化==
 
 
 
[https://blog.csdn.net/coolwzjcool/article/details/2544448 TOMCAT内存大小调整]
 
 
 
[http://elf8848.iteye.com/blog/378805 Tomcat内存设置详解]
 
 
 
[https://blog.csdn.net/xyang81/article/details/51530979 Tomcat配置与优化(内存、并发、管理)]
 
 
 
[https://blog.csdn.net/lifetragedy/article/details/7708724 通向架构师的道路(第四天)之Tomcat性能调优-让小猫飞奔]
 
 
 
==tomcat 启动脚本==
 
 
<pre>
 
<pre>
 +
#June 19 2020  有空结果一下原来的版本再优化一下
 +
cat redis_del_key.sh
 
#!/bin/bash
 
#!/bin/bash
#cat /etc/init.d/pp-col  在centos7上试过 可运行
+
# Usage
# chkconfig: 345 99 28
+
#redis_list=("host:post" "host:post")
# description: Starts/Stops Apache Tomcat
 
  
#by evan
+
redis_list=( "172.16.200.12:7003" "172.16.200.7:7004" "172.16.200.7:7005" "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#修改几个目录
+
#redis_list=( "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
##export JAVA_HOME=/usr/java/jdk1.8.0_121/
+
#redis_list=("172.16.200.7:7004")
#sed -i "s/JAVA_HOME=\/usr\/java\/default\//JAVA_HOME=\/usr\/java\/jdk1.8.0_121\//g" pp-collector.init
+
password="3636password"
#sed -i "s/CATALINA_HOME=\/data\/service\/pinpoint-collector\//CATALINA_HOME=\/data\/pp-col\//g" pp-collector.init
 
#sed -i "s/CATALINA_BASE=\/data\/service\/pinpoint-collector\//CATALINA_BASE=\/data\/pp-col\//g" pp-collector.init
 
#by evan
 
  
# Tomcat  start/stop/status script
+
for info in ${redis_list[@]}
# Forked from: https://gist.github.com/valotas/1000094
 
# @author: Miglen Evlogiev <[email protected]>
 
#
 
# Release updates:
 
# Updated method for gathering pid of the current proccess
 
# Added usage of CATALINA_BASE
 
# Added coloring and additional status
 
# Added check for existence of the tomcat user
 
#
 
 
#Location of JAVA_HOME (bin files)
 
export JAVA_HOME=/usr/java/jdk1.8.0_121/
 
 
#Add Java binary files to PATH
 
export PATH=$JAVA_HOME/bin:$PATH
 
 
#CATALINA_HOME is the location of the bin files of Tomcat 
 
export CATALINA_HOME=/data/pp-col/
 
 
#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
 
export CATALINA_BASE=/data/pp-col/
 
 
#TOMCAT_USER is the default user of tomcat
 
export TOMCAT_USER=root
 
 
#TOMCAT_USAGE is the message if this script is called without any options
 
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"
 
 
#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
 
SHUTDOWN_WAIT=3
 
 
tomcat_pid() {
 
        echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2`
 
}
 
 
start() {
 
  pid=$(tomcat_pid)
 
  if [ -n "$pid" ]
 
  then
 
    echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
 
  else
 
    # Start tomcat
 
    echo -e "\e[00;32mStarting tomcat\e[00m"
 
    #ulimit -n 100000
 
    #umask 007
 
    #/bin/su -p -s /bin/sh tomcat
 
        if [ `user_exists $TOMCAT_USER` = "1" ]
 
        then
 
                su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
 
        else
 
                sh $CATALINA_HOME/bin/startup.sh
 
        fi
 
        status
 
  fi
 
  return 0
 
}
 
 
status(){
 
          pid=$(tomcat_pid)
 
          if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
 
          else echo -e "\e[00;31mTomcat is not running\e[00m"
 
          fi
 
}
 
 
stop() {
 
  pid=$(tomcat_pid)
 
  if [ -n "$pid" ]
 
  then
 
    echo -e "\e[00;31mStoping Tomcat\e[00m"
 
    #/bin/su -p -s /bin/sh tomcat
 
        sh $CATALINA_HOME/bin/shutdown.sh
 
 
    let kwait=$SHUTDOWN_WAIT
 
    count=0;
 
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
 
 
     do
 
     do
      echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
+
        echo "开始执行:$info"
      sleep 1
+
        ip=`echo $info | cut -d : -f 1`
      let count=$count+1;
+
         port=`echo $info | cut -d : -f 2`
    done
 
 
    if [ $count -gt $kwait ]; then
 
      echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
 
      kill -9 $pid
 
    fi
 
  else
 
    echo -e "\e[00;31mTomcat is not running\e[00m"
 
  fi
 
 
  return 0
 
}
 
 
user_exists(){
 
        if id -u $1 >/dev/null 2>&1; then
 
         echo "1"
 
        else
 
                echo "0"
 
        fi
 
}
 
 
case $1 in
 
 
        start)
 
          start
 
        ;;
 
     
 
        stop) 
 
          stop
 
        ;;
 
     
 
        restart)
 
          stop
 
          start
 
        ;;
 
     
 
        status)
 
                status
 
             
 
        ;;
 
     
 
        *)
 
                echo -e $TOMCAT_USAGE
 
        ;;
 
esac   
 
exit 0
 
  
</pre>
+
      for  loop in  `cat key.txt`
 +
        do
 +
        #echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c del
 +
        echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c keys
 +
        done
  
<pre>[root@node2 tomcat]# vim /etc/init.d/tomcat(tomcat启动脚本)
+
    done
 +
    echo "success done完成"
  
------------script start--------------
+
# cat key.txt
 +
infnce:wonderfulCache
 +
ext_info
  
#!/bin/sh
 
  
# Tomcat init script for Linux.
 
  
#
+
#原来的版本
  
# chkconfig: 2345 96 14
+
del hello_user_*
  
# description: The Apache Tomcatservlet/JSP container.
+
redis-cli keys
  
export JAVA_HOME=/usr/java/latest
 
  
export CATALINA_HOME=/usr/local/tomcat
+
redis-cli keys "hello_user_*" | xargs redis-cli del
  
exec $CATALINA_HOME/bin/catalina.sh $*
 
  
--------------script end---------------
+
./redis-cli -h IP -p PORT -a PASSWORD keys 'key*' | xargs  ./redis-cli -h IP  -p PORT -a PASSWORD del
  
[root@node2 tomcat]# chmod +x !$
+
redis-cli    -c  -h    172.31.22.218  -p 7000  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218  -p 7000  -a pass  del {}
 +
redis-cli    -c  -h    172.31.22.218  -p 7001  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218  -p 7001  -a pass  del {}
  
chmod +x /etc/init.d/tomcat
+
redis-cli    -c  -h    172.31.16.135  -p 7002  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.16.135  -p 7002 -a pass  del {}
 +
redis-cli    -c  -h    172.31.16.135  -p 7003  -a pass keys 'hello_user_*'| xargs  -i redis-cli    -c  -h    172.31.16.135  -p 7003 -a pass  del {}
  
[root@node2 tomcat]# chkconfig --add tomcat
+
redis-cli    -c  -h    172.31.23.43  -p 7004  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43  -p 7004 -a pass  del {}
 +
redis-cli    -c  -h    172.31.23.43  -p 7005  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43  -p 7005 -a pass  del {}
  
[root@node2 tomcat]# chkconfig tomcat on
 
  
[root@node2 tomcat]# chkconfig --list tomcat
 
  
tomcat            0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭
+
#!/bin/bash
 +
redis_comm=/usr/local/redis-5.0.3/bin/redis-cli
 +
redis_ser01=192.168.50.175
 +
redis_ser02=192.168.50.174
 +
$redis_comm -c -h $redis_ser01  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser01  -p 7001 -a xxx del {}
 +
$redis_comm -c -h $redis_ser02  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser02  -p 7001 -a xxx del {}
  
[root@node2 tomcat]# service tomcat stop
+
运行:
  
……
+
./redis_del_key.sh  匹配的key*
  
[root@node2 tomcat]# service tomcat start</pre>
+
err 
  
=safe=
+
-i  {} 都是一定要的
[https://blog.linuxeye.cn/454.html fail2ban阻止SSH暴力破解]
 
  
== safe dns==
+
redis-cli -n 0 keys "test*" | xargs redis-cli -n 0 del
http://www.freenom.world/zh/index.html?lang=zh
+
(error) CROSSSLOT Keys in request don't hash to the same slot
  
Freenom是世界上第一个也是唯一的免费域名提供商。 我们的使命是把互联网带给世界人民,帮助各国发展自己的数字经济。
+
</pre>
 
 
通过打破壁垒、整合免费域名与最新网站建设和托管技术,Freenom让企业或个人建立网站和管理内容很容易,没有任何成本。
 
 
 
=docker k8s=
 
 
 
=intra=
 
==内网穿透打洞==
 
[[内网穿透打洞]]
 
 
 
==内网环境==
 
oracle 17
 
 
 
nginx  other 11
 
 
 
frp
 
 
 
但是没有开机自启动呢
 
 
 
=apps=
 
==7.1redis==
 
公司的redis要 HA
 
 
 
[https://my.oschina.net/u/2600078/blog/1923696 redis架构演变与redis-cluster群集读写方案 ]
 
 
 
==7.2 nginx==
 
  
redis  lua+ cc
+
=see also=
[[Nginx Lua Redis防止CC攻击]]
 
  
==7.3 mysql==
 
mysql gpt
 
  
==7.4 dns==
+
[https://blog.csdn.net/yangyangye/article/details/100523387  redis集群批量删除模糊key shell脚本]
[http://blog.51cto.com/sweetpotato/1596973 Linux运维实战之DNS基础]
 
  
==7.5 CI jenkins==
+
[https://www.cnblogs.com/feng0520/p/11067025.html  redis cluster集群批量删除中的key]
  
==备份==
+
[https://my.oschina.net/u/1255588/blog/1563672 Redis集群批量删除key]
==关键文件备份==
 
passwd  etc
 
  
== 更新==
+
[https://blog.csdn.net/zj20142213/article/details/80879744 redis集群批量删除指定的key]
 
mysql 文件 这个尽量做成自动化
 
接下何焱的活
 
==db备份==
 
  
=on  =
+
https://blog.csdn.net/qq_36090419/article/details/80537684
# 内网开发环境
 
# jenkins 自动化更新 (dev test)
 
# zabbix 报警
 
# pinpoint
 
#
 
#
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
#
 
# 有序列表项
 
# 有序列表项
 

2020年6月22日 (一) 11:37的版本


Redis-bigkeys

redis cluster 批量删除key

#June 19 2020   有空结果一下原来的版本再优化一下 
cat redis_del_key.sh
#!/bin/bash
# Usage 
#redis_list=("host:post" "host:post")

redis_list=( "172.16.200.12:7003" "172.16.200.7:7004" "172.16.200.7:7005" "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=( "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=("172.16.200.7:7004")
password="3636password"

for info in ${redis_list[@]}
    do
        echo "开始执行:$info"  
        ip=`echo $info | cut -d : -f 1`
        port=`echo $info | cut -d : -f 2`

      for  loop in  `cat key.txt`
         do
         #echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c del
         echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c keys 
         done

    done
    echo "success done完成"

# cat key.txt 
infnce:wonderfulCache
ext_info



#原来的版本

del hello_user_* 

redis-cli keys


 redis-cli keys "hello_user_*" | xargs redis-cli del


./redis-cli -h IP -p PORT -a PASSWORD keys 'key*' | xargs  ./redis-cli -h IP  -p PORT -a PASSWORD del

redis-cli    -c  -h    172.31.22.218   -p 7000  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218   -p 7000  -a pass  del {}
redis-cli    -c  -h    172.31.22.218   -p 7001  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218   -p 7001  -a pass  del {}

redis-cli    -c  -h    172.31.16.135  -p 7002  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.16.135   -p 7002 -a pass  del {}
redis-cli    -c  -h    172.31.16.135  -p 7003  -a pass keys 'hello_user_*'| xargs  -i redis-cli    -c  -h    172.31.16.135   -p 7003 -a pass  del {}

redis-cli    -c  -h     172.31.23.43   -p 7004  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43   -p 7004 -a pass  del {}
redis-cli    -c  -h     172.31.23.43   -p 7005  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43   -p 7005 -a pass  del {}



#!/bin/bash
redis_comm=/usr/local/redis-5.0.3/bin/redis-cli
redis_ser01=192.168.50.175
redis_ser02=192.168.50.174
$redis_comm -c -h $redis_ser01  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser01  -p 7001 -a xxx del {}
$redis_comm -c -h $redis_ser02  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser02  -p 7001 -a xxx del {}

运行:

./redis_del_key.sh  匹配的key*

err  

-i  {} 都是一定要的 

redis-cli -n 0 keys "test*" | xargs redis-cli -n 0 del
(error) CROSSSLOT Keys in request don't hash to the same slot

see also

redis集群批量删除模糊key shell脚本

redis cluster集群批量删除中的key

Redis集群批量删除key

redis集群批量删除指定的key

https://blog.csdn.net/qq_36090419/article/details/80537684