├── 结构化命令 ├── 嵌套if.sh ├── 解决读取列表中的复杂值.sh ├── 在for语句中使用多个变量.sh ├── 读取列表中的值.sh ├── 使用C语言风格的for命令.sh ├── 使用while.sh ├── 字符串比较.sh ├── 使用双引号圈起用空格分隔的字符串.sh ├── 使用双方括号.sh ├── 读取里表中复杂的值.sh ├── 使用双圆括号.sh ├── 两个for嵌套循环.sh ├── 使用while多个测试命令.sh ├── 使用符合条件测试.sh ├── 检查目录.sh ├── 正确使用大于小于号.sh ├── if-then语句.sh ├── 从变量读取列表.sh ├── 在then块中使用多条命令.sh ├── 使用continue命令.sh ├── 使用嵌套循环并修改IFS.sh ├── 使用通配符处理目录.sh ├── if-then-else语句.sh ├── 使用break跳出外部循环.sh ├── 使用test进行数值比较.sh ├── bash-shell无法处理浮点数.sh ├── 从命令读取值.sh ├── 错误的使用大于小于号.sh ├── 使用until命令.sh ├── 注意test大小写顺序和sort不同.sh ├── continue退出多层循环.sh ├── while里面嵌套for循环.sh ├── 使用case语句.sh ├── 使用elif.sh ├── 使用管道或重定向.sh ├── output.txt ├── 判断字符串长度是否为零.sh └── 检查文件或目录是否存在.sh ├── gawk进阶 ├── test ├── script ├── gawk脚本 ├── 调用函数库和脚本.sh ├── gawk函数库 ├── 自定义函数.sh ├── 使用模式,结构化命令.sh ├── 使用变量.sh └── 输出.sh ├── 理解输入和输出 ├── test1 ├── 测试.txt ├── 快速清除文件或日志.sh ├── test ├── 临时重定向.sh ├── 创建自己的重定向 │ ├── 创建读写文件描述符.sh │ ├── 创建输出文件描述符.sh │ ├── 从以重定向的文件描述符中恢复.sh │ ├── 关闭文件描述符.sh │ └── 创建输入文件描述符.sh ├── 列出当前脚本打开的文件描述符.sh ├── 在脚本中使用重定向输入.sh ├── 在tmp目录创建临时文件.sh ├── 记录信息.sh ├── 永久重定向.sh ├── 创建临时目录.sh └── 创建本地临时文件.sh ├── 初识sed和gawk ├── script ├── gawk.sh ├── sed文件操作.sh └── sed编辑器基础.sh ├── sed进阶 ├── 给文件中的行编号.sh ├── 在脚本中使用sed.sh ├── 排除命令.sh ├── 输出末尾指定行数的数据.sh ├── 测试.sh ├── test ├── 保持空间.sh ├── 跳转.sh ├── 删除指定的空白行和删除html标签.sh ├── 模式替代.sh └── 重定向sed输出.sh ├── README.md ├── 控制脚本 ├── 定时执行脚本.sh ├── 捕捉脚本的退出.sh ├── 移除捕捉.sh └── 捕捉信号.sh ├── shell脚本编程进阶 ├── 查看僵尸进程.sh ├── 查看uptime获取在线用户数.sh ├── 查看磁盘使用百分比.sh ├── 查看内存使用百分比.sh ├── 创建捕捉脚本.sh ├── 问题跟踪数据库 │ ├── 查找问题.sh │ ├── 记录问题.sh │ └── Update_Problem.sh ├── 生成报告脚本-基于创建捕捉脚本.sh └── 系统快照报告.sh ├── 图形化桌面的脚本编程 ├── 使用msgbox部件.sh ├── 使用select命令.sh ├── 使用脚本菜单.sh └── 在脚本中使用dialog命令.sh ├── Docker安装脚本 ├── seata │ ├── config │ │ └── resources │ │ │ ├── META-INF │ │ │ ├── services │ │ │ │ ├── io.seata.core.rpc.RegisterCheckAuthHandler │ │ │ │ ├── io.seata.core.store.DistributedLocker │ │ │ │ ├── io.seata.core.store.db.DataSourceProvider │ │ │ │ ├── io.seata.server.lock.LockManager │ │ │ │ ├── io.seata.server.coordinator.AbstractCore │ │ │ │ └── io.seata.server.session.SessionManager │ │ │ ├── spring.factories │ │ │ ├── native-image │ │ │ │ └── io.seata │ │ │ │ │ └── server │ │ │ │ │ └── resource-config.json │ │ │ └── spring-configuration-metadata.json │ │ │ ├── banner.txt │ │ │ ├── README-zh.md │ │ │ ├── logback │ │ │ ├── console-appender.xml │ │ │ ├── kafka-appender.xml │ │ │ ├── logstash-appender.xml │ │ │ └── file-appender.xml │ │ │ ├── README.md │ │ │ ├── lua │ │ │ └── redislocker │ │ │ │ └── redislock.lua │ │ │ ├── application.yml │ │ │ ├── logback-spring.xml │ │ │ └── application.example.yml │ └── start.sh ├── nginx │ ├── conf │ │ ├── modules │ │ │ ├── ngx_http_js_module.so │ │ │ ├── ngx_http_geoip_module.so │ │ │ ├── ngx_stream_js_module.so │ │ │ ├── ngx_http_js_module-debug.so │ │ │ ├── ngx_stream_geoip_module.so │ │ │ ├── ngx_http_geoip_module-debug.so │ │ │ ├── ngx_http_xslt_filter_module.so │ │ │ ├── ngx_stream_js_module-debug.so │ │ │ ├── ngx_http_image_filter_module.so │ │ │ ├── ngx_stream_geoip_module-debug.so │ │ │ ├── ngx_http_image_filter_module-debug.so │ │ │ └── ngx_http_xslt_filter_module-debug.so │ │ ├── conf.d │ │ │ ├── prod_80.conf │ │ │ ├── static_ssl_443.conf │ │ │ └── prod_ssl_443.conf │ │ ├── scgi_params │ │ ├── uwsgi_params │ │ ├── fastcgi_params │ │ ├── nginx.conf │ │ ├── koi-win │ │ ├── koi-utf │ │ ├── win-utf │ │ └── mime.types │ ├── html │ │ └── crossdomain.xml │ ├── start.sh │ └── logs │ │ └── error.log ├── xxFileView │ ├── restart.sh │ └── application.properties ├── mysql8 │ ├── start.sh │ └── conf │ │ └── my.cnf ├── redis │ └── start.sh ├── mssql │ └── start.sh ├── MinIo │ └── run.sh ├── rabbitmq │ └── start.sh └── nacos │ ├── start.sh │ └── init.d │ └── custom.properties ├── 基本脚本 ├── 反引号的使用.sh ├── 在脚本中使用bc.sh ├── 使用方括号执行数学运算.sh ├── 通过反引号获得当前日期并生成唯一文件名.sh ├── 使用expr执行数学运算.sh ├── exit命令.sh ├── 使用自定义变量.sh ├── 显示系统变量和转义字符.sh ├── 显示时间和登录者.sh └── 使用内联重定向计算表达式.sh ├── 自动化下载脚本.sh ├── 正则表达式 ├── 邮件验证.sh └── 目录文件计数.sh ├── 脚本函数 ├── 使用库函数.sh ├── 使用函数输出.sh ├── 全局变量.sh ├── 使用return命令.sh ├── 脚本库.sh ├── 使用命令行中传递的参数.sh ├── 基本的脚本函数.sh ├── 函数递归.sh ├── 使用局部变量.sh ├── 使用全局变量带来的问题.sh ├── 累加数组中的值.sh ├── 想函数传数组数据.sh ├── 从函数返回数组.sh ├── 在函数中使用参数.sh └── 默认退出状态码.sh ├── new.sh ├── 处理用户输入 ├── 读取多个命令行参数.sh ├── 隐藏方式读取数据.sh ├── 读取程序名.sh ├── 从文件中读取数据.sh ├── 参数计数.sh ├── 读取参数.sh ├── 抓取所有数据.sh ├── 处理简单选项.sh ├── 使用getopts.sh ├── 使用shift命令.sh ├── 分离参数和选项.sh ├── 使用getopts处理选项和参数.sh ├── 超时和输入计数.sh ├── 处理带值的选项.sh ├── 使用getopt命令.sh └── 获取用户输入.sh ├── mysql数据库 ├── 连接数据库并发送命令.sh ├── 格式化输出数据.sh └── 向数据库中插入数据.sh ├── 脚本实用工具 ├── black_list.sh ├── IP_iptables.sh ├── Custom_Rm.sh ├── 当服务器线程数超过 2500 时自动 dump 线程数最高的 java 进程的内存及线程栈 ├── check_mysql_ms.sh ├── Autoback-xtraback.sh ├── 查看磁盘目录使用情况.sh ├── Cpu_Limit.sh ├── Daily_Archive.sh ├── Hourly_Archive.sh ├── install_grafana.sh ├── install_maven.sh ├── install_tomcat.sh ├── install_kibana.sh ├── install_filebeat.sh ├── install_logstash.sh ├── install_zookeeper.sh ├── install_kafka.sh ├── Autoinstall_ELK_V1.3.sh ├── install_git.sh ├── Sys_Check.sh └── 删除用户脚本.sh └── 网络限流 ├── 清除限流效果.sh └── 随机限流.sh /结构化命令/嵌套if.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | -------------------------------------------------------------------------------- /gawk进阶/test: -------------------------------------------------------------------------------- 1 | 10 2 | 5 3 | 123 4 | 50 5 | -------------------------------------------------------------------------------- /理解输入和输出/test1: -------------------------------------------------------------------------------- 1 | This is the end of the script 2 | -------------------------------------------------------------------------------- /gawk进阶/script: -------------------------------------------------------------------------------- 1 | BEGIN{FS=","; print n} 2 | {print $n} 3 | -------------------------------------------------------------------------------- /初识sed和gawk/script: -------------------------------------------------------------------------------- 1 | { print $1 "'s home directory is " $6 } 2 | 3 | -------------------------------------------------------------------------------- /sed进阶/给文件中的行编号.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed '=' test | sed 'N; s/\n/ /' 4 | -------------------------------------------------------------------------------- /理解输入和输出/测试.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/理解输入和输出/测试.txt -------------------------------------------------------------------------------- /gawk进阶/gawk脚本: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BEGIN{FS="\n"; RS=""} 4 | { 5 | myprint() 6 | } 7 | -------------------------------------------------------------------------------- /理解输入和输出/快速清除文件或日志.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 清除日志 4 | 5 | cat /dev/null > [Logname] 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # shell 2 | 大部分案例均出自《Linux命令行与shell脚本编程大全案例》一书,方便各位小伙伴学习,欢迎各位同学共同扩充shell脚本库!!!! 3 | -------------------------------------------------------------------------------- /控制脚本/定时执行脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # testing the at command 4 | 5 | at -f 4.sh 22:10 6 | -------------------------------------------------------------------------------- /gawk进阶/调用函数库和脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #使用函数库和gawk脚本 4 | 5 | gawk -f gawk函数库 -f gawk脚本 test 6 | -------------------------------------------------------------------------------- /shell脚本编程进阶/查看僵尸进程.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #查看僵尸进程 4 | ps -al | gawk '{print $2,$4}' | grep Z 5 | -------------------------------------------------------------------------------- /图形化桌面的脚本编程/使用msgbox部件.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dialog --title text --msgbox "This is a test" 10 20 4 | -------------------------------------------------------------------------------- /shell脚本编程进阶/查看uptime获取在线用户数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | uptime | sed 's/user.*$//' | gawk '{print $NF}' 4 | -------------------------------------------------------------------------------- /理解输入和输出/test: -------------------------------------------------------------------------------- 1 | ls: cannot access badtest: No such file or directory 2 | but this should go to the testerror file 3 | -------------------------------------------------------------------------------- /shell脚本编程进阶/查看磁盘使用百分比.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #查看磁盘实用百分比 4 | df -h /dev/sda1 | sed -n '/% \//p' | gawk '{ print $5 }' 5 | -------------------------------------------------------------------------------- /结构化命令/解决读取列表中的复杂值.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for test in I don\'t know if "this'll" work 4 | do 5 | echo "word:$test" 6 | done 7 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/services/io.seata.core.rpc.RegisterCheckAuthHandler: -------------------------------------------------------------------------------- 1 | io.seata.server.auth.DefaultCheckAuthHandler -------------------------------------------------------------------------------- /sed进阶/在脚本中使用sed.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # shell wrapper for sed editor script to reverse lines 3 | 4 | sed -n '{ 5 | 1!G 6 | h 7 | $p 8 | }' $1 9 | -------------------------------------------------------------------------------- /sed进阶/排除命令.sh: -------------------------------------------------------------------------------- 1 | !/bin/bash 2 | 3 | #排除命令,使本来起作用的命令不起作用 4 | 5 | sed -n '/heade/!p' test 6 | 7 | #反转文本文件 8 | sed -n '{1!G ; h; $p}' test 9 | -------------------------------------------------------------------------------- /sed进阶/输出末尾指定行数的数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #输出末尾10行数据 3 | 4 | sed '{ 5 | :start 6 | $q 7 | N 8 | 11,$D 9 | b start 10 | }' /etc/passwd 11 | -------------------------------------------------------------------------------- /shell脚本编程进阶/查看内存使用百分比.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #查看内存使用百分比 4 | free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/' 5 | -------------------------------------------------------------------------------- /基本脚本/反引号的使用.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #using the backtick character 会把反引号里面当作一条命令来执行 3 | 4 | testing=`date` 5 | echo "The date and time are:$testing" 6 | -------------------------------------------------------------------------------- /基本脚本/在脚本中使用bc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | var1=100 3 | var2=45 4 | var3=`echo "scale=4; $var1 / $var2" | bc` 5 | echo The answer for this is $var3 6 | 7 | -------------------------------------------------------------------------------- /结构化命令/在for语句中使用多个变量.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # multiple variables 3 | 4 | for (( a=1, b=10; a<=10; a++,b-- )) 5 | do 6 | echo "$a - $b" 7 | done 8 | -------------------------------------------------------------------------------- /自动化下载脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #download latest cURL file automatically 3 | 4 | curl -s -o /home/tiandi/curl 5 | http://curl.haxx.se/download/curl 6 | -------------------------------------------------------------------------------- /基本脚本/使用方括号执行数学运算.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | var1=10 4 | var2=50 5 | var3=45 6 | var4=$[$var1 * ($var2 - $var3)] 7 | echo 'The final result is '$var4 8 | -------------------------------------------------------------------------------- /结构化命令/读取列表中的值.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # basic for command 4 | for test in Alabama Alaska Arizona 5 | do 6 | echo The next state is $test 7 | done 8 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_js_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_js_module.so -------------------------------------------------------------------------------- /sed进阶/测试.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #测试,如果测试成功,如果没有标签,sed会跳转到结尾,如果有标签,就跳转到标签,如果测试失败,则不会跳转 4 | sed -n '{s/first/matched/; t; s/This is the/No match on/}' test 5 | -------------------------------------------------------------------------------- /正则表达式/邮件验证.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #验证邮件 4 | 5 | gawk --re-interval '/^([a-zA-Z0-9_\-\.\+]+)@([a-zA-Z0-9_\-\+]+)\.([a-zA-Z]{2,5})/{print $0}' 6 | 7 | 8 | -------------------------------------------------------------------------------- /结构化命令/使用C语言风格的for命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing the C-style for loop 3 | 4 | for (( i=1; i<=10; i++ )) 5 | do 6 | echo "The next number is $i" 7 | done 8 | -------------------------------------------------------------------------------- /脚本函数/使用库函数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #using a library file the wrong way 4 | 5 | . ./脚本库.sh 6 | 7 | result=`addem 10 15` 8 | echo "The result is $result" 9 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_geoip_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_geoip_module.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_stream_js_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_stream_js_module.so -------------------------------------------------------------------------------- /sed进阶/test: -------------------------------------------------------------------------------- 1 | This is the header line 2 | This is the first data line 3 | This is the data line 4 | This is the second data line 5 | line This is the last line 6 | -------------------------------------------------------------------------------- /基本脚本/通过反引号获得当前日期并生成唯一文件名.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #copy the /usr/bin directory listing to a log file 3 | 4 | today=`date +%y%m%d` 5 | ls /usr/bin -al > log.$today 6 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_js_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_js_module-debug.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_stream_geoip_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_stream_geoip_module.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_geoip_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_geoip_module-debug.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_xslt_filter_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_xslt_filter_module.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_stream_js_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_stream_js_module-debug.so -------------------------------------------------------------------------------- /new.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #创建4个sh 4 | 5 | for (( i=1; i<=4; i++)) 6 | do 7 | touch $i.sh 8 | echo '#!/bin/bash' > $i.sh 9 | chmod 764 $i.sh 10 | done 11 | -------------------------------------------------------------------------------- /基本脚本/使用expr执行数学运算.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #An example of using the expr command 3 | 4 | var1=10 5 | var2=20 6 | var3=`expr $var2 / $var1` 7 | echo "The result is $var3" 8 | 9 | -------------------------------------------------------------------------------- /理解输入和输出/临时重定向.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing STDERR messages 3 | 4 | echo "This is an error " >&2 5 | echo "This is another error" 6 | echo "This is also an error" >&2 7 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_image_filter_module.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_image_filter_module.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_stream_geoip_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_stream_geoip_module-debug.so -------------------------------------------------------------------------------- /结构化命令/使用while.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # while command test 4 | var1=10 5 | while [ $var1 -gt 0 ] 6 | do 7 | echo $var1 8 | var1=$[ $var1 - 1 ] 9 | done 10 | 11 | -------------------------------------------------------------------------------- /结构化命令/字符串比较.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing string equality 3 | 4 | testuser=tiandi 5 | 6 | if [ $USER = $testuser ] 7 | then 8 | echo "Welcome $testuser" 9 | fi 10 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_image_filter_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_image_filter_module-debug.so -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/modules/ngx_http_xslt_filter_module-debug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuhetao/shell/HEAD/Docker安装脚本/nginx/conf/modules/ngx_http_xslt_filter_module-debug.so -------------------------------------------------------------------------------- /结构化命令/使用双引号圈起用空格分隔的字符串.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # another example of how not to use the for command 3 | 4 | for test in Newada "New Hampshire" 5 | do 6 | echo "Now going to $test" 7 | done 8 | -------------------------------------------------------------------------------- /结构化命令/使用双方括号.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # using pattern matching 3 | 4 | if [[ $USER == r* ]] 5 | then 6 | echo "Hello $USER" 7 | else 8 | echo "Sorry, I do not know you" 9 | fi 10 | -------------------------------------------------------------------------------- /结构化命令/读取里表中复杂的值.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # another example of how not to use the for command 4 | 5 | for test in I don't know if this'll work 6 | do 7 | echo "word:$test" 8 | done 9 | -------------------------------------------------------------------------------- /基本脚本/exit命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #退出状态码,最大为255,超过则进行模运算 3 | #testing the exit status 4 | var1=10 5 | var2=20 6 | var3=$[ $var1 + $var2] 7 | echo The answer is $var3 8 | exit 5 9 | 10 | -------------------------------------------------------------------------------- /理解输入和输出/创建自己的重定向/创建读写文件描述符.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing inpiut/output file descriptor 3 | 4 | exec 3<> test 5 | read line <&3 6 | echo "Read: $line" 7 | echo "This is the test line" >&3 8 | -------------------------------------------------------------------------------- /gawk进阶/gawk函数库: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function myprint() 4 | { 5 | printf "%-16s - %s", $1, $4 6 | } 7 | 8 | function myrand(limit) 9 | { 10 | return int(limit * rand()) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/services/io.seata.core.store.DistributedLocker: -------------------------------------------------------------------------------- 1 | io.seata.server.storage.redis.lock.RedisDistributedLocker 2 | io.seata.server.storage.db.lock.DataBaseDistributedLocker -------------------------------------------------------------------------------- /gawk进阶/自定义函数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #gawk 自定义函数 3 | 4 | gawk ' 5 | function myprint() 6 | { 7 | printf "%-16s - %s\n", $1, $4 8 | } 9 | BEGIN{FS="\n"; RS=""} 10 | { 11 | myprint() 12 | }' test 13 | -------------------------------------------------------------------------------- /基本脚本/使用自定义变量.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing variables 3 | 4 | days=10 5 | guest="Katie" 6 | echo "$guest logged in $days days age" 7 | guest="Katie2" 8 | days=5 9 | echo "$guest logged in $days days age" 10 | -------------------------------------------------------------------------------- /处理用户输入/读取多个命令行参数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # handing lots of parameters 4 | 5 | total=$[ ${10} * ${11} ] 6 | echo The tenth parameter is ${10} 7 | echo The eleventh parameter is ${11} 8 | echo The total is $total 9 | -------------------------------------------------------------------------------- /处理用户输入/隐藏方式读取数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # hiding input data from monitor 3 | 4 | read -s -p "Please enter your password: " pass 5 | 6 | #添加了-s选项之后,不会自动换行,不添加-s 会自动换行 7 | echo 8 | echo "Is your password really $pass?" 9 | -------------------------------------------------------------------------------- /理解输入和输出/列出当前脚本打开的文件描述符.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # testing lsof with file descriptors 4 | 5 | exec 3>test 6 | exec 6>test 7 | exec 7 90)) 7 | then 8 | (( var2 = $var1 ** 2)) 9 | echo "The square of $var1 if $var2" 10 | fi 11 | 12 | -------------------------------------------------------------------------------- /sed进阶/保持空间.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #h将模式空间保存到保持空间 4 | #H将模式空间附加到保持空间 5 | #g将保持空间复制到模式空间 6 | #G将保持空间保存到模式空间 7 | #x交换模式空间和保持空间的内容 8 | 9 | sed -n '/first/{ 10 | h 11 | p 12 | n 13 | p 14 | g 15 | p 16 | }' test 17 | -------------------------------------------------------------------------------- /结构化命令/两个for嵌套循环.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #nesting for loops 3 | 4 | for (( a=1; a<=3; a++ )) 5 | do 6 | echo "Starting loop $a:" 7 | for (( b=1; b<=3; b++)) 8 | do 9 | echo "Inside loog: $b:" 10 | done 11 | done 12 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/conf.d/prod_80.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name tangyh.top; 4 | underscores_in_headers on; 5 | 6 | rewrite ^(.*)$ https://$host$1 permanent; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /sed进阶/跳转.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #跳转到指定脚本 4 | sed '{/first/b jump1; s/This is the/No jump on/; :jump1; s/This is the/Jump here on/}' test 5 | 6 | #跳转到开头,删除每一个逗号,并保证删除最后一个逗号之后,跳出循环 7 | sed -n '{:start; s/,//1p; /,/b start}' test 8 | -------------------------------------------------------------------------------- /处理用户输入/读取程序名.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing the $0 parameter 3 | 4 | echo The command entered is $0 5 | 6 | #当传给$0变量的真实字符串是整个脚本的路径是,程序中就会使用整个路径,而不仅仅是程序名 7 | 8 | name=`basename $0` 9 | echo The command entered is $name 10 | -------------------------------------------------------------------------------- /结构化命令/使用while多个测试命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #testing a multicommand while loop 4 | 5 | var1=10 6 | while echo $var1 7 | [ $var1 -ge 0 ] 8 | do 9 | echo 'This is inside the loop' 10 | var1=$[ $var1 - 1 ] 11 | done 12 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/services/io.seata.core.store.db.DataSourceProvider: -------------------------------------------------------------------------------- 1 | io.seata.server.store.DbcpDataSourceProvider 2 | io.seata.server.store.DruidDataSourceProvider 3 | io.seata.server.store.HikariDataSourceProvider -------------------------------------------------------------------------------- /结构化命令/使用符合条件测试.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing compound comparisons 3 | 4 | if [ -d $HOME ] && [ -w $HOME/testing ] 5 | then 6 | echo "The file exists and you can write to it" 7 | else 8 | echo "I cannot write to it" 9 | fi 10 | -------------------------------------------------------------------------------- /结构化命令/检查目录.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # look before you leap 3 | 4 | if [ -d $HOME ] 5 | then 6 | echo "Your home directory exists" 7 | cd $HOME 8 | ls -a 9 | else 10 | echo "There is a problem with your HOME direcotry" 11 | fi 12 | -------------------------------------------------------------------------------- /结构化命令/正确使用大于小于号.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #正确使用大于小于号 3 | 4 | val1=baseball 5 | val2=hocky 6 | 7 | if [ $val1 \> $val2 ] 8 | then 9 | echo "$val1 is greater than $val2" 10 | else 11 | echo "$val1 is less than $val2" 12 | fi 13 | -------------------------------------------------------------------------------- /脚本函数/使用函数输出.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # using the echo to return a value 3 | 4 | function db1 { 5 | read -p "Enter a value:" value 6 | echo $[ $value*2 ] 7 | } 8 | 9 | result=`db1` 10 | echo "The new value is $result" 11 | 12 | -------------------------------------------------------------------------------- /控制脚本/捕捉脚本的退出.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # trapping the script exit 4 | 5 | trap "echo byebye" EXIT 6 | 7 | count=1 8 | while [ $count -le 5 ] 9 | do 10 | echo "Loop #$count" 11 | sleep 3 12 | count=$[ $count + 1 ] 13 | done 14 | -------------------------------------------------------------------------------- /结构化命令/if-then语句.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing the if statement 3 | if date 4 | then 5 | echo "it worked" 6 | fi 7 | echo -e '\n' 8 | if asd 9 | then 10 | echo "it not worked" 11 | fi 12 | echo 'We are outside the if statement' 13 | -------------------------------------------------------------------------------- /结构化命令/从变量读取列表.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # using a variable to hold the list 3 | 4 | list="Alabama Alaska Arizona" 5 | list=$list" Connecticut" 6 | 7 | for state in $list 8 | do 9 | echo "Have you ever visited $state" 10 | done 11 | 12 | -------------------------------------------------------------------------------- /结构化命令/在then块中使用多条命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing multiple commands in the then section 3 | testuser=tiandi 4 | if grep $testuser /etc/passwd 5 | then 6 | echo The bash files from user $testuser are: 7 | ls -a /home/$testuser/.b* 8 | fi 9 | -------------------------------------------------------------------------------- /脚本函数/全局变量.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using a global variable to pass a value 4 | 5 | function db1 { 6 | value=$[ $value * 2 ] 7 | } 8 | 9 | read -p "Enter a value: " value 10 | db1 11 | echo "The new value is : $value" 12 | 13 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/services/io.seata.server.lock.LockManager: -------------------------------------------------------------------------------- 1 | io.seata.server.storage.db.lock.DataBaseLockManager 2 | io.seata.server.storage.file.lock.FileLockManager 3 | io.seata.server.storage.redis.lock.RedisLockManager -------------------------------------------------------------------------------- /基本脚本/显示系统变量和转义字符.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #display user information from system 3 | 4 | echo "User info fro userId:$USER" 5 | echo UID:$UID 6 | echo HOME:$HOME 7 | #换行 8 | echo -e '\n' 9 | echo 'The cost of the item is \$15' 10 | 11 | -------------------------------------------------------------------------------- /处理用户输入/从文件中读取数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # reading data from a file 3 | 4 | count=1 5 | cat test | while read line 6 | do 7 | echo "Line $count: $line" 8 | count=$[ $count + 1 ] 9 | done 10 | echo "Finished processing the file" 11 | 12 | -------------------------------------------------------------------------------- /处理用户输入/参数计数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # getting the number of parameters 3 | 4 | echo There were $# parameters supplied 5 | 6 | #花括号里不能使用美元符号 7 | params=$# 8 | 9 | echo The last parameter is $params 10 | echo The last parameter is ${!#} 11 | -------------------------------------------------------------------------------- /理解输入和输出/在脚本中使用重定向输入.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # redirecting the inpiut 3 | 4 | # 从test中读取数据,而不是从STDIN中读取数据 5 | exec 0< test 6 | count=1 7 | while read line 8 | do 9 | echo "Line #$count : $line " 10 | count=$[ $count +1 ] 11 | done 12 | 13 | -------------------------------------------------------------------------------- /基本脚本/显示时间和登录者.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #This script displays the date and who's logged on 3 | 4 | #如果想在同一行显示 5 | #echo -n -e 'The time is:\n\n' 6 | echo The time is: 7 | date 8 | echo The one who has been logged is: 9 | who 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /处理用户输入/读取参数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using one command line parameter 4 | 5 | factorial=1 6 | for (( number = 1; number <= $1; number++)) 7 | do 8 | factorial=$[ $factorial * $number ] 9 | done 10 | echo The factor of $1 is $factorial 11 | -------------------------------------------------------------------------------- /mysql数据库/连接数据库并发送命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #连接数据库 4 | mysql=`which mysql 5 | ` 6 | #发送单个命令 7 | $mysql emwjs -u test -e "show databases;" 8 | 9 | #发送多个命令 10 | $mysql emwjs -u test <test 6 | 7 | echo "This should display on the monitor" 8 | echo "and this should be stored in the file" >&3 9 | echo "Then this should be back on the monitor" 10 | -------------------------------------------------------------------------------- /结构化命令/使用嵌套循环并修改IFS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #changing the IFS value 4 | 5 | IFS.OLD=$IFS 6 | IFS=$'\n' 7 | for entry in `cat /etc/passwd` 8 | do 9 | echo "Values in $entry -" 10 | IFS=: 11 | for value in $entry 12 | do 13 | echo " $value" 14 | done 15 | done 16 | -------------------------------------------------------------------------------- /结构化命令/使用通配符处理目录.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #iterate through all the files in a directory 3 | for file in /home/tiandi/test/* 4 | do 5 | if [ -d "$file" ] 6 | then 7 | echo "$file is a directory" 8 | elif [ -f "$file" ] 9 | then 10 | echo "$file is a file" 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.context.ApplicationListener=\ 2 | io.seata.server.spring.listener.ServerApplicationListener 3 | org.springframework.context.ApplicationContextInitializer=\ 4 | io.seata.server.spring.listener.SeataPropertiesLoader -------------------------------------------------------------------------------- /结构化命令/if-then-else语句.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #testing the else section 3 | testuser=badtest 4 | if grep $testuser /etc/passwd 5 | then 6 | echo The files for user $testuser are: 7 | ls -a /home/.b* 8 | else 9 | echo "The user name $testuser does not exist on this system" 10 | fi 11 | -------------------------------------------------------------------------------- /控制脚本/移除捕捉.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # removeing a set trap 4 | 5 | trap "echo byebye" EXIT 6 | 7 | count=1 8 | while [ $count -le 5 ] 9 | do 10 | echo "Loop #$count" 11 | sleep 3 12 | count=$[ $count + 1 ] 13 | done 14 | #移除捕捉 15 | trap - EXIT 16 | echo "I just removed the trap" 17 | -------------------------------------------------------------------------------- /结构化命令/使用break跳出外部循环.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # break n,默认为1 3 | 4 | for (( a=1; a<=3; a++ )) 5 | do 6 | echo "Outer loop : $a" 7 | for (( b=1; b < 100; b++ )) 8 | do 9 | if [ $b -gt 4 ] 10 | then 11 | break 2 12 | fi 13 | echo " Inner loop:$b" 14 | done 15 | done 16 | 17 | -------------------------------------------------------------------------------- /结构化命令/使用test进行数值比较.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | var1=10 3 | var2=5 4 | if [ $var1 -gt 5 ] 5 | then 6 | echo "The test value $var1 is greater than 5" 7 | fi 8 | if [ $var1 -eq $var2 ] 9 | then 10 | echo "The values is equal" 11 | else 12 | echo "The values are different" 13 | fi 14 | 15 | 16 | -------------------------------------------------------------------------------- /理解输入和输出/创建自己的重定向/从以重定向的文件描述符中恢复.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #storing STDOUT, then coming back to it 4 | 5 | exec 3>&1 6 | exec 1>test 7 | 8 | echo "This should store in output file" 9 | echo "along with this line" 10 | 11 | exec 1>&3 12 | 13 | echo "Now things should be back to normal" 14 | -------------------------------------------------------------------------------- /结构化命令/bash-shell无法处理浮点数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #bash shell 仅能处理浮点数值,test命令无法处理val1变量中存储的浮点值 3 | 4 | #testing floating point numbers 5 | 6 | val1=`echo "scale=4; 10 / 3" | bc` 7 | echo "The test value is $val1" 8 | if [ $val1 -gt 3 ] 9 | then 10 | echo "The result is larger than 3" 11 | fi 12 | -------------------------------------------------------------------------------- /脚本函数/脚本库.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # myscript functions 4 | 5 | function addem { 6 | echo $[ $1 + $2 ] 7 | } 8 | 9 | function multem { 10 | echo $[ $1 * $2 ] 11 | } 12 | 13 | function divem { 14 | if [ $2 -ne 0] 15 | then 16 | echo $[ $1/$2 ] 17 | else 18 | echo -1 19 | fi 20 | } 21 | -------------------------------------------------------------------------------- /控制脚本/捕捉信号.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # testing signal trapping 4 | 5 | trap "echo 'Sorry! I have trapped Ctrl-C'" SIGINT SIGTERM 6 | 7 | echo this is a test program 8 | 9 | count=1 10 | 11 | while [ $count -le 10 ] 12 | do 13 | echo "Loop #$count" 14 | sleep 5 15 | count=$[ $count+1 ] 16 | done 17 | -------------------------------------------------------------------------------- /处理用户输入/抓取所有数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing $* and $@ 3 | 4 | count=1 5 | for param in "$*" 6 | do 7 | echo "\$* Parameter #$count = $param" 8 | count=$[ $count+1 ] 9 | done 10 | 11 | count=1 12 | for param in "$@" 13 | do 14 | echo "\$@ Paramenter #$count = $param" 15 | count=$[ $count+1 ] 16 | done 17 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/html/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ███████╗███████╗ █████╗ ████████╗ █████╗ 2 | ██╔════╝██╔════╝██╔══██╗╚══██╔══╝██╔══██╗ 3 | ███████╗█████╗ ███████║ ██║ ███████║ 4 | ╚════██║██╔══╝ ██╔══██║ ██║ ██╔══██║ 5 | ███████║███████╗██║ ██║ ██║ ██║ ██║ 6 | ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ 7 | 8 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker stop lamp_seata 4 | docker rm lamp_seata 5 | 6 | docker run -d --restart always --name lamp_seata \ 7 | -p 8091:8091 -p 7091:7091 -v /mydata/seata/config/resources:/seata-server/resources \ 8 | -e SEATA_PORT=8091 -e SEATA_IP=192.168.80.130 seataio/seata-server:1.7.1 9 | -------------------------------------------------------------------------------- /理解输入和输出/在tmp目录创建临时文件.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # creating a temp file in /tmp 4 | 5 | tempfile=`mktemp -t tmp.XXXXXX` 6 | 7 | echo "This is a test file" > $tempfile 8 | echo "This is the second line of the test" >> $tempfile 9 | 10 | echo ”The temp is locate at : $tempfile“ 11 | cat $tempfile 12 | rm -f $tempfile 13 | -------------------------------------------------------------------------------- /理解输入和输出/记录信息.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using the tee command for logging 4 | #将输入一边发送到STDOUT,一边发送到日志文件 5 | tempfile=test 6 | echo "This is the start of the test" | tee $tempfile 7 | echo "This is the second line of the test" | tee -a $tempfile 8 | echo "This is the end line of the test" | tee -a $tempfile 9 | 10 | 11 | -------------------------------------------------------------------------------- /结构化命令/从命令读取值.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #reading values from a file 3 | 4 | file="state" 5 | 6 | #更改字段分隔符,使其只能识别换行符 7 | IFS=$'\n' 8 | 9 | #处理长脚本是,在一个地方修改了该值,然后可能忘了修改过该值 10 | #IFS.OLD=$IFS 11 | #IFS=$'\n' 12 | #具体代码 13 | #IFS=$IFS.OLD 14 | 15 | for state in `cat $file` 16 | do 17 | echo "Visit beautiful $state" 18 | done 19 | -------------------------------------------------------------------------------- /结构化命令/错误的使用大于小于号.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 大于小于号必须转义,否则shell会将它们当做重定向符号而把字符串值当做文件名处理 3 | # 大于小于号顺序和sort命令所采用的有所不同 4 | # mis-using string comparisons 5 | 6 | val1=baseball 7 | val2=hockey 8 | 9 | if [ $val1 > $val2 ] 10 | then 11 | echo "$val1 is greater than $val2" 12 | else 13 | echo "$val1 is less than $val2" 14 | fi 15 | -------------------------------------------------------------------------------- /脚本函数/使用命令行中传递的参数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using a global variable to pass a value 4 | 5 | function db1 { 6 | # $1和$2 不能从命令行中传递,只能调用函数时,手动传递 7 | echo $[ $1 * $2 ] 8 | } 9 | 10 | if [ $# -eq 2 ] 11 | then 12 | value=`db1 $1 $2` 13 | echo "The result is $value" 14 | else 15 | echo "Usage: badtest1 a b" 16 | fi 17 | -------------------------------------------------------------------------------- /处理用户输入/处理简单选项.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # extracting command line options as parameters 3 | 4 | while [ -n "$1" ] 5 | do 6 | case "$1" in 7 | -a) echo "Found the -a option";; 8 | -b) echo "Found the -b optins";; 9 | -c) echo "Found the -c optins";; 10 | *) echo "$1 is not a valid options";; 11 | esac 12 | shift 13 | done 14 | -------------------------------------------------------------------------------- /理解输入和输出/创建自己的重定向/关闭文件描述符.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing closing file descriptors 3 | 4 | exec 3>test 5 | echo "This is a test line of data" >&3 6 | 7 | # closing file descriptor 8 | exec 3>&- 9 | 10 | echo "This won't work" >&3 11 | 12 | cat test 13 | 14 | #覆盖前一个test文件 15 | exec 3>test 16 | echo "This'll be bad" >&3 17 | -------------------------------------------------------------------------------- /结构化命令/使用until命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #using the until command 4 | 5 | var1=100 6 | until [ $var1 -eq 0 ] 7 | do 8 | echo $var1 9 | var1=$[ $var1-25 ] 10 | done 11 | 12 | var1=100 13 | until echo $var1 14 | [ $var1 -eq 0 ] 15 | do 16 | echo Inside the loop: $var1 17 | var1=$[ $var1 - 25 ] 18 | done 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /结构化命令/注意test大小写顺序和sort不同.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #test命令中,大小字母会被当成小于小写字符,而在sort中,小写字母会先出现,test使用标准的ASCII排序,sort使用本地化语言设置进行排序,对于英语,本地化设置制定了排序顺序中小写字母出现在大写字母之前 3 | 4 | var1=Testing 5 | var2=testing 6 | 7 | if [ $val1 \> $val2 ] 8 | then 9 | echo '$val1 is greater than $val2' 10 | else 11 | echo '$val1 is less than $val2' 12 | fi 13 | -------------------------------------------------------------------------------- /处理用户输入/使用getopts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # simple demonstration of the getopts command 3 | 4 | while getopts :ab:c opt 5 | do 6 | case "$opt" in 7 | a) echo "Found the -a option";; 8 | b) echo "Found the -b option, with value $OPTARG";; 9 | c) echo "Found the -c option";; 10 | *) echo "Unknown option:$opt";; 11 | esac 12 | done 13 | -------------------------------------------------------------------------------- /初识sed和gawk/gawk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BEGIN { 4 | print "The latest list of users and shells" 5 | print "Userid Shell" 6 | print "------ -----" 7 | FS=":" 8 | } 9 | 10 | { 11 | print $1 " " $7 12 | } 13 | 14 | END { 15 | print "This concludes the listing" 16 | } 17 | 18 | #执行gawk命令截取/etc/passwd输出 19 | #gawk -f gawk.sh /etc/passwd 20 | -------------------------------------------------------------------------------- /sed进阶/删除指定的空白行和删除html标签.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #多个空格只保留一个 4 | #sed '/./,/^$/!d' test 5 | 6 | #删除开头的空白行 7 | #sed '/./,$!d' test 8 | 9 | #删除结尾的空白行 10 | sed '{ 11 | :start 12 | /^\n*$/{$d; N; b start} 13 | }' test 14 | 15 | #删除html标签 16 | #有问题 17 | #s/<.*>//g 18 | 19 | #sed 's/<[^>]*>//g' test1 20 | 21 | #sed 's/<[^>]*>//g;/^$/d' test1 22 | -------------------------------------------------------------------------------- /结构化命令/continue退出多层循环.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #continuing an outer loop 3 | 4 | for (( a=1; a<=5; a++)) 5 | do 6 | echo "Iteration $a:" 7 | for (( b=1; b<3; b++ )) 8 | do 9 | if [ $a -gt 2 ] && [ $a -lt 4 ] 10 | then 11 | continue 2 12 | fi 13 | var3=$[ $a * $b ] 14 | echo " The result of $a * $b is $var3" 15 | done 16 | done 17 | -------------------------------------------------------------------------------- /结构化命令/while里面嵌套for循环.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # placing a for loop inside a while loop 4 | 5 | var1=5 6 | 7 | while [ $var1 -ge 0 ] 8 | do 9 | echo "Outer loop: $var1" 10 | for (( var2=1; $var2 < 3; var2++)) 11 | do 12 | var3=$[ $var1*$var2] 13 | echo "Inner loop: $var1 * $var2 = $var3" 14 | done 15 | var1=$[ $var1 - 1 ] 16 | done 17 | -------------------------------------------------------------------------------- /脚本函数/基本的脚本函数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using a function in script 4 | 5 | function func1 { 6 | echo "This is an example of a function" 7 | } 8 | 9 | count=1 10 | while [ $count -le 5 ] 11 | do 12 | func1 13 | count=$[ $count+1 ] 14 | done 15 | echo "This is the end of the loop" 16 | func1 17 | echo "Now this is the end of the script" 18 | -------------------------------------------------------------------------------- /脚本函数/函数递归.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function factorial { 4 | if [ $1 -eq 1 ] 5 | then 6 | echo 1 7 | else 8 | local temp=$[ $1 -1 ] 9 | local result=`factorial $temp` 10 | echo $[ $result * $1 ] 11 | fi 12 | } 13 | 14 | read -p "Please input a value: " value 15 | result=`factorial $value` 16 | echo "The factorial of $value is: $result" 17 | -------------------------------------------------------------------------------- /处理用户输入/使用shift命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # shift n 移动变量 3 | 4 | count=1 5 | while [ -n "$1" ] 6 | do 7 | echo "Parameter #$count = $1" 8 | count=$[ $count+1 ] 9 | shift 10 | done 11 | 12 | echo -e "\n" 13 | 14 | # demonstrating a multi-position shift 15 | echo "The original parameters : $*" 16 | shift 2 17 | echo "Here's the new first parameter: $1" 18 | -------------------------------------------------------------------------------- /正则表达式/目录文件计数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # count number of files in your PATH 4 | 5 | mypath=`echo $PATH | sed 's/:/ /g'` 6 | count=0 7 | for directory in $mypath 8 | do 9 | check=`ls $directory` 10 | echo $check 11 | for item in $check 12 | do 13 | count=$(( $count + 1 )) 14 | done 15 | echo "$directory - $count" 16 | count=0 17 | done 18 | 19 | -------------------------------------------------------------------------------- /结构化命令/使用case语句.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #using the case command 4 | 5 | case $USER in 6 | tiandi | barbar) 7 | echo "Welcome, $USER" 8 | echo "Pleas enjoy your visit";; 9 | testing) 10 | echo "Special testing account";; 11 | jessica) 12 | echo "Do not forget to logout when you are out";; 13 | *) 14 | echo "Sorry, you are not allowed here";; 15 | esac 16 | -------------------------------------------------------------------------------- /初识sed和gawk/sed文件操作.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #向文件写入 4 | sed '1,2w test1' test1 5 | 6 | echo -e "next\n" 7 | 8 | #从文件读取 9 | sed '3r ./test' ./test 10 | 11 | echo -e "next\n" 12 | 13 | #从文件读取,并插入字符流 14 | sed '/lazy/r test' test 15 | 16 | #向数据流末尾添加数据 17 | sed '$r test' test 18 | 19 | echo -e "next1\n" 20 | 21 | sed '/lazy/ { 22 | r test 23 | d 24 | }' test 25 | -------------------------------------------------------------------------------- /脚本函数/使用局部变量.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # demonstrating the local keyword 4 | 5 | function func1 { 6 | local temp=$[ $value +5 ] 7 | result=$[ $temp * 2 ] 8 | } 9 | 10 | temp=4 11 | value=6 12 | 13 | func1 14 | 15 | echo "The result is $result" 16 | if [ $temp -gt $value ] 17 | then 18 | echo "temp is larger" 19 | else 20 | echo "temp is smaller" 21 | fi 22 | -------------------------------------------------------------------------------- /脚本函数/使用全局变量带来的问题.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # demonstrating a bad use of variables 4 | 5 | function func1 { 6 | temp=$[ $value + 5 ] 7 | result=$[ $temp * 2 ] 8 | } 9 | 10 | temlp=4 11 | value=6 12 | 13 | func1 14 | echo "The result is $result" 15 | 16 | if [ $temp -gt $value ] 17 | then 18 | echo "Temp is larger" 19 | else 20 | echo "temp is smaller" 21 | fi 22 | -------------------------------------------------------------------------------- /sed进阶/模式替代.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #and符号,代表替换命令中的匹配模式,不管预定义模式是什么文本,都可以用and符号替换,and符号会提取匹配替换命令中指定替换模式中的所有字符串 4 | echo "The cat sleeps in his hat" | sed 's/.at/"&"/g' 5 | 6 | #替换单独的单词 7 | echo "The System Administrator manual" | sed 's/\(System\) Administrator/\1 user/' 8 | 9 | #在长数字中插入逗号 10 | echo "1234567" | sed '{:start; s/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/; t start}' 11 | 12 | -------------------------------------------------------------------------------- /mysql数据库/格式化输出数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #redirecting SQL output to a variable 4 | 5 | MYSQL=`which mysql` 6 | dbs=`$MYSQL emwjs -u test -Bse 'show tables;'` 7 | for db in $dbs 8 | do 9 | echo $db 10 | done 11 | 12 | 13 | #使用xml输出数据 14 | $MYSQL emwjs -u test -X -e 'select * from em_admin' 15 | 16 | #使用table标签输出数据 17 | $MYSQL emwjs -u test -H -e 'select * from em_admin' 18 | 19 | -------------------------------------------------------------------------------- /Docker安装脚本/mysql8/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cur_dir=`pwd` 3 | 4 | docker stop lamp_mysql 5 | docker rm lamp_mysql 6 | docker run --name lamp_mysql --restart=always \ 7 | -v `pwd`/conf:/etc/mysql/conf.d \ 8 | -v /data/docker-data/mysql8-data/:/var/lib/mysql \ 9 | -p 3306:3306 \ 10 | -e MYSQL_ROOT_PASSWORD="root" \ 11 | -e TZ=Asia/Shanghai \ 12 | -d mysql:8.0.19 13 | -------------------------------------------------------------------------------- /理解输入和输出/永久重定向.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # testing STDERR messages 3 | # redirecting all to a file 4 | 5 | # 脚本执行期间,用exec命令告诉shell重定向某个特定文件描述符 6 | exec 2>test 7 | 8 | ls badtest 9 | echo "This is test of redirecting all output" 10 | echo "from a script to another file" 11 | 12 | exec 1>test1 13 | echo "This is the end of the script" 14 | echo "but this should go to the testerror file" >&2 15 | -------------------------------------------------------------------------------- /Docker安装脚本/redis/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker stop lamp_redis 4 | docker rm lamp_redis 5 | docker run -idt -p 16379:16379 --name lamp_redis --restart=always \ 6 | -v `pwd`/redis.conf:/etc/redis/redis_default.conf \ 7 | -v /data/docker-data/redis-data/:/data \ 8 | -e TZ="Asia/Shanghai" \ 9 | redis:4.0.12 redis-server /etc/redis/redis_default.conf --appendonly yes 10 | 11 | -------------------------------------------------------------------------------- /Docker安装脚本/mssql/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cur_dir=`pwd` 3 | 4 | 5 | docker stop mssql 6 | docker rm mssql 7 | sudo docker run --name mssql -e 'ACCEPT_EULA=Y' \ 8 | -e 'MSSQL_SA_PASSWORD=1234@abcd' \ 9 | -p 1433:1433 \ 10 | -v /opt/mssql/data:/var/opt/mssql/data \ 11 | -v /opt/mssql/log:/var/opt/mssql/log \ 12 | -v /opt/mssql/secrets:/var/opt/mssql/secrets \ 13 | mcr.microsoft.com/mssql/server:2019-latest 14 | -------------------------------------------------------------------------------- /sed进阶/重定向sed输出.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # add commas to numbers in factorial answer 4 | 5 | factorial=1 6 | counter=1 7 | number=$1 8 | 9 | while [ $counter -le $number ] 10 | do 11 | factorial=$[ $factorial * $counter ] 12 | counter=$[ $counter + 1 ] 13 | done 14 | 15 | result=`echo $factorial | sed '{ 16 | :start 17 | s/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/ 18 | t start 19 | }'` 20 | 21 | echo "The result is $result" 22 | -------------------------------------------------------------------------------- /理解输入和输出/创建临时目录.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using a temporary directory 4 | 5 | tempdir=`mktemp -d dir.XXXXXX` 6 | cd $tempdir 7 | 8 | tempfile1=`mktemp temp.XXXXXX` 9 | tempfile2=`mktemp temp.XXXXXX` 10 | exec 7> $tempfile1 11 | exec 8> $tempfile2 12 | 13 | echo "Sending data to directory $tempdir" 14 | echo "This is a test line of data for $tempfile1" >&7 15 | echo "This is a test line of data for $tempfile2" >&8 16 | 17 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker stop lamp_nginx 4 | docker rm lamp_nginx 5 | docker run -idt -p 10000:10000 -p 180:180 --name lamp_nginx --restart=always \ 6 | -v /data/projects/:/data/projects \ 7 | -v `pwd`/conf/:/etc/nginx \ 8 | -v `pwd`/logs/:/var/log/nginx \ 9 | -v `pwd`/html/crossdomain.xml:/usr/share/nginx/html/crossdomain.xml \ 10 | -e TZ="Asia/Shanghai" \ 11 | nginx:1.17.0 12 | 13 | -------------------------------------------------------------------------------- /结构化命令/使用elif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # looking for a possible value 4 | 5 | if [ $USER = "tiandi" ] 6 | then 7 | echo "Welcome $USER" 8 | echo "Please enjoy your visit" 9 | elif [ $USER = testing ] 10 | then 11 | echo "Welcome $USER" 12 | echo "Please enjoy your visit" 13 | elif [ $USER = barbar ] 14 | then 15 | echo "Do not forget to logout when you're done" 16 | else 17 | echo "Sorry, you are not allowed here" 18 | fi 19 | 20 | -------------------------------------------------------------------------------- /脚本函数/累加数组中的值.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #adding values in the array 4 | 5 | function addarray { 6 | local sum=0 7 | local newarray 8 | newarray=(`echo "$@"`) 9 | for value in ${newarray[*]} 10 | do 11 | sum=$[ $sum + $value ] 12 | done 13 | echo $sum 14 | } 15 | 16 | myarray=(1 2 3 4 5) 17 | echo "The original array is : ${myarray[*]}" 18 | arg1=`echo ${myarray[*]}` 19 | result=`addarray $arg1` 20 | echo "The result is $result" 21 | -------------------------------------------------------------------------------- /理解输入和输出/创建自己的重定向/创建输入文件描述符.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # redirecting input file descriptors 3 | 4 | exec 3>&1 5 | echo "This is the 3 file descriptor" >&3 6 | 7 | exec 6>&0 8 | exec 0 output.txt 13 | 14 | # piping a loop to another command 15 | 16 | for state in "North Dakota" Connecticut 17 | do 18 | echo "$state is next place to go" 19 | done | sort 20 | echo "This completes our travels" 21 | -------------------------------------------------------------------------------- /Docker安装脚本/MinIo/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cur_dir=`pwd` 3 | 4 | docker stop lamp_minio 5 | docker rm lamp_minio 6 | docker run -p 9000:9000 -p 9999:9999 --name lamp_minio --restart=always \ 7 | -e "MINIO_ROOT_USER=lamp" \ 8 | -e "MINIO_ROOT_PASSWORD=ZHadmin123." \ 9 | -v /Users/tangyh/data/minio_data:/data \ 10 | -v /Users/tangyh/data/minio_config:/root/.minio \ 11 | -d minio/minio server --address '0.0.0.0:9000' --console-address '0.0.0.0:9999' /data 12 | -------------------------------------------------------------------------------- /处理用户输入/分离参数和选项.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #extracting options and parameters 4 | 5 | while [ -n "$1" ] 6 | do 7 | case "$1" in 8 | -a) echo "Found the -a option";; 9 | -b) echo "Found the -b option";; 10 | -c) echo "Found the -c option";; 11 | --) shift 12 | break;; 13 | *) echo "$1 is not an option";; 14 | esac 15 | shift 16 | done 17 | 18 | count=1 19 | for param in $@ 20 | do 21 | echo "Parameter #$count: $param" 22 | count=$[ $count + 1 ] 23 | done 24 | -------------------------------------------------------------------------------- /理解输入和输出/创建本地临时文件.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # creating and using a temp file 4 | 5 | tempfile=`mktemp test.XXXXXX` 6 | 7 | exec 3>$tempfile 8 | 9 | echo "This script writes to temp file $tempfile" 10 | 11 | echo "This is the first line" >&3 12 | echo "This is the second line" >&3 13 | echo "This is the last line" >&3 14 | 15 | exec 3>&- 16 | 17 | echo "Done creating temp file. The contents are:" 18 | 19 | cat $tempfile 20 | 21 | rm -f $tempfile 2>/dev/null 22 | 23 | -------------------------------------------------------------------------------- /结构化命令/output.txt: -------------------------------------------------------------------------------- 1 | /home/tiandi/Desktop is a directory 2 | /home/tiandi/Documents is a directory 3 | /home/tiandi/Downloads is a directory 4 | /home/tiandi/examples.desktop is a file 5 | /home/tiandi/lamp is a directory 6 | /home/tiandi/Music is a directory 7 | /home/tiandi/Pictures is a directory 8 | /home/tiandi/Public is a directory 9 | /home/tiandi/sh is a directory 10 | /home/tiandi/Templates is a directory 11 | /home/tiandi/test is a directory 12 | /home/tiandi/Videos is a directory 13 | -------------------------------------------------------------------------------- /脚本实用工具/black_list.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black/black.txt 4 | 5 | DEFINE="5" 6 | 7 | for i in `cat /root/black/black.txt` 8 | do 9 | 10 | IP=`echo $i |awk -F= '{print $1}'` 11 | NUM=`echo $i|awk -F= '{print $2}'` 12 | 13 | if [ $NUM -gt $DEFINE ]; then 14 | grep $IP /etc/hosts.deny > /dev/null 15 | 16 | if [ $? -gt 0 ]; then 17 | echo "sshd:$IP" >> /etc/hosts.deny 18 | fi 19 | fi 20 | done 21 | -------------------------------------------------------------------------------- /mysql数据库/向数据库中插入数据.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # send data to the the table in the MYSQL database 3 | 4 | MYSQL=`which mysql` 5 | 6 | if [ $# -ne 2 ] 7 | then 8 | echo "Usage:mtest2 emplid lastname firstname salary" 9 | else 10 | #脚本变量一定要用双引号,字符串变量使用单引号 11 | statement=" insert into em_admin values(NULL, '$1', $2)" 12 | $MYSQL emwjs -u test <> $HOME/testing 13 | else 14 | #the file is not exists,create a new file 15 | echo "Creating a new file" 16 | date > $HOME/testing 17 | fi 18 | else 19 | echo 'Sorry. you do not have a $HOME directory' 20 | fi 21 | -------------------------------------------------------------------------------- /脚本函数/从函数返回数组.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # returning an array value 4 | 5 | function arraydblr { 6 | local origarry 7 | local newarray 8 | local elements 9 | local i 10 | origarry=(`echo "$@"`) 11 | newarray=(`echo "$@"`) 12 | elements=$[ $# - 1 ] 13 | for (( i=0; i<=$elements; i++ )) 14 | { 15 | newarray[$i]=$[ ${origarry[$i]} * 2 ] 16 | } 17 | 18 | echo ${newarray[*]} 19 | } 20 | 21 | myarray=(1 2 3 4 5) 22 | echo "The original array is : ${myarray[*]}" 23 | arg1=`echo ${myarray[*]}` 24 | result=(`arraydblr $arg1`) 25 | echo "The new array is : ${result[*]}" 26 | -------------------------------------------------------------------------------- /处理用户输入/使用getopt命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #extracting command line options and values with getopt 3 | # getopt command is not goot at dealing with space,we can use getopts 4 | set -- `getopt -q ab:c "$@"` 5 | while [ -n "$1" ] 6 | do 7 | case "$1" in 8 | -a) echo "Found the -a option";; 9 | -b) param="$2" 10 | echo "Found the -b option,with parameter value $param" 11 | shift;; 12 | -c) echo "Found the -c option";; 13 | --) shift 14 | break;; 15 | *) echo "$1 is not an option";; 16 | esac 17 | shift 18 | done 19 | 20 | count=1 21 | for param in "$@" 22 | do 23 | echo "Parameter #$count: $param" 24 | count=$[ $count+1 ] 25 | done 26 | -------------------------------------------------------------------------------- /脚本函数/在函数中使用参数.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # passing parameters to a function 4 | 5 | function addem { 6 | if [ $# -eq 0 ] || [ $# -gt 2 ] 7 | then 8 | echo -1 9 | elif [ $# -eq 1 ] 10 | then 11 | echo $[ $1 + $1 ] 12 | else 13 | echo $[ $1 + $2 ] 14 | fi 15 | } 16 | 17 | echo -n "Adding 10 and 15:" 18 | value=`addem 10 15` 19 | echo $value 20 | 21 | echo -n "Let's try adding just one number: " 22 | value=`addem 10` 23 | echo $value 24 | 25 | echo -n "Now trying adding no number: " 26 | value=`addem` 27 | echo $value 28 | 29 | echo -n "Finally, try adding three or more numbers: " 30 | value=`addem 10 15 20` 31 | echo $value 32 | 33 | -------------------------------------------------------------------------------- /网络限流/清除限流效果.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 日志文件路径 4 | #LOG_FILE="/path/to/log_file.log" 5 | 6 | # 要限速的端口 7 | TARGET_PORT="9090" 8 | 9 | # 函数:清除流量限速设置 10 | clear_traffic_limit() { 11 | echo "执行清除限流的操作" 12 | # 在日志文件中记录限速已清除 13 | #echo "$(date): Traffic limit is cleared for port $TARGET_PORT." >> "$LOG_FILE" 14 | # 在这里执行清除流量限速设置的操作 15 | iptables -D OUTPUT -p tcp --sport $TARGET_PORT -j MARK --set-mark 1 16 | ip rule del fwmark 1 table 1 17 | tc qdisc del dev eth0 root 18 | echo "Traffic limit for src port $TARGET_PORT is enabled for this connection." 19 | } 20 | 21 | 22 | clear_traffic_limit 23 | 24 | #停止限流的进程 25 | pkill -f traffic.sh -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/META-INF/spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "groups": [], 3 | "properties": [ 4 | { 5 | "name": "logging.extend.kafka-appender.bootstrap-servers", 6 | "type": "java.lang.String", 7 | "defaultValue": "localhost:9092" 8 | }, 9 | { 10 | "name": "logging.extend.kafka-appender.topic", 11 | "type": "java.lang.String", 12 | "defaultValue": "logback_to_logstash" 13 | }, 14 | { 15 | "name": "logging.extend.logstash-appender.destination", 16 | "type": "java.lang.String", 17 | "defaultValue": "localhost:4560" 18 | } 19 | ], 20 | "hints": [ 21 | ] 22 | } -------------------------------------------------------------------------------- /脚本函数/默认退出状态码.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # testing the exit status of a function 4 | 5 | func1() { 6 | echo "Trying to display a non-existent file" 7 | ls -l badfile 8 | } 9 | 10 | #由于最后一条命令未执行成功,返回的状态码非0 11 | echo "testing the function" 12 | func1 13 | echo "The exit status is : $?" 14 | 15 | func2() { 16 | ls -l badfile 17 | echo "Another test to display a non-existent file" 18 | } 19 | 20 | #由于最后一条命令echo执行成功,返回的状态码为0 21 | echo "Another test" 22 | func2 23 | echo "The exit status is : $?" 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /图形化桌面的脚本编程/使用select命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # using select in the menu 3 | 4 | function diskspace { 5 | clear 6 | df -k 7 | } 8 | 9 | function whoseon { 10 | clear 11 | who 12 | } 13 | 14 | function menusage { 15 | clear 16 | cat /proc/meminfo 17 | } 18 | 19 | PS3="Enter option:" 20 | select option in "Display disk space" "Display logged on users" "Display memory usage" "Exit program" 21 | do 22 | case $option in 23 | "Exit program") 24 | break;; 25 | "Display disk space") 26 | diskspace;; 27 | "Display logged on users") 28 | whoseon;; 29 | "Display memory usage") 30 | menusage;; 31 | *) 32 | clear 33 | echo "Sorry, wrong selection";; 34 | esac 35 | done 36 | clear 37 | -------------------------------------------------------------------------------- /处理用户输入/获取用户输入.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # testing the reading command 4 | 5 | echo -n "Enter your name:" 6 | read name 7 | echo "Hello $name, welcome to my program" 8 | 9 | read -p "Please enter your age: " age 10 | days=$[ $age * 365 ] 11 | echo "That makes you over $days days old" 12 | 13 | #指定多个变量,输入的每个数据值都会分配给表中的下一个变量,如果用完了,就全分配各最后一个变量 14 | read -p "Please enter name:" first last 15 | echo "Checking data for $last. $first..." 16 | 17 | #如果不指定变量,read命令就会把它收到的任何数据都放到特殊环境变量REPLY中 18 | read -p "Enter a number:" 19 | factorial=1 20 | for (( count=1; count<=$REPLY; count++)) 21 | do 22 | factorial=$[ $factorial * $count ] 23 | done 24 | echo "The factorial of $REPLY is $factorial" 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /脚本实用工具/IP_iptables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #mail xuel@51idc.com 3 | #data 2017/2/23 4 | 5 | #function: use iptables Brute force 6 | SCAN=`/bin/egrep "Failed password for root" /var/log/secure|awk -F'[ :]+' '{print $13}'|sort|uniq -c|awk '{print $1"="$2;}'` 7 | for I in ${SCAN} 8 | do 9 | SCANUM=`echo ${I}|awk -F'=' '{print $1}'` 10 | SCANIP=`echo ${I}|awk -F'=' '{print $2}'` 11 | if [ ${SCANUM} -gt 100 ] && [ -z "`/sbin/iptables -vnL INPUT | grep $SCANIP`" ];then 12 | /sbin/iptables -I INPUT -s $SCANIP -m state --state NEW,RELATED,ESTABLISHED -j DROP 13 | echo "`date` $SCANIP($SCANUM)">>/var/log/scanIP.log 14 | fi 15 | done 16 | if [ $? -eq 0 ];then 17 | service iptables save && service iptables restart 18 | fi 19 | 20 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/scgi_params: -------------------------------------------------------------------------------- 1 | 2 | scgi_param REQUEST_METHOD $request_method; 3 | scgi_param REQUEST_URI $request_uri; 4 | scgi_param QUERY_STRING $query_string; 5 | scgi_param CONTENT_TYPE $content_type; 6 | 7 | scgi_param DOCUMENT_URI $document_uri; 8 | scgi_param DOCUMENT_ROOT $document_root; 9 | scgi_param SCGI 1; 10 | scgi_param SERVER_PROTOCOL $server_protocol; 11 | scgi_param REQUEST_SCHEME $scheme; 12 | scgi_param HTTPS $https if_not_empty; 13 | 14 | scgi_param REMOTE_ADDR $remote_addr; 15 | scgi_param REMOTE_PORT $remote_port; 16 | scgi_param SERVER_PORT $server_port; 17 | scgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /Docker安装脚本/nacos/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker stop lamp_nacos 4 | docker rm lamp_nacos 5 | docker run -idt --name lamp_nacos --restart=always \ 6 | -e JVM_XMS=512m -e JVM_XMX=512m -e JVM_XMN=384m \ 7 | -e PREFER_HOST_MODE=hostname -e MODE=standalone -e SPRING_DATASOURCE_PLATFORM=mysql \ 8 | -e MYSQL_DATABASE_NUM=1 \ 9 | -e MYSQL_SERVICE_HOST=192.168.80.130 -e MYSQL_SERVICE_DB_NAME=lamp_nacos -e MYSQL_SERVICE_PORT=3306 \ 10 | -e MYSQL_SERVICE_USER=root \ 11 | -e MYSQL_SERVICE_PASSWORD=root \ 12 | -p 8848:8848 \ 13 | -v `pwd`/logs/:/home/nacos/logs \ 14 | -v `pwd`/init.d/custom.properties:/home/nacos/init.d/custom.properties \ 15 | nacos/nacos-server:v2.1.1 16 | -------------------------------------------------------------------------------- /gawk进阶/使用模式,结构化命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #正则表达式 3 | 4 | gawk 'BEGIN{FS=","} 5 | /11/{print $1} 6 | ' test 7 | 8 | #if-else语句 9 | gawk '{ 10 | if($1 > 20) 11 | { 12 | x=$1*20 13 | print x 14 | } 15 | else 16 | { 17 | x=$1/2 18 | print x 19 | } 20 | }' test 21 | 22 | #while 语句 23 | gawk '{ 24 | total = 0 25 | i=1 26 | while(i<4) 27 | { 28 | total+=$i 29 | i++ 30 | } 31 | avg = total/3 32 | print "Average:".avg 33 | }' test 34 | 35 | 36 | #do-while语句 37 | gawk '{ 38 | total=0 39 | i=1 40 | do 41 | { 42 | total += $i 43 | i++ 44 | }while(total < 150) 45 | print total }' test 46 | 47 | 48 | #for语句 49 | gawk '{ 50 | total = 0 51 | for (i=1; i<4; i++) 52 | { 53 | total+=$i 54 | } 55 | avg = total/3 56 | print "Average:".avg 57 | }' test 58 | -------------------------------------------------------------------------------- /脚本实用工具/Custom_Rm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # function:自定义rm命令,每天晚上定时清理 3 | 4 | CMD_SCRIPTS=$HOME/.rm_scripts.sh 5 | TRASH_DIR=$HOME/.TRASH_DIR 6 | CRON_FILE=/var/spool/cron/root 7 | BASHRC=$HOME/.bashrc 8 | 9 | [ ! -d ${TRASH_DIR} ] && mkdir -p ${TRASH_DIR} 10 | cat > $CMD_SCRIPTS <> $CRON_FILE 24 | echo "删除目录:$TRASH_DIR" 25 | echo "删除脚本:$CMD_SCRIPTS" 26 | echo "请执行:source $BASHRC 来加载文件或退出当前shell重新登录" 27 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/uwsgi_params: -------------------------------------------------------------------------------- 1 | 2 | uwsgi_param QUERY_STRING $query_string; 3 | uwsgi_param REQUEST_METHOD $request_method; 4 | uwsgi_param CONTENT_TYPE $content_type; 5 | uwsgi_param CONTENT_LENGTH $content_length; 6 | 7 | uwsgi_param REQUEST_URI $request_uri; 8 | uwsgi_param PATH_INFO $document_uri; 9 | uwsgi_param DOCUMENT_ROOT $document_root; 10 | uwsgi_param SERVER_PROTOCOL $server_protocol; 11 | uwsgi_param REQUEST_SCHEME $scheme; 12 | uwsgi_param HTTPS $https if_not_empty; 13 | 14 | uwsgi_param REMOTE_ADDR $remote_addr; 15 | uwsgi_param REMOTE_PORT $remote_port; 16 | uwsgi_param SERVER_PORT $server_port; 17 | uwsgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /shell脚本编程进阶/创建捕捉脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Capture_Stats - Gather System Performance Statistics 4 | # 5 | ######################################################### 6 | # 7 | # Set Script Variables 8 | # 9 | REPORT_FILE=/home/tiandi/Documents/capstats.csv 10 | DATE=`date +%m/%d/%y` 11 | TIME=`date +%k:%M:%S` 12 | # 13 | ############################################################ 14 | # 15 | USERS=`uptime | sed 's/user.*$//' | gawk '{print $NF}'` 16 | LOAD=`uptime | gawk '{print $NF}'` 17 | # 18 | FREE=`vmstat 1 2 | sed -n '/[0-9]/p' | sed -n '2p' | gawk '{print $4}'` 19 | IDLE=`vmstat 1 2 | sed -n '/[0-9]/p' | sed -n '2p' | gawk '{print $15}'` 20 | # 21 | ########################################## 22 | # 23 | echo "$DATE,$TIME,$USERS,$LOAD,$FREE,$IDLE" >> $REPORT_FILE 24 | # 25 | -------------------------------------------------------------------------------- /Docker安装脚本/nacos/init.d/custom.properties: -------------------------------------------------------------------------------- 1 | #spring.security.enabled=false 2 | #management.security=false 3 | #security.basic.enabled=false 4 | #nacos.security.ignore.urls=/** 5 | #management.metrics.export.elastic.host=http://localhost:9200 6 | # metrics for prometheus 7 | #management.endpoints.web.exposure.include=* 8 | # metrics for elastic search 9 | #management.metrics.export.elastic.enabled=false 10 | #management.metrics.export.elastic.host=http://localhost:9200 11 | # metrics for influx 12 | #management.metrics.export.influx.enabled=false 13 | #management.metrics.export.influx.db=springboot 14 | #management.metrics.export.influx.uri=http://localhost:8086 15 | #management.metrics.export.influx.auto-create-db=true 16 | #management.metrics.export.influx.consistency=one 17 | #management.metrics.export.influx.compressed=true 18 | -------------------------------------------------------------------------------- /脚本实用工具/当服务器线程数超过 2500 时自动 dump 线程数最高的 java 进程的内存及线程栈: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 来源: https://blog.csdn.net/qianghaohao/article/details/80379118 3 | # 服务器线程数达到 2500 以上时 dump 线程数最多的 java 进程的线程及内存 4 | # 5 | source ~/.bashrc 6 | cur_thread_num=`ps -efL | wc -l` 7 | if [ $cur_thread_num -le 2500 ]; then 8 | exit 0 9 | fi 10 | 11 | cur_date=`date +"%Y-%m-%d_%H-%M-%S"` 12 | cd ./dumpfile 13 | # 服务器当前线程 dump 到文件:按照线程数由大到小排序显示 14 | ps -efL --sort -nlwp > server_thread_dump_$cur_date 15 | # dump 线程数最多的 jvm 的线程及内存 16 | most_thread_num_pid=`cat server_thread_dump_$cur_date | sed -n '2p' | awk '{print $2}'` 17 | nohup jstack -l $most_thread_num_pid > java_app_thread_dump_${cur_date}_pid_${most_thread_num_pid} & 18 | nohup jmap -dump:format=b,file=java_app_mem_dump_${cur_date}_pid_${most_thread_num_pid} $most_thread_num_pid & 19 | 20 | exit 0 21 | -------------------------------------------------------------------------------- /图形化桌面的脚本编程/使用脚本菜单.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function menu { 4 | clear 5 | echo 6 | echo -e "\t\tSys Admin Menu\n" 7 | echo -e "\t1. Display disk space" 8 | echo -e "\t2. Display logged on users" 9 | echo -e "\t3. Display memory usage" 10 | echo -e "\t0. Exit program\n\n" 11 | echo -en "\t\tEnter option:" 12 | read -n 1 option 13 | } 14 | 15 | function diskspace { 16 | clear 17 | df -k 18 | } 19 | 20 | function whoseon { 21 | clear 22 | who 23 | } 24 | 25 | function menusage { 26 | clear 27 | cat /proc/meminfo 28 | } 29 | 30 | while [ 1 ] 31 | do 32 | menu 33 | case $option in 34 | 0) 35 | break;; 36 | 1) 37 | diskspace;; 38 | 2) 39 | whoseon;; 40 | 3) 41 | menusage;; 42 | *) 43 | clear 44 | echo "Sorry, wrong selection";; 45 | esac 46 | echo -en "\n\n\t\tHit any key to continue" 47 | read -n 1 line 48 | done 49 | clear 50 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/conf.d/static_ssl_443.conf: -------------------------------------------------------------------------------- 1 | 2 | upstream minio_server { 3 | least_conn; 4 | server 172.30.30.194:9000; 5 | } 6 | 7 | server { 8 | listen 443 ssl; 9 | server_name static.tangyh.top; 10 | root html; 11 | index index.html index.htm; 12 | ssl_certificate ../ssl/static.tangyh.top.crt; 13 | ssl_certificate_key ../ssl/static.tangyh.top.key; 14 | ssl_session_timeout 5m; 15 | ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 16 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 17 | ssl_prefer_server_ciphers on; 18 | 19 | underscores_in_headers on; 20 | 21 | location / { 22 | proxy_set_header Host $http_host; 23 | proxy_set_header X-Real-IP $remote_addr; 24 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 25 | proxy_pass http://minio_server; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gawk进阶/使用变量.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #使用内建变量 3 | 4 | # NF 当前记录的字段个数 5 | # NR 到目前为止读的记录数量 6 | #下面的程序在每行开头输出行号,并在最后输出文件的总字段数 7 | gawk '{ total+=NF; print NR, $0 }END{ print "Total: ", total}' 8 | 9 | gawk 'BEGIN {testing="This is a test"; print testing; testing=45; print testing}' 10 | 11 | #处理数字值 12 | 13 | gawk 'BEGIN{x=4; x= x*2+3; printx}' 14 | 15 | #处理数组 16 | gawk 'BEGIN{capital["Ill"] = "SprintField"; print capital["Ill"]}' 17 | 18 | #遍历数组变量 19 | gawk 'BEGIN{ 20 | var["a"] = 1 21 | var["g"] = 2 22 | var["m"] = 3 23 | for( test in var) 24 | { 25 | print "Index:",test,"- Value:",var[test] 26 | } 27 | }' 28 | 29 | print "------" 30 | 31 | #删除数组变量 32 | gawk 'BEGIN{ 33 | var["a"] = 1 34 | var["g"] = 2 35 | for (test in var) 36 | { 37 | print "Index:",test," - Value:", var[test] 38 | } 39 | delete var["g"] 40 | 41 | print "----" 42 | 43 | for (test in var) 44 | { 45 | print "Index;",test," - Value:", var[test] 46 | } 47 | }' 48 | -------------------------------------------------------------------------------- /脚本实用工具/check_mysql_ms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mysql_user='root' 3 | mysql_pass="bhVd!564qazWSX78U#7" 4 | data=$(/bin/date +%Y-%m-%d-%H:%M) 5 | /bin/netstat -lntup|egrep ":3306"|grep -v grep>/dev/null0 6 | if [ $? -eq 0 ];then 7 | Slave_IO=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_IO_Running:"|awk -F": " '{print $2}'` 8 | Slave_SQL=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_SQL_Running:"|awk -F": " '{print $2}'` 9 | if [ "$Slave_IO" == "Yes" ] && [ "$Slave_SQL" == "Yes" ];then 10 | STAT=1 && echo "$data mysql-status is ok">>/var/log/mysql-status.log 11 | else 12 | STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log 13 | fi 14 | else 15 | STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log 16 | fi 17 | /usr/bin/zabbix_sender -z 101.227.67.205 -s "DaoDaEr-mysql-status" -k mysql -o $STAT 18 | -------------------------------------------------------------------------------- /图形化桌面的脚本编程/在脚本中使用dialog命令.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # using dialog to create a menu 4 | 5 | temp=`mktemp -t test.XXXXXX` 6 | temp2=`mktemp -t test2.XXXXXX` 7 | 8 | function diskspace { 9 | df -k > $temp 10 | dialog --textbox $temp 20 60 11 | } 12 | 13 | function whoseon { 14 | who > $temp 15 | dialog --textbox $temp 20 50 16 | } 17 | 18 | function menusage { 19 | cat /proc/meminfo > $temp 20 | dialog --textbox $temp 20 50 21 | } 22 | 23 | while [ 1 ] 24 | do 25 | dialog --menu "Sys Admin Menu" 20 30 10 1 "Display disk space" 2 "Display users" 3 "Display memory usage" 0 "Exit" 2> $temp2 26 | if [ $? -eq 1 ] 27 | then 28 | break 29 | fi 30 | 31 | selection=`cat $temp2` 32 | 33 | case $selection in 34 | 1) 35 | diskspace;; 36 | 2) 37 | whoseon;; 38 | 3) 39 | menusage;; 40 | 0) 41 | break;; 42 | *) 43 | dialog --msgbox "Sorry,invalid selection" 10 30 44 | esac 45 | done 46 | rm -f $temp 2> /dev/null 47 | rm -f $temp2 2> /dev/null 48 | -------------------------------------------------------------------------------- /Docker安装脚本/mysql8/conf/my.cnf: -------------------------------------------------------------------------------- 1 | [mysql] 2 | default-character-set=utf8mb4 3 | 4 | [mysqld] 5 | federated 6 | default-storage-engine=INNODB 7 | character_set_server=utf8mb4 8 | collation-server = utf8mb4_general_ci 9 | 10 | datadir = /var/lib/mysql 11 | port = 3306 12 | socket = /var/run/mysqld/mysqld.sock 13 | lower_case_table_names=1 14 | ft_min_word_len=1 15 | # SQL数据包发送的大小,如果有BLOB对象建议修改成1G 16 | max_allowed_packet=128M 17 | 18 | innodb_buffer_pool_size=4G 19 | 20 | innodb_data_file_path=ibdata1:1024M:autoextend:max:1G 21 | innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:1G 22 | default_password_lifetime = 0 23 | 24 | max_connections = 32000 25 | max_user_connections=20000 26 | 27 | # MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭 28 | # MySQL默认的wait_timeout 值为8个小时, interactive_timeout参数需要同时配置才能生效 29 | interactive_timeout = 1800 30 | wait_timeout=1800 31 | default_authentication_plugin=mysql_native_password 32 | 33 | sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 34 | -------------------------------------------------------------------------------- /脚本实用工具/Autoback-xtraback.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | hostname=`/bin/hostname` 3 | week=`date +%w` 4 | datadir=/backup 5 | logdir=/backup/log 6 | mycnf=/etc/my.cnf 7 | Time=`date +%Y-%m-%d_%H-%M-%S` 8 | cmd=`which innobackupex` 9 | user=root 10 | passwd=mysqladmin 11 | 12 | 13 | function getdir() 14 | { 15 | if [ ! -d ${datadir} ];then 16 | mkdir -p ${datadir} 17 | fi 18 | } 19 | function backup() 20 | { 21 | if [ ${week} == "0" ];then 22 | $cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} ${datadir}&>${logdir}/${Time}-log 23 | [ $? -eq 0 ] && stat=`tail -1 ${logdir}/${Time}-log |awk '{print $4}'` 24 | if [ "${stat}" == "OK!" ];then 25 | echo "${Time} mysql backup is success!" 26 | else 27 | echo "${Time} mysql backup is fail! please check ${logdir}/${Time}-log" 28 | fi 29 | else 30 | $cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} --incremental --incremental-basedir=${datadir}&>${logdir}/${Time}-log 31 | 32 | } 33 | -------------------------------------------------------------------------------- /脚本实用工具/查看磁盘目录使用情况.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Big_Users - find big disk space users in various directories 4 | ############################################################# 5 | #Parameters for script 6 | # 7 | CHECK_DIRECTORIES="/var/log /home" #directories to check 8 | # 9 | ######################### Main Script ####################### 10 | # 11 | DATE=$(date '+%m%d%y') #Date for report file 12 | # 13 | exec > disk_space_$DATE.rpt #Make report file Std Output 14 | # 15 | echo "Top Ten Disk Space Usage" #Report header for while report 16 | echo "for $CHECK_DIRECTORIES Directories" 17 | # 18 | for DIR_CHECK in $CHECK_DIRECTORIES #loop to du directories 19 | do 20 | echo "" 21 | echo "The $DIR_CHECK Directory:" #Title header for each directory 22 | # 23 | # Creating a listing of top ten disk space users 24 | du -S $DIR_CHECK 2>/dev/null | 25 | sort -rn | 26 | sed '{11,$D; =}' | 27 | sed 'N; s/\n/ /' | 28 | gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}' 29 | # 30 | done #End of for loop for du directories 31 | # 32 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/README-zh.md: -------------------------------------------------------------------------------- 1 | # 脚本说明 2 | 3 | ## [client](https://github.com/seata/seata/tree/develop/script/client) 4 | 5 | > 存放用于客户端的配置和SQL 6 | 7 | - at: AT模式下的 `undo_log` 建表语句 8 | - conf: 客户端的配置文件 9 | - saga: SAGA 模式下所需表的建表语句 10 | - spring: SpringBoot 应用支持的配置文件 11 | 12 | ## [server](https://github.com/seata/seata/tree/develop/script/server) 13 | 14 | > 存放server侧所需SQL和部署脚本 15 | 16 | - db: server 侧的保存模式为 `db` 时所需表的建表语句 17 | - docker-compose: server 侧通过 docker-compose 部署的脚本 18 | - helm: server 侧通过 Helm 部署的脚本 19 | - kubernetes: server 侧通过 Kubernetes 部署的脚本 20 | 21 | ## [config-center](https://github.com/seata/seata/tree/develop/script/config-center) 22 | 23 | > 用于存放各种配置中心的初始化脚本,执行时都会读取 `config.txt`配置文件,并写入配置中心 24 | 25 | - nacos: 用于向 Nacos 中添加配置 26 | - zk: 用于向 Zookeeper 中添加配置,脚本依赖 Zookeeper 的相关脚本,需要手动下载;ZooKeeper相关的配置可以写在 `zk-params.txt` 中,也可以在执行的时候输入 27 | - apollo: 向 Apollo 中添加配置,Apollo 的地址端口等可以写在 `apollo-params.txt`,也可以在执行的时候输入 28 | - etcd3: 用于向 Etcd3 中添加配置 29 | - consul: 用于向 consul 中添加配置 30 | 31 | ## 打包 32 | ./mvnw -Prelease-seata -Dmaven.test.skip=true clean install -U 33 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/fastcgi_params: -------------------------------------------------------------------------------- 1 | 2 | fastcgi_param QUERY_STRING $query_string; 3 | fastcgi_param REQUEST_METHOD $request_method; 4 | fastcgi_param CONTENT_TYPE $content_type; 5 | fastcgi_param CONTENT_LENGTH $content_length; 6 | 7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 8 | fastcgi_param REQUEST_URI $request_uri; 9 | fastcgi_param DOCUMENT_URI $document_uri; 10 | fastcgi_param DOCUMENT_ROOT $document_root; 11 | fastcgi_param SERVER_PROTOCOL $server_protocol; 12 | fastcgi_param REQUEST_SCHEME $scheme; 13 | fastcgi_param HTTPS $https if_not_empty; 14 | 15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 17 | 18 | fastcgi_param REMOTE_ADDR $remote_addr; 19 | fastcgi_param REMOTE_PORT $remote_port; 20 | fastcgi_param SERVER_ADDR $server_addr; 21 | fastcgi_param SERVER_PORT $server_port; 22 | fastcgi_param SERVER_NAME $server_name; 23 | 24 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 25 | fastcgi_param REDIRECT_STATUS 200; 26 | -------------------------------------------------------------------------------- /shell脚本编程进阶/问题跟踪数据库/查找问题.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Find_Problem - finds problem records using keywords 4 | # 5 | ########################################################### 6 | # 7 | # Determine sql location & set variable 8 | # 9 | MYSQL=`which mysql`" Problem_Trek -u root" 10 | # 11 | ########################################################## 12 | # 13 | # Obtain Keyword(s) 14 | # 15 | if [ -n "$1" ] # Check if a keyword was passed 16 | then # Grab all the passed keywords 17 | # 18 | KEYWORDS=$@ # Grab all the params as separate words, same string 19 | # 20 | else # Keyword(s) not passed, Ask for them 21 | echo 22 | echo "What keywords would you like to search for?" 23 | echo -e "Please separate words by a space: \c" 24 | read ANSWER 25 | KEYWORDS=$ANSWER 26 | fi 27 | # 28 | ####################################################### 29 | # 30 | # Find problem record 31 | # 32 | echo 33 | echo "The following was found using keywords: $KEYWORDS" 34 | echo 35 | # 36 | KEYWORDS=`echo $KEYWORDS | sed 's/ /|/g'` 37 | # 38 | $MYSQL < CPU) print $2}') 20 | CPULIMITCMD=$(which cpulimit) 21 | 22 | install_cpulimit() { 23 | [ ! -d /tmp ] && mkdir /tmp || cd /tmp 24 | wget -c https://github.com/opsengine/cpulimit/archive/v0.2.tar.gz 25 | tar -zxf v0.2.tar.gz 26 | cd cpulimit-0.2 && make 27 | [ $? -eq 0 ] && cp src/cpulimit /usr/bin/ 28 | } 29 | 30 | 31 | do_cpulimit() { 32 | [ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR} 33 | for i in ${PIDARG}; 34 | do 35 | MSG=$(ps -aux |awk -v pid=$i '{if($2 == pid) print $0}') 36 | echo ${MSG} 37 | [ ! -d /tmp ] && mkdir /tmp || cd /tmp 38 | nohup ${CPULIMITCMD} -p $i -l ${LIMIT_CPU} & 39 | echo "$(date) -- ${MSG}" >> ${LOG_DIR}$(date +%F).log 40 | done 41 | } 42 | 43 | main() { 44 | 45 | hash cpulimit 46 | if [ $? -eq 0 ];then 47 | do_cpulimit 48 | else 49 | install_cpulimit && do_cpulimit 50 | fi 51 | } 52 | 53 | main 54 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/logs/error.log: -------------------------------------------------------------------------------- 1 | 2022/03/02 17:04:22 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 2 | 2022/03/02 17:04:26 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 3 | 2022/03/02 17:04:31 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 4 | 2022/03/02 17:04:35 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 5 | 2022/03/02 17:04:40 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 6 | 2022/03/02 17:04:44 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 7 | 2022/03/02 17:04:50 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 8 | 2022/03/02 17:04:58 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 9 | 2022/03/02 17:05:14 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 10 | 2022/03/02 17:05:42 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 11 | 2022/03/02 17:06:35 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 12 | 2022/03/02 17:07:37 [emerg] 1#1: open() "/etc/nginx/logs/error.log" failed (2: No such file or directory) 13 | -------------------------------------------------------------------------------- /shell脚本编程进阶/生成报告脚本-基于创建捕捉脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Report_Stats - Generates Rpt from Captured Perf Stats 4 | # 5 | ############################################################ 6 | # 7 | # Set Script Variables 8 | # 9 | REPORT_FILE=/home/tiandi/Documents/capstats.csv 10 | TEMP_FILE=/home/tiandi/Documents/capstats.html 11 | # 12 | DATE=`date +%m/%d/%y` 13 | # 14 | MAIL=`which mutt` 15 | MAIL_TO=tiandi 16 | # 17 | ###############################################################3 18 | # 19 | # Create Report Header 20 | # 21 | echo "

