forked from supermy/mytools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
111 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
web(极限性能挖掘,可快速扩充) | ||
==================== | ||
|
||
介绍 | ||
--------------------- | ||
nginx(tengine)+tomcat+mysql+memcached 集群 | ||
一键构造,一键启动,一键数据初始化。 | ||
|
||
> nginx 整合HttpRedis2Module/lua-resty-redis完成,http方式访问redis; | ||
> | ||
> | ||
> ## end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docker build -t jamesmo/mynginx:2.1 mynginx | ||
docker build -t jamesmo/mytomcat:7 mytomcat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
location /hello { | ||
default_type 'text/plain'; | ||
|
||
access_by_lua_file "/usr/local/nginx/conf/nginx.d/redis-ip.lua"; | ||
|
||
|
||
content_by_lua 'ngx.say("hello, lua")'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
ip_bind_time = 300 --封禁IP时间 | ||
ip_time_out = 60 --指定ip访问频率时间段 | ||
connect_count = 100 --指定ip访问频率计数最大值 | ||
|
||
--连接redis | ||
local redis = require "resty.redis" | ||
local cache = redis.new() | ||
local ok , err = cache.connect(cache,"192.168.59.103","6379") | ||
cache:set_timeout(60000) | ||
|
||
--如果连接失败,跳转到脚本结尾 | ||
if not ok then | ||
goto A | ||
end | ||
|
||
--查询ip是否在封禁段内,若在则返回403错误代码 | ||
--因封禁时间会大于ip记录时间,故此处不对ip时间key和计数key做处理 | ||
is_bind , err = cache:get("bind_"..ngx.var.remote_addr) | ||
if is_bind == 1 then | ||
ngx.exit(403) | ||
goto A | ||
end | ||
|
||
start_time , err = cache:get("time_"..ngx.var.remote_addr) | ||
ip_count , err = cache:get("count_"..ngx.var.remote_addr) | ||
|
||
--如果ip记录时间大于指定时间间隔或者记录时间或者不存在ip时间key则重置时间key和计数key | ||
--如果ip时间key小于时间间隔,则ip计数+1,且如果ip计数大于ip频率计数,则设置ip的封禁key为1 | ||
--同时设置封禁key的过期时间为封禁ip的时间 | ||
if start_time == ngx.null or os.time() - start_time > ip_time_out then | ||
res , err = cache:set("time_"..ngx.var.remote_addr , os.time()) | ||
res , err = cache:set("count_"..ngx.var.remote_addr , 1) | ||
else | ||
ip_count = ip_count + 1 | ||
res , err = cache:incr("count_"..ngx.var.remote_addr) | ||
if ip_count >= connect_count then | ||
res , err = cache:set("bind_"..ngx.var.remote_addr,1) | ||
res , err = cache:expire("bind_",ip_bind_time) | ||
end | ||
end | ||
|
||
--结尾标记 | ||
::A:: | ||
local ok, err = cache:close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
#转移到common/mysql | ||
#FROM mysql:latest | ||
FROM mysql:latest | ||
MAINTAINER jamesmo <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
db: | ||
image: mysql:latest | ||
environment: | ||
MYSQL_USER: java | ||
MYSQL_PASSWORD: java | ||
MYSQL_DATABASE: javatest | ||
MYSQL_ROOT_PASSWORD: mysql | ||
ports: | ||
- "3306:3306" | ||
|
||
dbinit: | ||
image: mysql:latest | ||
entrypoint: /bin/bash | ||
volumes: | ||
- .:/host | ||
command: -c "sleep 8; mysql -ujava -pjava -hmysql_base javatest < /host/init.sql; exit 0" | ||
links: | ||
- db:mysql_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
create table testdata (id int not null auto_increment primary key,foo varchar(25),bar int); | ||
insert into testdata values(null, 'hello', 12345); |
This file was deleted.
Oops, something went wrong.