Skip to content

Instantly share code, notes, and snippets.

@naokij
naokij / rsyslogforwarder
Created February 16, 2012 17:03
init script for rsyslog to forward remote syslog to another server
#!/bin/bash
#
# rsyslogforwarder Starts rsyslogd/rklogd forwarder.
#
#
# chkconfig: 2345 12 88
# description: Syslog is the facility by which many daemons use to log \
# messages to various system log files. It is a good idea to always \
# run rsyslog.
### BEGIN INIT INFO
@naokij
naokij / rsyslogforwarder.conf
Created February 16, 2012 17:05
rsyslog config to forward log from remote server to another server
#rsyslog v3 config file
# if you experience problems, check
# http://www.rsyslog.com/troubleshoot for assistance
#### MODULES ####
# Provides UDP syslog reception
$ModLoad imudp.so
$UDPServerRun 514
@naokij
naokij / graylog2-server
Created February 17, 2012 08:53
/etc/init.d/graylog2-server
#!/bin/sh
#
# graylog2-server: graylog2 message collector
#
# chkconfig: - 98 02
# description: This daemon listens for syslog and GELF messages and stores them in mongodb
#
CMD=$1
NOHUP=`which nohup`
@naokij
naokij / graylog2-server
Created February 17, 2012 08:56
/etc/logrotate.d/graylog2-server
/var/log/graylog2.log {
daily
rotate 90
copytruncate
delaycompress
compress
notifempty
missingok
}
@naokij
naokij / graylog2-web-interface
Created February 20, 2012 04:15
/etc/init.d/graylog2-web-interface
#!/bin/bash
#
# graylog2-web-interface: graylog2 web interface
#
# chkconfig: - 98 02
# description: Starts graylog2-web-interface using passenger-standalone. \
# Uses RVM to use switch to a specific ruby version.
#
# config
@naokij
naokij / graylog2-blacklist-2-rsyslog.rb
Created February 20, 2012 09:21
ruby script to create rsyslog discarding terms based on graylog2 blacklist terms
require 'rubygems'
require 'mongo'
@conn = Mongo::Connection.new
@db = @conn['graylog2']
@db.authenticate('grayloguser','grayloguser-mongo-passwd')
@coll = @db['blacklists']
@conf_file = '/etc/rsyslog_disgarding.conf'
@conf_content = ""
@file = File.open(@conf_file,'r')
@naokij
naokij / spider-killer.sh
Created October 24, 2012 03:24
根据nginx日志文件过滤spider
#! /bin/bash
LOGFILE=/var/log/nginx/access.log
PREFIX=/etc/spiders
#日志中大部分蜘蛛都有spider的关键字,但是百度的不能封,所以过滤掉百度
grep 'spider' $LOGFILE |grep -v 'Baidu' |awk '{print $1}' >$PREFIX/ip1.txt
# 封掉网易的有道
grep 'YoudaoBot' $LOGFILE | awk '{print $1}' >>$PREFIX/ip1.txt
#封掉雅虎
grep 'Yahoo!' $LOGFILE | awk '{print $1}' >>$PREFIX/ip1.txt
# 过滤掉信任IP
@naokij
naokij / gist:4011810
Created November 4, 2012 12:57
nginx 反向代理设置
server
{
listen 80;
server_name yoursite.com;
location / {
proxy_pass http://sourcesite.com/;
proxy_redirect default;
proxy_set_header X-Real-IP $remote_addr;
@naokij
naokij / nginx
Created October 11, 2013 04:33
nginx start script with chkconfig support
#!/bin/bash
# chkconfig: 2345 88 88
# description: starts the nginx web server
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
@naokij
naokij / gist:0550005be8d469b9bf78
Created May 29, 2014 08:54
go语言map中的坑
package main
type HostReport struct {
Download string
Upload string
Traceroute string
}
func main(){
reports := make(map[string]HostReport)
}