Report for $DATE

" > $TEMP_FILE 22 | echo "" >> $TEMP_FILE 23 | echo "" >> $TEMP_FILE 24 | echo "" >> $TEMP_FILE 25 | # 26 | ############################################################### 27 | # 28 | # Place Performance Stats in Report 29 | # 30 | cat $REPORT_FILE | gawk -F, '{ 31 | printf "", $1, $2, $3; 32 | printf "\n\n", $4, $5, $6; 33 | }' >> $TEMP_FILE 34 | # 35 | echo "
DateTimeUsersLoadFree Memory%CPU Idle
%s%s%s%s%s%s
" >> $TEMP_FILE 36 | # 37 | ################################################################ 38 | # 39 | # Mail Performance Report & Clean up 40 | # 41 | #$MAIL -a $TEMP_FILE -s "Performance Report $DATE" 42 | #-- $MAIL_TO < /dev/null 43 | # 44 | #rm -r $TEMP_FILE 45 | # 46 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/logback/console-appender.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | ${CONSOLE_LOG_PATTERN} 26 | UTF-8 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /gawk进阶/输出.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #print用于产生简单输出 4 | #多个表达式的字符串值之间用输出字段分隔符分开 5 | 6 | gawk '{ print $1, $2 }' 7 | 8 | #输出字段分割符与输出记录分隔符存储在内建变量OFS与ORS中, 9 | #初始情况下,OFS与ORS被设置成一个空格符与一个换行符,但它们的值可以在任何时候改变 10 | #下面这个程序打印每一行的第1第2个字段,字段之间用分号分开,在每一行的第2个字段之后输出两个换行符 11 | 12 | gawk 'BEGIN { OFS = ":"; ORS = "\n\n" } 13 | { print $1, $2 }' 14 | 15 | #下面这个程序拼接第1个与第2个字段,两个字段之间没有输出字段分隔符插入 16 | 17 | gawk '{ print $1 $2 }' 18 | 19 | #这两句话等价 20 | 21 | gawk '{ print }' 22 | gawk '{ print $0 }' 23 | 24 | #输出空行 25 | 26 | gawk '{ print "" }' 27 | 28 | 29 | #printf用于产生格式化输出 30 | 31 | #printf不会自动换行,需要手动添加\n 32 | #格式说明符以%开始,以转换字符结束 33 | # - 表达式在它的域内左对齐,没有则右对齐 34 | # width 为了达到规定的宽度,必要时填充空格 35 | # .prec 字符串最大宽度, 或十进制数的小数部分的位数 36 | 37 | gawk '{ printf ("Name:%-10sAge:%-5dWeight:%7.2f\n", $1, $2, $3) }' 38 | 39 | 40 | #输出到文件 41 | #重定向运算符>与>>用于将输出重定向到文件,文件名必须用双引号括起来 42 | 43 | #下面这个程序将所有输入行的第1个与第3个字段输出到两个文件中:如果第3个字段大于100,则输出到bigpop,否则输出到smallpop 44 | gawk '{ print($1, $3) > ($3 > 100 ? "bigpop" : "smallpop") }' 45 | 46 | 47 | #输出到管道 48 | #print的输出将以管道的方式传递给command 49 | 50 | # Canada 3852 51 | # China 3705 52 | # USA 3615 53 | # Brazil 3286 54 | 55 | gawk '{ pop[$1]+=$2 } 56 | END{ for(c in pop) printf("%15-s%6d\n", c, pop[c]) | "sort -nk 2"; close("sort -nk 2") }' 57 | 58 | 59 | #关闭文件与管道 60 | #语句close(expression)关闭一个文件或管道,文件或管道由expression指定。 61 | #expression的字符串值必须与最初用于创建文件或管道的字符串值相同。 62 | #在同一个程序中,如果你写了一个文件,而待会儿想要读取它,那么就需要调用close。 63 | #某一时刻,同时处于打开状态的文件或管道数量最大值由实现定义。 64 | 65 | close("sort -nk 2") 66 | 67 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | user root; 3 | worker_processes 1; 4 | 5 | error_log logs/error.log warn; 6 | #error_log logs/error.log notice; 7 | #error_log logs/error.log info; 8 | 9 | pid logs/nginx.pid; 10 | 11 | 12 | events { 13 | worker_connections 1024; 14 | } 15 | 16 | 17 | http { 18 | include mime.types; 19 | default_type application/octet-stream; 20 | 21 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 22 | '$status $body_bytes_sent "$http_referer" ' 23 | '"$http_user_agent" "$http_x_forwarded_for"'; 24 | 25 | access_log logs/access.log main; 26 | 27 | sendfile on; 28 | #tcp_nopush on; 29 | 30 | #keepalive_timeout 0; 31 | keepalive_timeout 65; 32 | 33 | # 文件上传大小限制 34 | client_max_body_size 512M; 35 | client_body_buffer_size 256k; 36 | 37 | # 压缩设置 38 | gzip on; 39 | # 开启gzip_static 40 | # gzip_static 开启后可能会报错,需要安装相应的模块, 具体安装方式可以自行查询 41 | # 只有这个开启,vue文件打包的.gz文件才会有效果,否则不需要开启gzip进行打包 42 | gzip_static on; 43 | gzip_proxied any; 44 | gzip_min_length 5k; 45 | gzip_buffers 4 16k; 46 | gzip_comp_level 3; 47 | gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; 48 | gzip_vary on; 49 | gzip_disable "MSIE [1-6]\."; 50 | 51 | 52 | include /usr/local/nginx/conf/conf.d/*.conf; 53 | } 54 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/README.md: -------------------------------------------------------------------------------- 1 | # Script Description 2 | 3 | ## [client](https://github.com/seata/seata/tree/develop/script/client) 4 | 5 | > Store configuration and SQL for client side 6 | 7 | - at: Script of create table `undo_log` for AT mode. 8 | - conf: Configuration which client need. 9 | - saga: Script of create table in SAGA mode 10 | - spring: Configuration for Spring Boot 11 | 12 | ## [server](https://github.com/seata/seata/tree/develop/script/server) 13 | 14 | > Store SQL and deploy script for server side 15 | 16 | - db: Create table script for server when store mode is `db` 17 | - docker-compose: Script for deploy server by docker-compose 18 | - helm: Script for deploy server by Helm 19 | - kubernetes: Script for deploy server by Kubernetes 20 | 21 | ## [config-center](https://github.com/seata/seata/tree/develop/script/config-center) 22 | 23 | > Store initialize script for configuration center, will use `config.txt` as configuration when initial 24 | 25 | - nacos: Initialize script for Nacos 26 | - zk: Initialize script for ZooKeeper, the script need related script in Zookeeper, you need download yourself. You can modify `zk-params.txt` to change the ZooKeeper server configuration, or input when execute also 27 | - apollo: Initialize script for Apollo. You can modify `apollo-params.txt` to change the Apollo server configuration, or input when execute also 28 | - etcd3: Initialize script for Etcd3 29 | - consul: Initialize script for consul 30 | 31 | ## build packege 32 | ./mvnw -Prelease-seata -Dmaven.test.skip=true clean install -U 33 | 34 | -------------------------------------------------------------------------------- /shell脚本编程进阶/问题跟踪数据库/记录问题.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Record_Problem - records system problems in database 4 | # 5 | ########################################################### 6 | # 7 | # Determine mysql location & put into variable 8 | # 9 | MYSQL=`which mysql`" Problem_Trek -u root" 10 | # 11 | ########################################################### 12 | # 13 | # Create Record Id & Report_Date 14 | # 15 | #ID_NUMBER=`date +%y%m%d%H%M` 16 | # 17 | REPORT_DATE=`date +%y%m%d` 18 | # 19 | ############################################################ 20 | # 21 | # Acquire information to put into table 22 | # 23 | echo 24 | echo -e "Birefly describe the problem & its symptoms: \c" 25 | # 26 | read ANSWER 27 | PROB_SYMPTOMS=$ANSWER 28 | # 29 | # Set Fixed Date & Problem Solution to null for now 30 | # 31 | FIXED_DATE=0 32 | PROB_SOLUTIONS="" 33 | # 34 | ############################################################# 35 | # 36 | # Insert acquired information into table 37 | # 38 | echo 39 | echo "Problem recorded as follows:" 40 | echo 41 | id=$($MYSQL -e "INSERT INTO problem_logger VALUES (null,$REPORT_DATE,$FIXED_DATE,'$PROB_SYMPTOMS','$PROB_SOLUTIONS');SELECT LAST_INSERT_ID() id") 42 | id=`echo $id | gawk '{print $2}'` 43 | $MYSQL < /dev/null 66 | # 67 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/lua/redislocker/redislock.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- User: tianyu.li 3 | -- Date: 2021/1/19 4 | -- 5 | -- init data 6 | local array = {}; local result; local keySize = ARGV[1]; local argSize = ARGV[2]; 7 | -- Loop through all keys to see if they can be used , when a key is not available, exit 8 | for i= 1, keySize do 9 | -- search lock xid 10 | result = redis.call('HGET',KEYS[i],'xid'); 11 | -- if lock xid is nil 12 | if (not result) 13 | -- set 'no' mean There is need to store lock information 14 | then array[i]='no' 15 | else 16 | if (result ~= ARGV[3]) 17 | then 18 | -- return fail 19 | return result 20 | else 21 | -- set 'yes' mean There is not need to store lock information 22 | array[i]= 'yes' 23 | end 24 | end 25 | end 26 | -- Loop through array 27 | for i =1, keySize do 28 | -- if is no ,The lock information is stored 29 | if(array[i] == 'no') 30 | then 31 | -- set xid 32 | redis.call('HSET',KEYS[i],'xid',ARGV[3]); 33 | -- set transactionId 34 | redis.call('HSET',KEYS[i],'transactionId',ARGV[(i-1)*6+4]); 35 | -- set branchId 36 | redis.call('HSET',KEYS[i],'branchId',ARGV[(i-1)*6+5]); 37 | -- set resourceId 38 | redis.call('HSET',KEYS[i],'resourceId',ARGV[(i-1)*6+6]); 39 | -- set tableName 40 | redis.call('HSET',KEYS[i],'tableName',ARGV[(i-1)*6+7]); 41 | -- set rowKey 42 | redis.call('HSET',KEYS[i],'rowKey',ARGV[(i-1)*6+8]); 43 | -- set pk 44 | redis.call('HSET',KEYS[i],'pk',ARGV[(i-1)*6+9]); 45 | -- exit if 46 | end 47 | -- exit for 48 | end 49 | -- set SEATA_GLOBAL_LOCK 50 | redis.call('HSET',KEYS[(keySize+1)],KEYS[(keySize+2)],ARGV[(argSize+0)]); 51 | -- return success 52 | return ARGV[3] 53 | -------------------------------------------------------------------------------- /初识sed和gawk/sed编辑器基础.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #sed编辑器基础 3 | 4 | #替换标记 5 | sed 's/lazy/ht/' ./test 6 | 7 | echo -e "next\n" 8 | 9 | #可用的替换标记 10 | #1.数字 表明新闻本将替换第几处模式匹配的地方 11 | sed 's/lazy/ht/2' ./test 12 | #2.g 表明新文件将会替换所有已有文本出现的地方 13 | sed 's/lazy/ht/g' ./test 14 | #3.p 表明原来行的内容要打印出来,替换后的 15 | sed 's/lazy/ht/p' ./test 16 | #4.w file 将替换的结果写到文件中 17 | sed 's/lazy/ht/w test1' ./test 18 | 19 | echo -e "next\n" 20 | 21 | #替换字符 22 | sed 's/\/bin\/bash/\/bin\/csh/' /etc/passwd 23 | #或者 24 | sed 's!/bin/bash!/bin/csh!' /etc/passwd 25 | 26 | echo -e "next\n" 27 | 28 | #使用地址 29 | #1.数字方式的行寻址 30 | sed '2s/lazy/cat/' ./test 31 | sed '2,3s/lazy/cat/' ./test 32 | sed '2,$s/lazy/cat/' ./test 33 | #2.使用文本模式过滤器 34 | sed '/tiandi/s/bash/csh/' /etc/passwd 35 | 36 | echo -e "next\n" 37 | 38 | #组合命令 39 | sed '2{ 40 | s/fox/elephant/ 41 | s/dog/cat/ 42 | }' test 43 | sed '2,${ 44 | s/fox/elephant/ 45 | s/dog/cat/ 46 | }' test 47 | 48 | echo -e "next\n" 49 | 50 | #删除行 51 | sed '3d' ./test 52 | sed '2,$d' ./test 53 | sed '/number 1/d' ./test 54 | #删除两个文本模式来删除某个范围的行,第一个开启删除功能,第二个关闭删除功能 55 | sed '/1/,/3/d' ./test 56 | 57 | echo -e "next\n" 58 | 59 | #插入和附加文本 60 | sed '3i\ 61 | This is an appended line.' ./test 62 | 63 | sed '$a\ 64 | This is a new line of text.' ./test 65 | 66 | #修改行 67 | sed '3c\ 68 | This a changed line of text.' ./test 69 | sed '/number 1/c\ 70 | This a changed line of text.' ./test 71 | #替换两行文本 72 | #sed '2,3c\ 73 | #This a changed line of text.' ./test 74 | 75 | #转换命令,处理单个字符 76 | #sed 'y/123/789/' ./test 77 | 78 | echo -e "next\n" 79 | 80 | #回顾打印 81 | # p 打印文本行 82 | # -n 禁止其他行,只打印包含匹配文本模式的行 83 | sed -n '/number 3/p' ./test 84 | 85 | #查看修改之前的行和修改之后的行 86 | #sed -n '/3/{ 87 | #p 88 | #s/line/test/p 89 | #}' ./test 90 | 91 | echo -e "next\n" 92 | 93 | # 打印行号 94 | sed '=' ./test 95 | 96 | #打印指定的行和行号 97 | #sed -n '/lazy/{ 98 | #= 99 | #p 100 | #}' ./test 101 | 102 | #列出行 打印数据流中的文本和不可打印的ASCII字符,任何不可打印的字符都用它们的八进制值前加一个反斜线或标准C风格的命名法,比如用\t来代表制表符 103 | sed -n 'l' ./test 104 | 105 | -------------------------------------------------------------------------------- /脚本实用工具/Hourly_Archive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Hourly_Archive - Every hour create an archive 4 | ###################################################### 5 | # 6 | # Set Configuration and Destination File 7 | # 8 | CONFIG_FILE=/home/tiandi/archive/Files_To_Backup 9 | # 10 | # Gather Current Date,Month & Time 11 | # 12 | DAY=`date +%d` 13 | MONTH=`date +%m` 14 | TIME=`date +%k%M` 15 | # 16 | # Set Base Archive Destination Location 17 | # 18 | BASEDEST=/home/tiandi/archive/hourly 19 | # 20 | # Create Archive Destination Directory 21 | mkdir -p $BASEDEST/$MONTH/$DAY 22 | # 23 | # Build Archive Destination File Name 24 | DESTINATION=$BASEDEST/$MONTH/$DAY/archive$TIME.tar.gz 25 | # 26 | ##################### Main Script ############### 27 | # 28 | # Check Backup Config file exists 29 | # 30 | if [ -f $CONFIG_FILE ] #Make sure the config file still exists 31 | then 32 | echo 33 | else 34 | echo 35 | echo "$CONFIG_FILE does not exist." 36 | echo "Backup not completed due to missing Configuration file" 37 | echo 38 | exit 39 | fi 40 | # 41 | # Build the names of all the files to backup 42 | # 43 | FILE_NO=1 # Start on Line 1 of Config file. 44 | exec < $CONFIG_FILE # Redirect Std Input to name of Config File 45 | # 46 | read FILE_NAME # Read 1st record 47 | # 48 | while [ $? -eq 0 ] 49 | do 50 | # Make sure the file or directory exists. 51 | if [ -f $FILE_NAME -o -d $FILE_NAME ] 52 | then 53 | # If file exists, add its name to the lists 54 | FILE_LIST="$FILE_LIST $FILE_NAME" 55 | else 56 | # If file doesn't exist, issue warning 57 | echo 58 | echo "$FILE_NAME, does not exist." 59 | echo "Obviously, I will not include it in this archive." 60 | echo "It is listed on line $FILE_NO of the config file." 61 | echo "Continuing to build archive file." 62 | echo 63 | fi 64 | # 65 | FILE_NO=$[ $FILE_NO + 1 ] # Increase Line/File number by one 66 | read FILE_NAME # Read next record. 67 | done 68 | ########################################################### 69 | # 70 | # Backup the files and Compress Archive 71 | # 72 | tar -czf $DESTINATION $FILE_LIST 2> /dev/null 73 | # 74 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/conf.d/prod_ssl_443.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 443 ssl; 3 | 4 | server_name tangyh.top; 5 | root html; 6 | index index.html index.htm; 7 | ssl_certificate ../ssl/tangyh.top.crt; 8 | ssl_certificate_key ../ssl/tangyh.top.key; 9 | ssl_session_timeout 5m; 10 | ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 11 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 12 | ssl_prefer_server_ciphers on; 13 | 14 | underscores_in_headers on; 15 | 16 | # 网关 17 | location /api { 18 | proxy_pass http://172.30.30.195:8760/api; 19 | 20 | # https + web socket 配置 21 | proxy_http_version 1.1; 22 | proxy_set_header Upgrade $http_upgrade; 23 | proxy_set_header Connection "upgrade"; 24 | proxy_set_header Host $host:$server_port; 25 | proxy_redirect off; 26 | proxy_set_header X-Real-IP $remote_addr; 27 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 28 | proxy_connect_timeout 60; 29 | proxy_read_timeout 600; 30 | proxy_send_timeout 600; 31 | } 32 | 33 | # 文件访问配置 34 | location ^~ /file { 35 | if ($request_uri ~* ^.*\/(.*)\.(apk|java|txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|jpg|png)(\?fileName=([^&]+))$) { 36 | add_header Content-Disposition "attachment;filename=$arg_attname"; 37 | } 38 | root /data_prod/uploadfile; 39 | index index.html; 40 | } 41 | 42 | # 前端 43 | location /lamp-web { 44 | root /data_prod/webapp/; 45 | index index.html; 46 | } 47 | 48 | # 前端 49 | location ^~ / { 50 | # 不缓存html,防止程序更新后缓存继续生效 51 | if ($request_filename ~* .*\.(?:htm|html)$) { 52 | add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate"; 53 | access_log on; 54 | } 55 | root /data_prod/webapp/lamp-web-plus; 56 | index index.html index.htm; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shell脚本编程进阶/问题跟踪数据库/Update_Problem.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Update_Problem - updates problem record in database 4 | # 5 | ############################################################ 6 | # 7 | # Determine sql location & set variable 8 | # 9 | MYSQL=`which mysql`" Problem_Trek -u root" 10 | # 11 | ############################################################## 12 | # 13 | # Obtain Record Id 14 | # 15 | if [ $# -eq 0 ] # Check if id number was passed 16 | then # If not passed ask for it 17 | # 18 | # Check if any unfinished records exist. 19 | RECORDS_EXIST=`$MYSQL -Bse 'SELECT id_number FROM problem_logger where fixed_date="0000-00-00" OR prob_solutions=""'` 20 | # 21 | if [ "$RECORDS_EXIST" != "" ] 22 | then 23 | echo 24 | echo "The following record(s) need updating..." 25 | $MYSQL < 2 | 17 | 18 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | { 29 | "@timestamp": "%d{yyyy-MM-dd HH:mm:ss.SSS}", 30 | "level":"%p", 31 | "app_name":"${APPLICATION_NAME:-seata-server}", 32 | "PORT": ${RPC_PORT:-0}, 33 | "thread_name": "%t", 34 | "logger_name": "%logger", 35 | "X-TX-XID": "%X{X-TX-XID:-}", 36 | "X-TX-BRANCH-ID": "%X{X-TX-BRANCH-ID:-}", 37 | "message": "%m", 38 | "stack_trace": "%wex" 39 | } 40 | 41 | 42 | ${KAFKA_TOPIC} 43 | 44 | 45 | bootstrap.servers=${KAFKA_BOOTSTRAP_SERVERS} 46 | acks=0 47 | linger.ms=1000 48 | max.block.ms=0 49 | 50 | 51 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/logback/logstash-appender.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | ${LOGSTASH_DESTINATION} 26 | 27 | 28 | 29 | 30 | 31 | { 32 | "app_name": "${APPLICATION_NAME:-seata-server}" 33 | } 34 | 35 | 36 | 37 | net.logstash.logback.composite.LogstashVersionJsonProvider 38 | 39 | net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider 40 | net.logstash.logback.composite.loggingevent.TagsJsonProvider 41 | net.logstash.logback.composite.loggingevent.LogstashMarkersJsonProvider 42 | net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /shell脚本编程进阶/系统快照报告.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Snapshot_Stats - produces a report for system stats 4 | # 5 | ############################################## 6 | # 7 | # Set Script Variables 8 | # 9 | DATE=`date +%m%d%y` 10 | DISKS_TO_MONITOR="/dev/sda1" 11 | MAIL=`which mutt` 12 | MAIL_TO=tiandi 13 | REPORT=/home/tiandi/Documents/Snapshot_Stats_$DATE.rpt 14 | # 15 | #################################################### 16 | # 17 | # Create Report File 18 | # 19 | exec 3>&1 # Save file descriptor 20 | # 21 | exec 1> $REPORT # direct output to rpt file 22 | # 23 | ################################################### 24 | # 25 | echo 26 | echo -e "\t\tDaily System Report" 27 | echo 28 | # 29 | ################################################### 30 | # Date Stamp the Report 31 | # 32 | echo -e "Today is" `date +%m%d%y` 33 | echo 34 | # 35 | ################################################## 36 | # 37 | #1) Gather System Uptime Statistics 38 | # 39 | echo -e "System has been \c" 40 | uptime | sed -n '/,/s/,/ /gp' | gawk '{if($4 == "days" || $4 == "day") {print $2,$3,$4,$5} else {print $2,$3}}' 41 | # 42 | ################################################# 43 | # 44 | #2) Gather Disk Usage Statistics 45 | # 46 | echo 47 | for DISK in $DISK_TO_MONITOR # loop to check disk space 48 | do 49 | echo -e "$DISK usage: \c" 50 | df -h $DISK | sed -n '/% \//p' | gawk '{ print $5 }' 51 | done 52 | # 53 | ################################################################## 54 | # 55 | #3) Gather Memory Usage Statstics 56 | # 57 | echo 58 | echo -e "Memory Usage: \c" 59 | # 60 | free | sed -n '2p' | gawk 'x = int(($3 / $2) * 100) {print x}' | sed 's/$/%/' 61 | # 62 | ############################################################### 63 | # 64 | #4) Gather Number of Zombie Processes 65 | # 66 | echo 67 | ZOMBIE_CHECK=`ps -al | gawk '{print $2,$4}' | grep Z` 68 | # 69 | if [ "$ZOMBIE_CHECK" = "" ] 70 | then 71 | echo "No Zombie Process on System at this Time" 72 | else 73 | echo "Current System Zombie Processes" 74 | ps -al | gawk '{print $2,$4}' | grep Z 75 | fi 76 | echo 77 | # 78 | ##################################################################### 79 | # 80 | # Restore File Descriptor & Mail Report 81 | # 82 | exec 1>&3 # Restore output to STDOUT 83 | # 84 | #$MAIL -a $REPORT -s "System Sstatistics Report for $DATE" 85 | #-- $MAIL_TO < /dev/null 86 | # 87 | ############################################################### 88 | # 89 | # Clean up 90 | # 91 | #rm -f $REPORT 92 | # 93 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/koi-win: -------------------------------------------------------------------------------- 1 | 2 | charset_map koi8-r windows-1251 { 3 | 4 | 80 88 ; # euro 5 | 6 | 95 95 ; # bullet 7 | 8 | 9A A0 ; #   9 | 10 | 9E B7 ; # · 11 | 12 | A3 B8 ; # small yo 13 | A4 BA ; # small Ukrainian ye 14 | 15 | A6 B3 ; # small Ukrainian i 16 | A7 BF ; # small Ukrainian yi 17 | 18 | AD B4 ; # small Ukrainian soft g 19 | AE A2 ; # small Byelorussian short u 20 | 21 | B0 B0 ; # ° 22 | 23 | B3 A8 ; # capital YO 24 | B4 AA ; # capital Ukrainian YE 25 | 26 | B6 B2 ; # capital Ukrainian I 27 | B7 AF ; # capital Ukrainian YI 28 | 29 | B9 B9 ; # numero sign 30 | 31 | BD A5 ; # capital Ukrainian soft G 32 | BE A1 ; # capital Byelorussian short U 33 | 34 | BF A9 ; # (C) 35 | 36 | C0 FE ; # small yu 37 | C1 E0 ; # small a 38 | C2 E1 ; # small b 39 | C3 F6 ; # small ts 40 | C4 E4 ; # small d 41 | C5 E5 ; # small ye 42 | C6 F4 ; # small f 43 | C7 E3 ; # small g 44 | C8 F5 ; # small kh 45 | C9 E8 ; # small i 46 | CA E9 ; # small j 47 | CB EA ; # small k 48 | CC EB ; # small l 49 | CD EC ; # small m 50 | CE ED ; # small n 51 | CF EE ; # small o 52 | 53 | D0 EF ; # small p 54 | D1 FF ; # small ya 55 | D2 F0 ; # small r 56 | D3 F1 ; # small s 57 | D4 F2 ; # small t 58 | D5 F3 ; # small u 59 | D6 E6 ; # small zh 60 | D7 E2 ; # small v 61 | D8 FC ; # small soft sign 62 | D9 FB ; # small y 63 | DA E7 ; # small z 64 | DB F8 ; # small sh 65 | DC FD ; # small e 66 | DD F9 ; # small shch 67 | DE F7 ; # small ch 68 | DF FA ; # small hard sign 69 | 70 | E0 DE ; # capital YU 71 | E1 C0 ; # capital A 72 | E2 C1 ; # capital B 73 | E3 D6 ; # capital TS 74 | E4 C4 ; # capital D 75 | E5 C5 ; # capital YE 76 | E6 D4 ; # capital F 77 | E7 C3 ; # capital G 78 | E8 D5 ; # capital KH 79 | E9 C8 ; # capital I 80 | EA C9 ; # capital J 81 | EB CA ; # capital K 82 | EC CB ; # capital L 83 | ED CC ; # capital M 84 | EE CD ; # capital N 85 | EF CE ; # capital O 86 | 87 | F0 CF ; # capital P 88 | F1 DF ; # capital YA 89 | F2 D0 ; # capital R 90 | F3 D1 ; # capital S 91 | F4 D2 ; # capital T 92 | F5 D3 ; # capital U 93 | F6 C6 ; # capital ZH 94 | F7 C2 ; # capital V 95 | F8 DC ; # capital soft sign 96 | F9 DB ; # capital Y 97 | FA C7 ; # capital Z 98 | FB D8 ; # capital SH 99 | FC DD ; # capital E 100 | FD D9 ; # capital SHCH 101 | FE D7 ; # capital CH 102 | FF DA ; # capital hard sign 103 | } 104 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2019 Seata.io Group. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | server: 16 | port: 7091 17 | 18 | spring: 19 | application: 20 | name: seata-server 21 | 22 | logging: 23 | config: classpath:logback-spring.xml 24 | file: 25 | path: ${user.home}/logs/seata 26 | extend: 27 | logstash-appender: 28 | destination: 127.0.0.1:4560 29 | kafka-appender: 30 | bootstrap-servers: 127.0.0.1:9092 31 | topic: logback_to_logstash 32 | 33 | console: 34 | user: 35 | username: seata 36 | password: seata 37 | seata: 38 | config: 39 | # support: nacos, consul, apollo, zk, etcd3 40 | type: nacos 41 | nacos: 42 | application: seata-server 43 | server-addr: 127.0.0.1:8848 44 | group: SEATA_GROUP 45 | namespace: 5b51e46a-4aeb-4d40-8398-8a9d33e2f0ad 46 | cluster: default 47 | username: nacos 48 | password: nacos 49 | context-path: 50 | registry: 51 | # support: nacos, eureka, redis, zk, consul, etcd3, sofa 52 | type: nacos 53 | nacos: 54 | application: seata-server 55 | server-addr: 127.0.0.1:8848 56 | group: SEATA_GROUP 57 | namespace: 5b51e46a-4aeb-4d40-8398-8a9d33e2f0ad 58 | cluster: default 59 | username: nacos 60 | password: nacos 61 | context-path: 62 | store: 63 | # support: file 、 db 、 redis 64 | mode: db 65 | db: 66 | datasource: druid 67 | db-type: mysql 68 | driver-class-name: com.mysql.jdbc.Driver 69 | url: jdbc:mysql://127.0.0.1:3306/lamp_seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=GMT 70 | user: root 71 | password: root 72 | min-conn: 10 73 | max-conn: 100 74 | global-table: global_table 75 | branch-table: branch_table 76 | lock-table: lock_table 77 | distributed-lock-table: distributed_lock 78 | query-limit: 1000 79 | max-wait: 5000 80 | # server: 81 | # service-port: 8091 #If not configured, the default is '${server.port} + 1000' 82 | security: 83 | secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 84 | tokenValidityInMilliseconds: 1800000 85 | ignore: 86 | urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login 87 | -------------------------------------------------------------------------------- /网络限流/随机限流.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 日志文件路径 4 | #LOG_FILE="/path/to/log_file.log" 5 | 6 | # 要限速的端口 7 | TARGET_PORT="9090" 8 | # 计数器变量 9 | counter=10 10 | CONDIATION_NUMBER=11 11 | EXECUTE_NUMBER=3 12 | # 函数:设置流量限速 13 | setup_traffic_limit() { 14 | # 监听特定端口的TCP连接,并动态应用流量限制 15 | echo "开始执行限流函数" 16 | tcpdump -i ens33 "tcp[tcpflags] & (tcp-syn) != 0 and port $TARGET_PORT" -n -l | 17 | while read -r line; do 18 | # 生成随机数(0到100之间的随机数) 19 | RANDOM_NUMBER=$((RANDOM % 100)) 20 | EXECUTE_NUMBER=$((RANDOM % 1000)) 21 | # 如果计数器小于阈值,则递增计数器,不执行限流的逻辑 22 | if [ "$counter" -lt $CONDIATION_NUMBER ]; then 23 | echo "延迟等待,当前计数器为: $counter 阈值为: $CONDIATION_NUMBER" 24 | ((counter++)) 25 | else 26 | # 如果随机数小于85(假设85%的概率),则执行限速 27 | if [ "$RANDOM_NUMBER" -lt 85 ]; then 28 | # 在日志文件中记录限速已启用 29 | #echo "$(date): Traffic limit is enabled for port $TARGET_PORT." >> "$LOG_FILE" 30 | # 在这里执行设置流量限速的操作,可以调用之前示例中的流量限速设置部分 31 | # Your traffic shaping commands here... 32 | SRC_IP=$(echo "$line" | awk '{print $3}' | cut -d. -f1-4) # 提取源IP 33 | SRC_PORT=$(echo "$line" | awk '{print $3}' | cut -d. -f5) # 提取源端口 34 | # 动态应用流量限制 35 | tc qdisc add dev ens33 root handle 1: htb default 12 36 | #主类别最大限制mbit/kbit 37 | tc class add dev ens33 parent 1: classid 1:1 htb rate 200kbit burst 15k 38 | #子类别最小和最大限制 39 | tc class add dev ens33 parent 1:1 classid 1:12 htb rate 20kbit ceil 100kbit burst 15k 40 | iptables -A OUTPUT -p tcp --sport $SRC_PORT -j MARK --set-mark 1 41 | 42 | echo "生成的随机数为:$RANDOM_NUMBER 限流成功,计数器为: $counter 阈值为:$CONDIATION_NUMBER 加权值为:$EXECUTE_NUMBER" 43 | #小于15的时候解除限流 44 | if [ "$RANDOM_NUMBER" -lt 15 ] && [ "$((EXECUTE_NUMBER % 6))" -eq 0 ]; then 45 | CONDIATION_NUMBER=$(((RANDOM % 50)+1)) 46 | echo "重新生成延迟等待计数器阈值: $CONDIATION_NUMBER" 47 | clear_traffic_limit 48 | fi 49 | #else 50 | # 在日志文件中记录未应用限速 51 | #echo "$(date): No traffic limit is applied for port $TARGET_PORT." >> "$LOG_FILE" 52 | fi 53 | fi 54 | done 55 | } 56 | 57 | # 函数:清除流量限速设置 58 | clear_traffic_limit() { 59 | # 在成功清除限速后,将计数器重置为0 60 | counter=0 61 | echo "执行清除限流的操作,客户端目标IP:$SRC_IP $SRC_PORT" 62 | iptables -D OUTPUT -p tcp --sport $TARGET_PORT -j MARK --set-mark 1 63 | ip rule del fwmark 1 table 1 64 | tc qdisc del dev ens33 root 65 | echo "Traffic limit for src port $TARGET_PORT is enabled for this connection." 66 | } 67 | 68 | 69 | clear_traffic_limit # 确保 clear_traffic_limit 在 setup_traffic_limit 之前调用 70 | 71 | setup_traffic_limit # 调用设置流量限速的函数 72 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/koi-utf: -------------------------------------------------------------------------------- 1 | 2 | # This map is not a full koi8-r <> utf8 map: it does not contain 3 | # box-drawing and some other characters. Besides this map contains 4 | # several koi8-u and Byelorussian letters which are not in koi8-r. 5 | # If you need a full and standard map, use contrib/unicode2nginx/koi-utf 6 | # map instead. 7 | 8 | charset_map koi8-r utf-8 { 9 | 10 | 80 E282AC ; # euro 11 | 12 | 95 E280A2 ; # bullet 13 | 14 | 9A C2A0 ; #   15 | 16 | 9E C2B7 ; # · 17 | 18 | A3 D191 ; # small yo 19 | A4 D194 ; # small Ukrainian ye 20 | 21 | A6 D196 ; # small Ukrainian i 22 | A7 D197 ; # small Ukrainian yi 23 | 24 | AD D291 ; # small Ukrainian soft g 25 | AE D19E ; # small Byelorussian short u 26 | 27 | B0 C2B0 ; # ° 28 | 29 | B3 D081 ; # capital YO 30 | B4 D084 ; # capital Ukrainian YE 31 | 32 | B6 D086 ; # capital Ukrainian I 33 | B7 D087 ; # capital Ukrainian YI 34 | 35 | B9 E28496 ; # numero sign 36 | 37 | BD D290 ; # capital Ukrainian soft G 38 | BE D18E ; # capital Byelorussian short U 39 | 40 | BF C2A9 ; # (C) 41 | 42 | C0 D18E ; # small yu 43 | C1 D0B0 ; # small a 44 | C2 D0B1 ; # small b 45 | C3 D186 ; # small ts 46 | C4 D0B4 ; # small d 47 | C5 D0B5 ; # small ye 48 | C6 D184 ; # small f 49 | C7 D0B3 ; # small g 50 | C8 D185 ; # small kh 51 | C9 D0B8 ; # small i 52 | CA D0B9 ; # small j 53 | CB D0BA ; # small k 54 | CC D0BB ; # small l 55 | CD D0BC ; # small m 56 | CE D0BD ; # small n 57 | CF D0BE ; # small o 58 | 59 | D0 D0BF ; # small p 60 | D1 D18F ; # small ya 61 | D2 D180 ; # small r 62 | D3 D181 ; # small s 63 | D4 D182 ; # small t 64 | D5 D183 ; # small u 65 | D6 D0B6 ; # small zh 66 | D7 D0B2 ; # small v 67 | D8 D18C ; # small soft sign 68 | D9 D18B ; # small y 69 | DA D0B7 ; # small z 70 | DB D188 ; # small sh 71 | DC D18D ; # small e 72 | DD D189 ; # small shch 73 | DE D187 ; # small ch 74 | DF D18A ; # small hard sign 75 | 76 | E0 D0AE ; # capital YU 77 | E1 D090 ; # capital A 78 | E2 D091 ; # capital B 79 | E3 D0A6 ; # capital TS 80 | E4 D094 ; # capital D 81 | E5 D095 ; # capital YE 82 | E6 D0A4 ; # capital F 83 | E7 D093 ; # capital G 84 | E8 D0A5 ; # capital KH 85 | E9 D098 ; # capital I 86 | EA D099 ; # capital J 87 | EB D09A ; # capital K 88 | EC D09B ; # capital L 89 | ED D09C ; # capital M 90 | EE D09D ; # capital N 91 | EF D09E ; # capital O 92 | 93 | F0 D09F ; # capital P 94 | F1 D0AF ; # capital YA 95 | F2 D0A0 ; # capital R 96 | F3 D0A1 ; # capital S 97 | F4 D0A2 ; # capital T 98 | F5 D0A3 ; # capital U 99 | F6 D096 ; # capital ZH 100 | F7 D092 ; # capital V 101 | F8 D0AC ; # capital soft sign 102 | F9 D0AB ; # capital Y 103 | FA D097 ; # capital Z 104 | FB D0A8 ; # capital SH 105 | FC D0AD ; # capital E 106 | FD D0A9 ; # capital SHCH 107 | FE D0A7 ; # capital CH 108 | FF D0AA ; # capital hard sign 109 | } 110 | -------------------------------------------------------------------------------- /Docker安装脚本/xxFileView/application.properties: -------------------------------------------------------------------------------- 1 | #######################################不可动态配置,需要重启生效####################################### 2 | server.port=${KK_SERVER_PORT:8012} 3 | server.context-path=${KK_CONTEXT_PATH:/} 4 | spring.http.encoding.charset=utf8 5 | ## Freemarker 配置 6 | spring.freemarker.template-loader-path=classpath:/web/ 7 | spring.freemarker.cache=false 8 | spring.freemarker.charset=UTF-8 9 | spring.freemarker.check-template-location=true 10 | spring.freemarker.content-type=text/html 11 | spring.freemarker.expose-request-attributes=true 12 | spring.freemarker.expose-session-attributes=true 13 | spring.freemarker.request-context-attribute=request 14 | spring.freemarker.suffix=.ftl 15 | server.tomcat.uri-encoding=UTF-8 16 | #文件上传限制 17 | spring.http.multipart.max-request-size=500MB 18 | spring.http.multipart.max-file-size=500MB 19 | #文件资源路径(默认为打包根路径下的file目录下) 20 | #file.dir = D:\\kkFileview\\ 21 | file.dir=${KK_FILE_DIR:default} 22 | #openoffice home路径 23 | #office.home = C:\\Program Files (x86)\\OpenOffice 4 24 | office.home=${KK_OFFICE_HOME:default} 25 | #缓存实现类型,不配默认为内嵌RocksDB(type = default)实现,可配置为redis(type = redis)实现(需要配置spring.redisson.address等参数)和 JDK 内置对象实现(type = jdk), 26 | cache.type=${KK_CACHE_TYPE:jdk} 27 | #redis连接,只有当cache.type = redis时才有用 28 | spring.redisson.address=${KK_SPRING_REDISSON_ADDRESS:127.0.0.1:6379} 29 | spring.redisson.password=${KK_SPRING_REDISSON_PASSWORD:123456} 30 | #缓存是否自动清理 true 为开启,注释掉或其他值都为关闭 31 | cache.clean.enabled=${KK_CACHE_CLEAN_ENABLED:true} 32 | #缓存自动清理时间,cache.clean.enabled = true时才有用,cron表达式,基于Quartz cron 33 | cache.clean.cron=${KK_CACHE_CLEAN_CRON:0 0 3 * * ?} 34 | #######################################可在运行时动态配置####################################### 35 | #提供预览服务的地址,默认从请求url读,如果使用nginx等反向代理,需要手动设置 36 | #base.url = https://file.keking.cn 37 | base.url=${KK_BASE_URL:default} 38 | #信任站点,多个用','隔开,设置了之后,会限制只能预览来自信任站点列表的文件,默认不限制 39 | #trust.host = file.keking.cn,kkfileview.keking.cn 40 | trust.host=${KK_TRUST_HOST:default} 41 | #是否启用缓存 42 | cache.enabled=${KK_CACHE_ENABLED:true} 43 | #文本类型,默认如下,可自定义添加 44 | simText=${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd} 45 | #多媒体类型,默认如下,可自定义添加 46 | media=${KK_MEDIA:mp3,wav,mp4,flv} 47 | #office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换) 48 | office.preview.type=${KK_OFFICE_PREVIEW_TYPE:image} 49 | #是否关闭office预览切换开关,默认为false,可配置为true关闭 50 | office.preview.switch.disabled=${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false} 51 | #是否禁止下载转换生成的pdf文件 52 | pdf.download.disable=${KK_PDF_DOWNLOAD_DISABLE:true} 53 | #预览源为FTP时 FTP用户名,可在ftp url后面加参数ftp.username=ftpuser指定,不指定默认用配置的 54 | ftp.username=${KK_FTP_USERNAME:ftpuser} 55 | #预览源为FTP时 FTP密码,可在ftp url后面加参数ftp.password=123456指定,不指定默认用配置的 56 | ftp.password=${KK_FTP_PASSWORD:123456} 57 | #预览源为FTP时, FTP连接默认ControlEncoding(根据FTP服务器操作系统选择,Linux一般为UTF-8,Windows一般为GBK),可在ftp url后面加参数ftp.control.encoding=UTF-8指定,不指定默认用配置的 58 | ftp.control.encoding=${KK_FTP_CONTROL_ENCODING:UTF-8} 59 | #水印内容 60 | #例:watermark.txt = ${WATERMARK_TXT:凯京科技内部文件,严禁外泄} 61 | #如需取消水印,内容设置为空即可,例:watermark.txt = ${WATERMARK_TXT:} 62 | watermark.txt=${WATERMARK_TXT:} 63 | #水印x轴间隔 64 | watermark.x.space=${WATERMARK_X_SPACE:10} 65 | #水印y轴间隔 66 | watermark.y.space=${WATERMARK_Y_SPACE:10} 67 | #水印字体 68 | watermark.font=${WATERMARK_FONT:微软雅黑} 69 | #水印字体大小 70 | watermark.fontsize=${WATERMARK_FONTSIZE:18px} 71 | #水印字体颜色 72 | watermark.color=${WATERMARK_COLOR:black} 73 | #水印透明度,要求设置在大于等于0.005,小于1 74 | watermark.alpha=${WATERMARK_ALPHA:0.2} 75 | #水印宽度 76 | watermark.width=${WATERMARK_WIDTH:180} 77 | #水印高度 78 | watermark.height=${WATERMARK_HEIGHT:80} 79 | #水印倾斜度数,要求设置在大于等于0,小于90 80 | watermark.angle=${WATERMARK_ANGLE:10} 81 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /脚本实用工具/install_grafana.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:grafana 5.1.0/5.1.5/5.2.2 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_grafana.log 12 | env_file=/etc/profile.d/grafana.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | 16 | clear 17 | echo "##########################################" 18 | echo "# #" 19 | echo "# 安装 grafana 5.1.0/5.1.5/5.2.2 #" 20 | echo "# #" 21 | echo "##########################################" 22 | echo "1: Install grafana 5.1.0" 23 | echo "2: Install grafana 5.1.5" 24 | echo "3: Install grafana 5.2.2" 25 | echo "4: EXIT" 26 | # 选择安装软件版本 27 | read -p "Please input your choice:" softversion 28 | if [ "${softversion}" == "1" ];then 29 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.1.0-1.x86_64.rpm" 30 | elif [ "${softversion}" == "2" ];then 31 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.1.5-1.x86_64.rpm" 32 | elif [ "${softversion}" == "3" ];then 33 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.2.2-1.x86_64.rpm" 34 | elif [ "${softversion}" == "4" ];then 35 | echo "you choce channel!" 36 | exit 1; 37 | else 38 | echo "input Error! Place input{1|2|3|4}" 39 | exit 0; 40 | fi 41 | 42 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 43 | output_msg() { 44 | for msg in $*;do 45 | action $msg /bin/true 46 | done 47 | } 48 | 49 | 50 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 51 | check_yum_command() { 52 | output_msg "命令检查:$1" 53 | hash $1 >/dev/null 2>&1 54 | if [ $? -eq 0 ];then 55 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 56 | else 57 | yum -y install $2 >/dev/null 2>&1 58 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 59 | fi 60 | } 61 | 62 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 63 | check_dir() { 64 | output_msg "目录检查" 65 | for dirname in $*;do 66 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 67 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 68 | done 69 | } 70 | 71 | # 下载文件并解压至安装目录,传入url链接地址 72 | download_file() { 73 | output_msg "下载源码包" 74 | mkdir -p $download_path 75 | for file in $*;do 76 | wget $file -c -P $download_path &> /dev/null 77 | if [ $? -eq 0 ];then 78 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 79 | else 80 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 81 | fi 82 | done 83 | } 84 | 85 | # 安装grafana插件,传入安装的插件的名称 86 | install_grafana_plugins() { 87 | output_msg "grafana插件安装" 88 | check_yum_command grafana-cli 89 | grafana-cli plugins install $* >/dev/null 90 | if [ $? -eq 0 ];then 91 | echo "`date +%F' '%H:%M:%S` grafana plugins $* install success!">>${install_log_path}${install_log_name} 92 | else 93 | echo "`date +%F' '%H:%M:%s` grafana plugins $* install success!">>${install_log_path}${install_log_name} && exit 1 94 | fi 95 | 96 | 97 | } 98 | 99 | main() { 100 | check_dir $install_log_path $install_path 101 | check_yum_command wget wget 102 | download_file $URL 103 | for filename in `ls $download_path`;do 104 | yum -y install $download_path$filename >/dev/null 2>&1 105 | done 106 | install_grafana_plugins alexanderzobnin-zabbix-app 107 | } 108 | 109 | main 110 | 111 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/win-utf: -------------------------------------------------------------------------------- 1 | 2 | # This map is not a full windows-1251 <> utf8 map: it does not 3 | # contain Serbian and Macedonian letters. If you need a full map, 4 | # use contrib/unicode2nginx/win-utf map instead. 5 | 6 | charset_map windows-1251 utf-8 { 7 | 8 | 82 E2809A ; # single low-9 quotation mark 9 | 10 | 84 E2809E ; # double low-9 quotation mark 11 | 85 E280A6 ; # ellipsis 12 | 86 E280A0 ; # dagger 13 | 87 E280A1 ; # double dagger 14 | 88 E282AC ; # euro 15 | 89 E280B0 ; # per mille 16 | 17 | 91 E28098 ; # left single quotation mark 18 | 92 E28099 ; # right single quotation mark 19 | 93 E2809C ; # left double quotation mark 20 | 94 E2809D ; # right double quotation mark 21 | 95 E280A2 ; # bullet 22 | 96 E28093 ; # en dash 23 | 97 E28094 ; # em dash 24 | 25 | 99 E284A2 ; # trade mark sign 26 | 27 | A0 C2A0 ; #   28 | A1 D18E ; # capital Byelorussian short U 29 | A2 D19E ; # small Byelorussian short u 30 | 31 | A4 C2A4 ; # currency sign 32 | A5 D290 ; # capital Ukrainian soft G 33 | A6 C2A6 ; # borken bar 34 | A7 C2A7 ; # section sign 35 | A8 D081 ; # capital YO 36 | A9 C2A9 ; # (C) 37 | AA D084 ; # capital Ukrainian YE 38 | AB C2AB ; # left-pointing double angle quotation mark 39 | AC C2AC ; # not sign 40 | AD C2AD ; # soft hypen 41 | AE C2AE ; # (R) 42 | AF D087 ; # capital Ukrainian YI 43 | 44 | B0 C2B0 ; # ° 45 | B1 C2B1 ; # plus-minus sign 46 | B2 D086 ; # capital Ukrainian I 47 | B3 D196 ; # small Ukrainian i 48 | B4 D291 ; # small Ukrainian soft g 49 | B5 C2B5 ; # micro sign 50 | B6 C2B6 ; # pilcrow sign 51 | B7 C2B7 ; # · 52 | B8 D191 ; # small yo 53 | B9 E28496 ; # numero sign 54 | BA D194 ; # small Ukrainian ye 55 | BB C2BB ; # right-pointing double angle quotation mark 56 | 57 | BF D197 ; # small Ukrainian yi 58 | 59 | C0 D090 ; # capital A 60 | C1 D091 ; # capital B 61 | C2 D092 ; # capital V 62 | C3 D093 ; # capital G 63 | C4 D094 ; # capital D 64 | C5 D095 ; # capital YE 65 | C6 D096 ; # capital ZH 66 | C7 D097 ; # capital Z 67 | C8 D098 ; # capital I 68 | C9 D099 ; # capital J 69 | CA D09A ; # capital K 70 | CB D09B ; # capital L 71 | CC D09C ; # capital M 72 | CD D09D ; # capital N 73 | CE D09E ; # capital O 74 | CF D09F ; # capital P 75 | 76 | D0 D0A0 ; # capital R 77 | D1 D0A1 ; # capital S 78 | D2 D0A2 ; # capital T 79 | D3 D0A3 ; # capital U 80 | D4 D0A4 ; # capital F 81 | D5 D0A5 ; # capital KH 82 | D6 D0A6 ; # capital TS 83 | D7 D0A7 ; # capital CH 84 | D8 D0A8 ; # capital SH 85 | D9 D0A9 ; # capital SHCH 86 | DA D0AA ; # capital hard sign 87 | DB D0AB ; # capital Y 88 | DC D0AC ; # capital soft sign 89 | DD D0AD ; # capital E 90 | DE D0AE ; # capital YU 91 | DF D0AF ; # capital YA 92 | 93 | E0 D0B0 ; # small a 94 | E1 D0B1 ; # small b 95 | E2 D0B2 ; # small v 96 | E3 D0B3 ; # small g 97 | E4 D0B4 ; # small d 98 | E5 D0B5 ; # small ye 99 | E6 D0B6 ; # small zh 100 | E7 D0B7 ; # small z 101 | E8 D0B8 ; # small i 102 | E9 D0B9 ; # small j 103 | EA D0BA ; # small k 104 | EB D0BB ; # small l 105 | EC D0BC ; # small m 106 | ED D0BD ; # small n 107 | EE D0BE ; # small o 108 | EF D0BF ; # small p 109 | 110 | F0 D180 ; # small r 111 | F1 D181 ; # small s 112 | F2 D182 ; # small t 113 | F3 D183 ; # small u 114 | F4 D184 ; # small f 115 | F5 D185 ; # small kh 116 | F6 D186 ; # small ts 117 | F7 D187 ; # small ch 118 | F8 D188 ; # small sh 119 | F9 D189 ; # small shch 120 | FA D18A ; # small hard sign 121 | FB D18B ; # small y 122 | FC D18C ; # small soft sign 123 | FD D18D ; # small e 124 | FE D18E ; # small yu 125 | FF D18F ; # small ya 126 | } 127 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/logback/file-appender.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 22 | 24 | 25 | 26 | 27 | ${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.all.log 28 | true 29 | 30 | ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.all.%d{yyyy-MM-dd}.%i.log.gz 31 | 2GB 32 | 7 33 | 7GB 34 | true 35 | 36 | 37 | ${FILE_LOG_PATTERN} 38 | UTF-8 39 | 40 | 41 | 42 | 43 | 44 | 45 | WARN 46 | ACCEPT 47 | DENY 48 | 49 | ${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.warn.log 50 | true 51 | 52 | ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.warn.%d{yyyy-MM-dd}.%i.log.gz 53 | 2GB 54 | 7 55 | 7GB 56 | true 57 | 58 | 59 | ${FILE_LOG_PATTERN} 60 | UTF-8 61 | 62 | 63 | 64 | 65 | 66 | 67 | ERROR 68 | ACCEPT 69 | DENY 70 | 71 | ${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.error.log 72 | true 73 | 74 | ${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.error.%d{yyyy-MM-dd}.%i.log.gz 75 | 2GB 76 | 7 77 | 7GB 78 | true 79 | 80 | 81 | ${FILE_LOG_PATTERN} 82 | UTF-8 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Docker安装脚本/nginx/conf/mime.types: -------------------------------------------------------------------------------- 1 | 2 | types { 3 | text/html html htm shtml; 4 | text/css css; 5 | text/xml xml; 6 | image/gif gif; 7 | image/jpeg jpeg jpg; 8 | application/javascript js; 9 | application/atom+xml atom; 10 | application/rss+xml rss; 11 | 12 | text/mathml mml; 13 | text/plain txt; 14 | text/vnd.sun.j2me.app-descriptor jad; 15 | text/vnd.wap.wml wml; 16 | text/x-component htc; 17 | 18 | image/png png; 19 | image/tiff tif tiff; 20 | image/vnd.wap.wbmp wbmp; 21 | image/x-icon ico; 22 | image/x-jng jng; 23 | image/x-ms-bmp bmp; 24 | image/svg+xml svg svgz; 25 | image/webp webp; 26 | 27 | application/font-woff woff; 28 | application/java-archive jar war ear; 29 | application/json json; 30 | application/mac-binhex40 hqx; 31 | application/msword doc; 32 | application/pdf pdf; 33 | application/postscript ps eps ai; 34 | application/rtf rtf; 35 | application/vnd.apple.mpegurl m3u8; 36 | application/vnd.ms-excel xls; 37 | application/vnd.ms-fontobject eot; 38 | application/vnd.ms-powerpoint ppt; 39 | application/vnd.wap.wmlc wmlc; 40 | application/vnd.google-earth.kml+xml kml; 41 | application/vnd.google-earth.kmz kmz; 42 | application/x-7z-compressed 7z; 43 | application/x-cocoa cco; 44 | application/x-java-archive-diff jardiff; 45 | application/x-java-jnlp-file jnlp; 46 | application/x-makeself run; 47 | application/x-perl pl pm; 48 | application/x-pilot prc pdb; 49 | application/x-rar-compressed rar; 50 | application/x-redhat-package-manager rpm; 51 | application/x-sea sea; 52 | application/x-shockwave-flash swf; 53 | application/x-stuffit sit; 54 | application/x-tcl tcl tk; 55 | application/x-x509-ca-cert der pem crt; 56 | application/x-xpinstall xpi; 57 | application/xhtml+xml xhtml; 58 | application/xspf+xml xspf; 59 | application/zip zip; 60 | 61 | application/octet-stream bin exe dll; 62 | application/octet-stream deb; 63 | application/octet-stream dmg; 64 | application/octet-stream iso img; 65 | application/octet-stream msi msp msm; 66 | 67 | application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; 68 | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; 69 | application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; 70 | 71 | audio/midi mid midi kar; 72 | audio/mpeg mp3; 73 | audio/ogg ogg; 74 | audio/x-m4a m4a; 75 | audio/x-realaudio ra; 76 | 77 | video/3gpp 3gpp 3gp; 78 | video/mp2t ts; 79 | video/mp4 mp4; 80 | video/mpeg mpeg mpg; 81 | video/quicktime mov; 82 | video/webm webm; 83 | video/x-flv flv; 84 | video/x-m4v m4v; 85 | video/x-mng mng; 86 | video/x-ms-asf asx asf; 87 | video/x-ms-wmv wmv; 88 | video/x-msvideo avi; 89 | } 90 | -------------------------------------------------------------------------------- /脚本实用工具/install_maven.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:maven 3.0.5/3.3.9/3.5.4 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_maven.log 12 | env_file=/etc/profile.d/maven.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | #software_config_file=${install_path}filebeat/filebeat.yml 16 | 17 | clear 18 | echo "##########################################" 19 | echo "# #" 20 | echo "# 安装 maven 3.0.5/3.3.9/3.5.4 #" 21 | echo "# #" 22 | echo "##########################################" 23 | echo "1: Install maven 3.0.5" 24 | echo "2: Install maven 3.2.9" 25 | echo "3: Install maven 3.5.4" 26 | echo "4: EXIT" 27 | # 选择安装软件版本 28 | read -p "Please input your choice:" softversion 29 | if [ "${softversion}" == "1" ];then 30 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.0.5-bin.tar.gz" 31 | elif [ "${softversion}" == "2" ];then 32 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.3.9-bin.tar.gz" 33 | elif [ "${softversion}" == "3" ];then 34 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.5.4-bin.tar.gz" 35 | elif [ "${softversion}" == "4" ];then 36 | echo "you choce channel!" 37 | exit 1; 38 | else 39 | echo "input Error! Place input{1|2|3|4}" 40 | exit 0; 41 | fi 42 | 43 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 44 | output_msg() { 45 | for msg in $*;do 46 | action $msg /bin/true 47 | done 48 | } 49 | 50 | 51 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 52 | check_yum_command() { 53 | output_msg "命令检查:$1" 54 | hash $1 >/dev/null 2>&1 55 | if [ $? -eq 0 ];then 56 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 57 | else 58 | yum -y install $2 >/dev/null 2>&1 59 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 60 | fi 61 | } 62 | 63 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 64 | check_dir() { 65 | output_msg "目录检查" 66 | for dirname in $*;do 67 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 68 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 69 | done 70 | } 71 | 72 | # 下载文件并解压至安装目录,传入url链接地址 73 | download_file() { 74 | output_msg "下载源码包" 75 | mkdir -p $download_path 76 | for file in $*;do 77 | wget $file -c -P $download_path &> /dev/null 78 | if [ $? -eq 0 ];then 79 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 80 | else 81 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 82 | fi 83 | done 84 | } 85 | 86 | 87 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 88 | extract_file() { 89 | output_msg "解压源码" 90 | for file in $*;do 91 | if [ "${file##*.}" == "gz" ];then 92 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 93 | elif [ "${file##*.}" == "zip" ];then 94 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 95 | else 96 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 97 | fi 98 | done 99 | } 100 | 101 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 102 | config_env() { 103 | output_msg "环境变量配置" 104 | echo "export PATH=\$PATH:$1" >${env_file} 105 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 106 | 107 | } 108 | 109 | 110 | main() { 111 | check_dir $install_log_path $install_path 112 | check_yum_command wget wget 113 | download_file $URL 114 | 115 | software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'-bin.tar.gz' '{print $1}') 116 | for filename in `ls $download_path`;do 117 | extract_file ${download_path}$filename 118 | done 119 | rm -fr ${download_path} 120 | ln -s $install_path$software_name ${install_path}maven 121 | config_env ${install_path}maven/bin 122 | } 123 | 124 | main 125 | 126 | -------------------------------------------------------------------------------- /脚本实用工具/install_tomcat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:tomcat 6.0/7.0/8.5/9.0 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_tomcat.log 12 | env_file=/etc/profile.d/tomcat.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | 16 | clear 17 | echo "##########################################" 18 | echo "# #" 19 | echo "# 安装 tomcat 6.0/7.0/8.5/9.0 #" 20 | echo "# #" 21 | echo "##########################################" 22 | echo "1: Install tomcat-6.0" 23 | echo "2: Install tomcat-7.0" 24 | echo "3: Install tomcat-8.5" 25 | echo "4: Install tomcat-9.0" 26 | echo "5: EXIT" 27 | # 选择安装软件版本 28 | read -p "Please input your choice:" softversion 29 | if [ "${softversion}" == "1" ];then 30 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-6.0.9.zip" 31 | elif [ "${softversion}" == "2" ];then 32 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-7.0.79.zip" 33 | elif [ "${softversion}" == "3" ];then 34 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-8.5.20.zip" 35 | elif [ "${softversion}" == "4" ];then 36 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-9.0.0.M26.zip" 37 | elif [ "${softversion}" == "5" ];then 38 | echo "you choce channel!" 39 | exit 1; 40 | else 41 | echo "input Error! Place input{1|2|3|4|5}" 42 | exit 0; 43 | fi 44 | 45 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 46 | output_msg() { 47 | for msg in $*;do 48 | action $msg /bin/true 49 | done 50 | } 51 | 52 | 53 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 54 | check_yum_command() { 55 | output_msg "命令检查:$1" 56 | hash $1 >/dev/null 2>&1 57 | if [ $? -eq 0 ];then 58 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 59 | else 60 | yum -y install $2 >/dev/null 2>&1 61 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 62 | fi 63 | } 64 | 65 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 66 | check_dir() { 67 | output_msg "目录检查" 68 | for dirname in $*;do 69 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 70 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 71 | done 72 | } 73 | 74 | # 下载文件并解压至安装目录,传入url链接地址 75 | download_file() { 76 | output_msg "下载源码包" 77 | mkdir -p $download_path 78 | for file in $*;do 79 | wget $file -c -P $download_path &> /dev/null 80 | if [ $? -eq 0 ];then 81 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 82 | else 83 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 84 | fi 85 | done 86 | } 87 | 88 | 89 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 90 | extract_file() { 91 | output_msg "解压源码" 92 | for file in $*;do 93 | if [ "${file##*.}" == "gz" ];then 94 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 95 | elif [ "${file##*.}" == "zip" ];then 96 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 97 | else 98 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 99 | fi 100 | done 101 | } 102 | 103 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 104 | config_env() { 105 | output_msg "环境变量配置" 106 | echo "export PATH=\$PATH:$1" >${env_file} 107 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 108 | 109 | } 110 | 111 | main() { 112 | check_dir $install_log_path $install_path 113 | check_yum_command wget wget 114 | check_yum_command unzip unzip 115 | download_file $URL 116 | 117 | software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.zip' '{print $1}') 118 | for filename in `ls $download_path`;do 119 | extract_file ${download_path}$filename 120 | done 121 | rm -fr ${download_path} 122 | ln -s $install_path$software_name ${install_path}tomcat 123 | config_env ${install_path}tomcat/bin 124 | } 125 | 126 | main 127 | -------------------------------------------------------------------------------- /脚本实用工具/install_kibana.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:kibana 6.0.1/6.2.4/6.3.1 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_kibana.log 12 | env_file=/etc/profile.d/kibana.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | software_config_file=${install_path}kibana/config/kibana.yml 16 | 17 | clear 18 | echo "##########################################" 19 | echo "# #" 20 | echo "# 安装 kibana 6.0.1/6.2.4/6.3.1 #" 21 | echo "# #" 22 | echo "##########################################" 23 | echo "1: Install kibana 6.0.1" 24 | echo "2: Install kibana 6.2.4" 25 | echo "3: Install kibana 6.3.1" 26 | echo "4: EXIT" 27 | # 选择安装软件版本 28 | read -p "Please input your choice:" softversion 29 | if [ "${softversion}" == "1" ];then 30 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.0.1-linux-x86_64.tar.gz" 31 | elif [ "${softversion}" == "2" ];then 32 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.2.4-linux-x86_64.tar.gz" 33 | elif [ "${softversion}" == "3" ];then 34 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.3.1-linux-x86_64.tar.gz" 35 | elif [ "${softversion}" == "4" ];then 36 | echo "you choce channel!" 37 | exit 1; 38 | else 39 | echo "input Error! Place input{1|2|3|4}" 40 | exit 0; 41 | fi 42 | 43 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 44 | output_msg() { 45 | for msg in $*;do 46 | action $msg /bin/true 47 | done 48 | } 49 | 50 | 51 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 52 | check_yum_command() { 53 | output_msg "命令检查:$1" 54 | hash $1 >/dev/null 2>&1 55 | if [ $? -eq 0 ];then 56 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 57 | else 58 | yum -y install $2 >/dev/null 2>&1 59 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 60 | fi 61 | } 62 | 63 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 64 | check_dir() { 65 | output_msg "目录检查" 66 | for dirname in $*;do 67 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 68 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 69 | done 70 | } 71 | 72 | # 下载文件并解压至安装目录,传入url链接地址 73 | download_file() { 74 | output_msg "下载源码包" 75 | mkdir -p $download_path 76 | for file in $*;do 77 | wget $file -c -P $download_path &> /dev/null 78 | if [ $? -eq 0 ];then 79 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 80 | else 81 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 82 | fi 83 | done 84 | } 85 | 86 | 87 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 88 | extract_file() { 89 | output_msg "解压源码" 90 | for file in $*;do 91 | if [ "${file##*.}" == "gz" ];then 92 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 93 | elif [ "${file##*.}" == "zip" ];then 94 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 95 | else 96 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 97 | fi 98 | done 99 | } 100 | 101 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 102 | config_env() { 103 | output_msg "环境变量配置" 104 | echo "export PATH=\$PATH:$1" >${env_file} 105 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 106 | 107 | } 108 | 109 | # 添加配置文件 110 | add_config() { 111 | cat> $1 </dev/null 2>&1 55 | if [ $? -eq 0 ];then 56 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 57 | else 58 | yum -y install $2 >/dev/null 2>&1 59 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 60 | fi 61 | } 62 | 63 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 64 | check_dir() { 65 | output_msg "目录检查" 66 | for dirname in $*;do 67 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 68 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 69 | done 70 | } 71 | 72 | # 下载文件并解压至安装目录,传入url链接地址 73 | download_file() { 74 | output_msg "下载源码包" 75 | mkdir -p $download_path 76 | for file in $*;do 77 | wget $file -c -P $download_path &> /dev/null 78 | if [ $? -eq 0 ];then 79 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 80 | else 81 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 82 | fi 83 | done 84 | } 85 | 86 | 87 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 88 | extract_file() { 89 | output_msg "解压源码" 90 | for file in $*;do 91 | if [ "${file##*.}" == "gz" ];then 92 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 93 | elif [ "${file##*.}" == "zip" ];then 94 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 95 | else 96 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 97 | fi 98 | done 99 | } 100 | 101 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 102 | config_env() { 103 | output_msg "环境变量配置" 104 | echo "export PATH=\$PATH:$1" >${env_file} 105 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 106 | 107 | } 108 | 109 | # 添加配置文件 110 | add_config() { 111 | cat> $1 </dev/null 2>&1 55 | if [ $? -eq 0 ];then 56 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 57 | else 58 | yum -y install $2 >/dev/null 2>&1 59 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 60 | fi 61 | } 62 | 63 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 64 | check_dir() { 65 | output_msg "目录检查" 66 | for dirname in $*;do 67 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 68 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 69 | done 70 | } 71 | 72 | # 下载文件并解压至安装目录,传入url链接地址 73 | download_file() { 74 | output_msg "下载源码包" 75 | mkdir -p $download_path 76 | for file in $*;do 77 | wget $file -c -P $download_path &> /dev/null 78 | if [ $? -eq 0 ];then 79 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 80 | else 81 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 82 | fi 83 | done 84 | } 85 | 86 | 87 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 88 | extract_file() { 89 | output_msg "解压源码" 90 | for file in $*;do 91 | if [ "${file##*.}" == "gz" ];then 92 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 93 | elif [ "${file##*.}" == "zip" ];then 94 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 95 | else 96 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 97 | fi 98 | done 99 | } 100 | 101 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 102 | config_env() { 103 | output_msg "环境变量配置" 104 | echo "export PATH=\$PATH:$1" >${env_file} 105 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 106 | 107 | } 108 | 109 | # 添加配置文件 110 | add_config() { 111 | cat> $1 < "5044" 115 | } 116 | } 117 | output { 118 | elasticsearch { 119 | hosts => "127.0.0.1:9200" 120 | } 121 | stdout { codec => rubydebug } 122 | } 123 | EOF 124 | } 125 | 126 | main() { 127 | check_dir $install_log_path $install_path 128 | check_yum_command wget wget 129 | download_file $URL 130 | 131 | software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}') 132 | for filename in `ls $download_path`;do 133 | extract_file ${download_path}$filename 134 | done 135 | rm -fr ${download_path} 136 | ln -s $install_path$software_name ${install_path}logstash 137 | add_config ${software_config_file} 138 | config_env ${install_path}logstash/bin 139 | } 140 | 141 | main 142 | -------------------------------------------------------------------------------- /脚本实用工具/install_zookeeper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:zookeeper 3.4/3.5 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_zookeeper.log 12 | env_file=/etc/profile.d/zookeeper.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | software_config_file=${install_path}zookeeper/conf/zoo.cfg 16 | 17 | clear 18 | echo "##########################################" 19 | echo "# #" 20 | echo "# 安装 zookeeper 3.4/3.5 #" 21 | echo "# #" 22 | echo "##########################################" 23 | echo "1: Install zookeeper 3.4" 24 | echo "2: Install zookeeper 3.5" 25 | echo "3: EXIT" 26 | # 选择安装软件版本 27 | read -p "Please input your choice:" softversion 28 | if [ "${softversion}" == "1" ];then 29 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/zookeeper/zookeeper-3.4.12.tar.gz" 30 | elif [ "${softversion}" == "2" ];then 31 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/zookeeper/zookeeper-3.5.4-beta.tar.gz" 32 | elif [ "${softversion}" == "3" ];then 33 | echo "you choce channel!" 34 | exit 1; 35 | else 36 | echo "input Error! Place input{1|2|3}" 37 | exit 0; 38 | fi 39 | 40 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 41 | output_msg() { 42 | for msg in $*;do 43 | action $msg /bin/true 44 | done 45 | } 46 | 47 | 48 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 49 | check_yum_command() { 50 | output_msg "命令检查:$1" 51 | hash $1 >/dev/null 2>&1 52 | if [ $? -eq 0 ];then 53 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 54 | else 55 | yum -y install $2 >/dev/null 2>&1 56 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 57 | fi 58 | } 59 | 60 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 61 | check_dir() { 62 | output_msg "目录检查" 63 | for dirname in $*;do 64 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 65 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 66 | done 67 | } 68 | 69 | # 下载文件并解压至安装目录,传入url链接地址 70 | download_file() { 71 | output_msg "下载源码包" 72 | mkdir -p $download_path 73 | for file in $*;do 74 | wget $file -c -P $download_path &> /dev/null 75 | if [ $? -eq 0 ];then 76 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 77 | else 78 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 79 | fi 80 | done 81 | } 82 | 83 | 84 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 85 | extract_file() { 86 | output_msg "解压源码" 87 | for file in $*;do 88 | if [ "${file##*.}" == "gz" ];then 89 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 90 | elif [ "${file##*.}" == "zip" ];then 91 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 92 | else 93 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 94 | fi 95 | done 96 | } 97 | 98 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 99 | config_env() { 100 | output_msg "环境变量配置" 101 | echo "export PATH=\$PATH:$1" >${env_file} 102 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 103 | 104 | } 105 | 106 | # 添加配置文件 107 | add_config() { 108 | cat> $1 <${install_path}zookeeper/data/myid 133 | config_env ${install_path}zookeeper/bin 134 | } 135 | 136 | main 137 | 138 | -------------------------------------------------------------------------------- /脚本实用工具/install_kafka.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:kafka 0.10.2/0.11.0/1.1.0/2.0.0 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_kafka.log 12 | env_file=/etc/profile.d/kafka.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | software_config_file=${install_path}kafka/config/server.properties 16 | 17 | clear 18 | echo "##########################################" 19 | echo "# #" 20 | echo "# 安装kafka 0.10.2/0.11.0/1.1.0/2.0.0 #" 21 | echo "# #" 22 | echo "##########################################" 23 | echo "1: Install kafka 0.10.2" 24 | echo "2: Install kafka 0.11.0" 25 | echo "3: Install kafka 1.1.0" 26 | echo "4: Install kafka 2.0.0" 27 | echo "5: EXIT" 28 | # 选择安装软件版本 29 | read -p "Please input your choice:" softversion 30 | if [ "${softversion}" == "1" ];then 31 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-0.10.2.2.tgz" 32 | elif [ "${softversion}" == "2" ];then 33 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-0.11.0.3.tgz" 34 | elif [ "${softversion}" == "3" ];then 35 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-1.1.0.tgz" 36 | elif [ "${softversion}" == "4" ];then 37 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-2.0.0.tgz" 38 | elif [ "${softversion}" == "5" ];then 39 | echo "you choce channel!" 40 | exit 1; 41 | else 42 | echo "input Error! Place input{1|2|3|4|5}" 43 | exit 0; 44 | fi 45 | 46 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 47 | output_msg() { 48 | for msg in $*;do 49 | action $msg /bin/true 50 | done 51 | } 52 | 53 | 54 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 55 | check_yum_command() { 56 | output_msg "命令检查:$1" 57 | hash $1 >/dev/null 2>&1 58 | if [ $? -eq 0 ];then 59 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 60 | else 61 | yum -y install $2 >/dev/null 2>&1 62 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 63 | fi 64 | } 65 | 66 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 67 | check_dir() { 68 | output_msg "目录检查" 69 | for dirname in $*;do 70 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 71 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 72 | done 73 | } 74 | 75 | # 下载文件并解压至安装目录,传入url链接地址 76 | download_file() { 77 | output_msg "下载源码包" 78 | mkdir -p $download_path 79 | for file in $*;do 80 | wget $file -c -P $download_path &> /dev/null 81 | if [ $? -eq 0 ];then 82 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 83 | else 84 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 85 | fi 86 | done 87 | } 88 | 89 | 90 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 91 | extract_file() { 92 | output_msg "解压源码" 93 | for file in $*;do 94 | if [ "${file##*.}" == "gz" ] || [ "${file##*.}" == "tgz" ];then 95 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 96 | elif [ "${file##*.}" == "zip" ];then 97 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 98 | else 99 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 100 | fi 101 | done 102 | } 103 | 104 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 105 | config_env() { 106 | output_msg "环境变量配置" 107 | echo "export PATH=\$PATH:$1" >${env_file} 108 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 109 | 110 | } 111 | 112 | # 添加配置文件 113 | add_config() { 114 | cat> $1 <>/etc/security/limits.conf<>/etc/sysctl.conf && sysctl -p 63 | if [ ${sys_mem} -eq 0 ];then 64 | sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx512m"#g" ${jvm_conf} 65 | sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms512m"#g" ${jvm_conf} 66 | else 67 | sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx${sys_mem}g"#g" ${jvm_conf} 68 | sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms${sys_mem}g"#g" ${jvm_conf} 69 | fi 70 | cat >>/usr/local/elasticsearch/config/elasticsearch.yml</usr/local/logstash/config/01-syslog.conf< "5044" 91 | } 92 | } 93 | output { 94 | elasticsearch { 95 | hosts => "127.0.0.1:9200" 96 | } 97 | stdout { codec => rubydebug } 98 | } 99 | EOF 100 | nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/01-syslog.conf & >/dev/null 101 | } 102 | 103 | #install filebeat 104 | install_filebeat() { 105 | cd $software_dir 106 | tar -zxf filebeat-5.4.1-linux-x86_64.tar.gz 107 | mv filebeat-5.4.1-linux-x86_64 /usr/local/filebeat 108 | cat >/usr/local/filebeat/filebeat.yml</dev/null 118 | } 119 | 120 | #install kibana 121 | install_kibana() { 122 | cd $software_dir 123 | tar -zxf kibana-5.4.1-linux-x86_64.tar.gz 124 | mv kibana-5.4.1-linux-x86_64 /usr/local/kibana 125 | cat >> /usr/local/kibana/config/kibana.yml </dev/null 131 | } 132 | 133 | check() { 134 | port=$1 135 | program=$2 136 | check_port=`netstat -lntup|grep ${port}|wc -l` 137 | check_program=`ps -ef|grep ${program}|grep -v grep|wc -l` 138 | if [ $check_port -gt 0 ] && [ $check_program -gt 0 ];then 139 | action "${program} run is ok!" /bin/true 140 | else 141 | action "${program} run is error!" /bin/false 142 | fi 143 | } 144 | 145 | main() { 146 | init_sys 147 | wget_fun 148 | install_elasticsearch 149 | install_filebeat 150 | install_logstash 151 | install_kibana 152 | echo -e "\033[32m Checking Elasticsearch...\033[0m" 153 | sleep 20 154 | check :9200 "elasticsearch" 155 | echo -e "\033[32m Checking Logstash...\033[0m" 156 | sleep 2 157 | check ":9600" "logstash" 158 | echo -e "\033[32m Checking Kibana...\033[0m" 159 | sleep 2 160 | check ":5601" "kibana" 161 | action "ELK install is success!" /bin/true 162 | echo "url:http://$IP:5601" 163 | } 164 | main 165 | -------------------------------------------------------------------------------- /脚本实用工具/install_git.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # version:v1.0 4 | # func:git 2.0.0/2.10.0/2.18.0 安装 5 | 6 | # 定义安装目录、及日志信息 7 | . /etc/init.d/functions 8 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 9 | export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 10 | download_path=/tmp/tmpdir/ 11 | install_log_name=install_git.log 12 | env_file=/etc/profile.d/git.sh 13 | install_log_path=/var/log/appinstall/ 14 | install_path=/usr/local/ 15 | #software_config_file=${install_path} 16 | 17 | clear 18 | echo "##########################################" 19 | echo "# #" 20 | echo "# 安装 git 2.0.0/2.10.0/2.18.0 #" 21 | echo "# #" 22 | echo "##########################################" 23 | echo "1: Install git 2.0.0" 24 | echo "2: Install git 2.10.0" 25 | echo "3: Install git 2.18.0" 26 | echo "4: EXIT" 27 | # 选择安装软件版本 28 | read -p "Please input your choice:" softversion 29 | if [ "${softversion}" == "1" ];then 30 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.0.0.tar.gz" 31 | elif [ "${softversion}" == "2" ];then 32 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.10.0.tar.gz" 33 | elif [ "${softversion}" == "3" ];then 34 | URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.18.0.tar.gz" 35 | elif [ "${softversion}" == "4" ];then 36 | echo "you choce channel!" 37 | exit 1; 38 | else 39 | echo "input Error! Place input{1|2|3|4}" 40 | exit 0; 41 | fi 42 | 43 | # 传入内容,格式化内容输出,可以传入多个参数,用空格隔开 44 | output_msg() { 45 | for msg in $*;do 46 | action $msg /bin/true 47 | done 48 | } 49 | 50 | 51 | # 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称 52 | check_yum_command() { 53 | output_msg "命令检查:$1" 54 | hash $1 >/dev/null 2>&1 55 | if [ $? -eq 0 ];then 56 | echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0 57 | else 58 | yum -y install $2 >/dev/null 2>&1 59 | # hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 } 60 | fi 61 | } 62 | 63 | # yum 安装软件包,可传入多个软件包,用空格隔开 64 | yum_install_software() { 65 | output_msg "yum 安装软件" 66 | yum -y install $* >/dev/null 2>${install_log_path}${install_log_name} 67 | if [ $? -eq 0 ];then 68 | echo "`date +%F' '%H:%M:%S`yum install $* 完成" >>${install_log_path}${install_log_name} 69 | else 70 | exit 1 71 | fi 72 | } 73 | 74 | 75 | # 判断目录是否存在,传入目录绝对路径,可以传入多个目录 76 | check_dir() { 77 | output_msg "目录检查" 78 | for dirname in $*;do 79 | [ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1 80 | echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name} 81 | done 82 | } 83 | 84 | # 下载文件并解压至安装目录,传入url链接地址 85 | download_file() { 86 | output_msg "下载源码包" 87 | mkdir -p $download_path 88 | for file in $*;do 89 | wget $file -c -P $download_path &> /dev/null 90 | if [ $? -eq 0 ];then 91 | echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name} 92 | else 93 | echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1 94 | fi 95 | done 96 | } 97 | 98 | 99 | # 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录 100 | extract_file() { 101 | output_msg "解压源码" 102 | for file in $*;do 103 | if [ "${file##*.}" == "gz" ];then 104 | tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 105 | elif [ "${file##*.}" == "zip" ];then 106 | unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name} 107 | else 108 | echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1 109 | fi 110 | done 111 | } 112 | 113 | # 编译安装git,传入$1 为解压后软件包的名称 114 | source_install_git() { 115 | output_msg "编译安装git" 116 | mv ${install_path}${1} ${install_path}tmp${1} 117 | cd ${install_path}tmp${1} && make prefix=${install_path}git all >/dev/null 2>&1 118 | if [ $? -eq 0 ];then 119 | make prefix=${install_path}git install >/dev/null 2>&1 echo "`date +%F' '%H:%M:%S` git source install success ">>${install_log_path}${install_log_name} 120 | else 121 | echo "`date +%F' '%H:%M:%S` git source install fail!">>${install_log_path}${install_log_name} && exit 1 122 | fi 123 | } 124 | 125 | 126 | # 配置环境变量,第一个参数为添加环境变量的绝对路径 127 | config_env() { 128 | output_msg "环境变量配置" 129 | echo "export PATH=\$PATH:$1" >${env_file} 130 | source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name} 131 | 132 | } 133 | 134 | 135 | main() { 136 | check_dir $install_log_path $install_path 137 | check_yum_command wget wget 138 | check_yum_command make make 139 | yum_install_software curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker 140 | download_file $URL 141 | 142 | software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}') 143 | for filename in `ls $download_path`;do 144 | extract_file ${download_path}$filename 145 | done 146 | 147 | source_install_git ${software_name} 148 | mv /usr/bin/git /usr/bin/git.bak 149 | 150 | rm -fr ${download_path} 151 | config_env ${install_path}git/bin 152 | } 153 | 154 | main 155 | 156 | -------------------------------------------------------------------------------- /脚本实用工具/Sys_Check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # auth:kaliarch 3 | # func:sys info check 4 | # version:v1.0 5 | 6 | [ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1 7 | sysversion=$(rpm -q centos-release|cut -d- -f3) 8 | line="-------------------------------------------------" 9 | 10 | 11 | [ -d logs ] || mkdir logs 12 | 13 | sys_check_file="logs/$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt" 14 | 15 | # 获取系统cpu信息 16 | function get_cpu_info() { 17 | Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l) 18 | Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l) 19 | CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}') 20 | CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq) 21 | CPU_Arch=$(uname -m) 22 | cat </dev/null) 129 | if [ ${sysversion} -gt 6 ];then 130 | service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled") 131 | run_service=$(systemctl list-units --type=service --state=running |grep ".service") 132 | else 133 | service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t) 134 | run_service=$(/sbin/service --status-all|grep -E "running") 135 | fi 136 | cat </dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done) 162 | cat < ${sys_check_file} 226 | -------------------------------------------------------------------------------- /Docker安装脚本/seata/config/resources/application.example.yml: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2019 Seata.io Group. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | server: 16 | port: 7091 17 | 18 | spring: 19 | application: 20 | name: seata-server 21 | 22 | logging: 23 | config: classpath:logback-spring.xml 24 | file: 25 | path: ${user.home}/logs/seata 26 | extend: 27 | logstash-appender: 28 | destination: 127.0.0.1:4560 29 | kafka-appender: 30 | bootstrap-servers: 127.0.0.1:9092 31 | topic: logback_to_logstash 32 | 33 | seata: 34 | config: 35 | # support: nacos 、 consul 、 apollo 、 zk 、 etcd3 36 | type: file 37 | nacos: 38 | server-addr: 127.0.0.1:8848 39 | namespace: 40 | group: SEATA_GROUP 41 | username: 42 | password: 43 | context-path: 44 | ##if use MSE Nacos with auth, mutex with username/password attribute 45 | #access-key: 46 | #secret-key: 47 | data-id: seataServer.properties 48 | consul: 49 | server-addr: 127.0.0.1:8500 50 | acl-token: 51 | key: seata.properties 52 | apollo: 53 | appId: seata-server 54 | apollo-meta: http://192.168.1.204:8801 55 | apollo-config-service: http://192.168.1.204:8080 56 | namespace: application 57 | apollo-access-key-secret: 58 | cluster: seata 59 | zk: 60 | server-addr: 127.0.0.1:2181 61 | session-timeout: 6000 62 | connect-timeout: 2000 63 | username: 64 | password: 65 | node-path: /seata/seata.properties 66 | etcd3: 67 | server-addr: http://localhost:2379 68 | key: seata.properties 69 | registry: 70 | # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa 71 | type: file 72 | preferred-networks: 30.240.* 73 | nacos: 74 | application: seata-server 75 | server-addr: 127.0.0.1:8848 76 | group: SEATA_GROUP 77 | namespace: 78 | cluster: default 79 | username: 80 | password: 81 | context-path: 82 | ##if use MSE Nacos with auth, mutex with username/password attribute 83 | #access-key: 84 | #secret-key: 85 | eureka: 86 | service-url: http://localhost:8761/eureka 87 | application: default 88 | weight: 1 89 | redis: 90 | server-addr: localhost:6379 91 | db: 0 92 | password: 93 | cluster: default 94 | timeout: 0 95 | zk: 96 | cluster: default 97 | server-addr: 127.0.0.1:2181 98 | session-timeout: 6000 99 | connect-timeout: 2000 100 | username: 101 | password: 102 | consul: 103 | cluster: default 104 | server-addr: 127.0.0.1:8500 105 | acl-token: 106 | etcd3: 107 | cluster: default 108 | server-addr: http://localhost:2379 109 | sofa: 110 | server-addr: 127.0.0.1:9603 111 | application: default 112 | region: DEFAULT_ZONE 113 | datacenter: DefaultDataCenter 114 | cluster: default 115 | group: SEATA_GROUP 116 | address-wait-time: 3000 117 | 118 | server: 119 | service-port: 8091 #If not configured, the default is '${server.port} + 1000' 120 | max-commit-retry-timeout: -1 121 | max-rollback-retry-timeout: -1 122 | rollback-retry-timeout-unlock-enable: false 123 | enable-check-auth: true 124 | enable-parallel-request-handle: true 125 | retry-dead-threshold: 130000 126 | xaer-nota-retry-timeout: 60000 127 | enableParallelRequestHandle: true 128 | recovery: 129 | committing-retry-period: 1000 130 | async-committing-retry-period: 1000 131 | rollbacking-retry-period: 1000 132 | timeout-retry-period: 1000 133 | undo: 134 | log-save-days: 7 135 | log-delete-period: 86400000 136 | session: 137 | branch-async-queue-size: 5000 #branch async remove queue size 138 | enable-branch-async-remove: false #enable to asynchronous remove branchSession 139 | store: 140 | # support: file 、 db 、 redis 141 | mode: file 142 | session: 143 | mode: file 144 | lock: 145 | mode: file 146 | file: 147 | dir: sessionStore 148 | max-branch-session-size: 16384 149 | max-global-session-size: 512 150 | file-write-buffer-cache-size: 16384 151 | session-reload-read-size: 100 152 | flush-disk-mode: async 153 | db: 154 | datasource: druid 155 | db-type: mysql 156 | driver-class-name: com.mysql.jdbc.Driver 157 | url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true 158 | user: mysql 159 | password: mysql 160 | min-conn: 10 161 | max-conn: 100 162 | global-table: global_table 163 | branch-table: branch_table 164 | lock-table: lock_table 165 | distributed-lock-table: distributed_lock 166 | query-limit: 1000 167 | max-wait: 5000 168 | redis: 169 | mode: single 170 | database: 0 171 | min-conn: 10 172 | max-conn: 100 173 | password: 174 | max-total: 100 175 | query-limit: 1000 176 | single: 177 | host: 127.0.0.1 178 | port: 6379 179 | sentinel: 180 | master-name: 181 | sentinel-hosts: 182 | metrics: 183 | enabled: false 184 | registry-type: compact 185 | exporter-list: prometheus 186 | exporter-prometheus-port: 9898 187 | transport: 188 | rpc-tc-request-timeout: 15000 189 | enable-tc-server-batch-send-response: false 190 | shutdown: 191 | wait: 3 192 | thread-factory: 193 | boss-thread-prefix: NettyBoss 194 | worker-thread-prefix: NettyServerNIOWorker 195 | boss-thread-size: 1 196 | -------------------------------------------------------------------------------- /脚本实用工具/删除用户脚本.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Delete_User - Automates the 4 steps to remove an account 4 | # 5 | ################################################################# 6 | # 7 | # Define Functions 8 | # 9 | ################################################################# 10 | function get_answer { 11 | # 12 | unset ANSWER 13 | ASK_COUNT=0 14 | # 15 | while [ -z "$ANSWER" ] # while no answer is given, keep asking 16 | do 17 | ASK_COUNT=$[ $ASK_COUNT + 1 ] 18 | # 19 | case $ASK_COUNT in # If user gives no answer in time allowed 20 | 2) 21 | echo 22 | echo "Please answer the question." 23 | echo 24 | ;; 25 | 3) 26 | echo 27 | echo "One last try... please answer the question." 28 | echo 29 | ;; 30 | 4) 31 | echo 32 | echo "Since you refuse to answer the question..." 33 | echo "exiting program." 34 | echo 35 | # 36 | exit 37 | ;; 38 | esac 39 | # 40 | echo 41 | # 42 | if [ -n "$LINE2" ] 43 | then 44 | echo $LINE1 # Print 2 lines 45 | echo -e $LINE2" \c" 46 | else # Print 1 line 47 | echo -e $LINE1" \c" 48 | fi 49 | # 50 | # Allow 60 seconds to answer before time-out 51 | read -t 60 ANSWER 52 | done 53 | # 54 | # Do a little variable clean-up 55 | # 56 | unset LINE1 57 | unset LINE2 58 | # 59 | } #end of get_answer function 60 | # 61 | ################################################################# 62 | function process_answer { 63 | # 64 | case $ANSWER in 65 | y|Y|YES|yes|yEs|yeS|YEs|yES) 66 | # If user answers "yes".do nothing. 67 | ;; 68 | *) 69 | # If user answers anything but "yes", exit script 70 | echo 71 | echo $EXIT_LINE1 72 | echo $EXIT_LINE2 73 | echo 74 | exit 75 | ;; 76 | esac 77 | # 78 | # Do a little variable clean-up 79 | unset EXIT_LINE1 80 | unset EXIT_LINE2 81 | # 82 | } #End of process_answer function 83 | # 84 | ################################################################ 85 | # 86 | # End of Function Definitions 87 | # 88 | ############### Main Script ################################# 89 | # 90 | # Get name of User Account to check 91 | # 92 | echo "Step #1 - Determine User Account name to delete " 93 | echo 94 | LINE1="Please enter the username of the user" 95 | LINE2="account you wish to delete from system:" 96 | get_answer 97 | USER_ACCOUNT=$ANSWER 98 | # 99 | # Double check with script user that this is the correct User Account 100 | # 101 | LINE1="Is $USER_ACCOUNT the user account" 102 | LINE2="you wish to delete from the system?[ y/n ]:" 103 | get_answer 104 | # 105 | ############################################################ 106 | # 107 | # Check that USER_ACCOUNT is really an account on the system 108 | # 109 | USER_ACCOUNT_RECORD=$(cat /etc/passwd | grep -w $USER_ACCOUNT) 110 | # 111 | if [ $? -eq 1 ] # If the account is not found, exit script 112 | then 113 | echo 114 | echo "Account, $USER_ACCOUNT, not found." 115 | echo "Leaving the script..." 116 | echo 117 | exit 118 | fi 119 | # 120 | echo 121 | echo "I found this record:" 122 | echo $USER_ACCOUNT_RECORD 123 | echo 124 | # 125 | LINE1="Is this the correct User Account?[y/n]:" 126 | get_answer 127 | # 128 | # 129 | # Call process_answer function: 130 | # if user answers anything but "yes", exit script 131 | # 132 | EXIT_LINE1="Because the account, $USER_ACCOUNT, is not " 133 | EXIT_LINE2="the one you wish to delete, we are leaving the script..." 134 | process_anser 135 | # 136 | ############################################################## 137 | # 138 | # Search for any running processes that belong to the User Account 139 | # 140 | echo 141 | echo "Step #2 - Find process on system belonging to user account" 142 | echo 143 | echo "$USER_ACCOUNT has the following processes running: " 144 | echo 145 | # 146 | ps -u $USER_ACCOUNT #List the processes running 147 | # 148 | case $? in 149 | 1) # No processes running for this User Account 150 | # 151 | echo "There are no processes for this account currently running." 152 | echo 153 | ;; 154 | 0) # Processes running for this User Account. 155 | # Ask Script User if wants us to kill the processes. 156 | # 157 | unset ANSWER # I think this line is not needed 158 | LINE1="Would you like me to kill the process(es)? [y/n]:" 159 | get_answer 160 | # 161 | case $ANSWER in 162 | y|Y|YES|yes|Yes|yEs|yeS|YEs|yES) # if user answer "yes", 163 | #kill User Account processes 164 | # 165 | echo 166 | # 167 | # Clean-up temp file upon signals 168 | # 169 | trap "rm $USER_ACCOUNT_Running_Process.rpt" SIGTERM SIGINT SIGQUIT 170 | # 171 | # List user processes running 172 | ps -u $USER_ACCOUNT > $USER_ACCOUNT_Running_Process.rpt 173 | # 174 | exec < $USER_ACCOUNT_Running_Process.rpt # Make report Std Input 175 | # 176 | read USER_PROCESS_REC # First record will be blank 177 | read USER_PROCESS_REC 178 | # 179 | while [ $? -eq 0 ] 180 | do 181 | # obtain PID 182 | USER_PID=$(echo $USER_PROCESS_REC | cut -d " " -f1 ) 183 | kill -9 $USER_PID 184 | echo "Killed process $USER_PID" 185 | read USER_PROCESS_REC 186 | done 187 | # 188 | echo 189 | # 190 | rm $USER_ACCOUNT_Running_Process.rpt # Remove temp report 191 | ;; 192 | *) # If user answers anything but "yes", do not kill. 193 | echo 194 | echo "Will not kill the process(es)." 195 | echo 196 | ;; 197 | esac 198 | ;; 199 | esac 200 | ################################################################################### 201 | # 202 | # Create a report of all files owned by User Account 203 | # 204 | echo 205 | echo "Step #3 - Find files on system belonging to user account" 206 | echo 207 | echo "Creating a report of all files owned by $USER_ACCOUNT." 208 | echo 209 | echo "It is recommended that you backup/archive these files." 210 | echo "and then do one of two things:" 211 | echo " 1) Delete the files" 212 | echo " 2) Change the files' ownership to a current user account." 213 | echo 214 | echo "Please wait. This may take a while..." 215 | # 216 | REPORT_DATE=`date +%y%m%d` 217 | REPORT_FILE=$USER_ACCOUNT"_Files_"$REPORT_DATE".rpt" 218 | # 219 | find / -user $USER_ACCOUNT > $REPORT_FILE 2>/dev/null 220 | # 221 | echo 222 | echo "Report is complete." 223 | echo "Name of report: $REPORT_FILE" 224 | echo "Location of report: `pwd`" 225 | echo 226 | ################################################################ 227 | # 228 | # Remove User Account 229 | echo 230 | echo "Step #4 - Remove user account" 231 | echo 232 | # 233 | LINE1="Do you wish to remove $USER_ACCOUNT's account from system? [y/n]:" 234 | get_answer 235 | # 236 | # Cass process_answer function: 237 | # if user answers anything but "yes", exit script 238 | # 239 | EXIT_LINE1="Since you do not wish to remove the user account." 240 | EXIT_LINE2="$USER_ACCOUNT at this time, exiting the script..." 241 | process_answer 242 | # 243 | userdel $USER_ACCOUNT # delete user account 244 | echo 245 | echo "User account, $USER_ACCOUNT, has been removed" 246 | echo 247 | # 248 | --------------------------------------------------------------------------------