本文以获取 squid 内存缓存命中率为例。

在 /etc/snmp/snmpd.conf 可以看到这样的样例:
# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest
可以使用自己编写的脚本,比如:
exec .1.3.6.1.4.1.2021.50 squidmemhits /usr/local/bin/squidmemhits.sh

vi /usr/local/bin/squidmemhits.sh

#!/bin/sh
PATH=$PATH:/usr/local/squid/bin
export PATH
squidclient -t 1 -h localhost -p 3128 mgr:info | grep "Memory hits" | cut -d "%" -f 2 | awk '{print $5}'
squidclient -t 1 -h localhost -p 3128 mgr:info | grep "Memory hits" | cut -d "%" -f 3 | awk '{print $3}'

/etc/init.d/snmpd restart
全文阅读 »

nginx 使用 logrotate 回滚日志

2009-09-04 15:28  |  分类:应用技术

vi /usr/local/nginx/conf/logrotate.conf

/var/log/nginx/*.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 www-data adm
    sharedscripts
    prerotate
    sleep 59
    endscript
    postrotate
        if [ -f /var/run/nginx.pid ]; then
          kill -USR1 `cat /var/run/nginx.pid`
        fi
    endscript
}

调试:
logrotate -d /usr/local/nginx/conf/logrotate.conf

执行:
logrotate -f /usr/local/nginx/conf/logrotate.conf

定期执行:
vi /etc/crontab
59 23 * * * root logrotate -f /usr/local/nginx/conf/logrotate.conf

先要配置好 ssh 的 key ,然后安装:
apt-get install pssh

为了方便输入,设置一下别名和环境变量( CentOS 安装后的程序文件名直接就是短格式的):
vi ~/.bashrc

alias pssh='parallel-ssh'
alias pscp='parallel-scp'
alias prsync='parallel-rsync'

export PSSH_HOSTS="/root/servers.txt"
export PSSH_USER="root"
export PSSH_PAR="32"
export PSSH_OUTDIR="/tmp"
export PSSH_VERBOSE="0"
export PSSH_OPTIONS="UserKnownHostsFile /root/.ssh/known_hosts"

source ~/.profile
全文阅读 »

Linux 下使用 NMON 分析系统性能

2009-08-31 19:06  |  分类:操作系统

下载相应 CPU 类型的版本:
http://nmon.sourceforge.net/pmwiki.php?n=Site.Download

wget http://sourceforge.net/projects/nmon/files/download/nmon_x86_12a.zip/download
unzip nmon_x86_12a.zip
Archive:  nmon_x86_12a.zip
  inflating: nmon_x86_rhel45
  inflating: nmon_x86_rhel52
  inflating: nmon_x86_sles9
  inflating: nmon_x86_sles10
  inflating: nmon_x86_ubuntu810
  inflating: nmon_x86_fedora10
  inflating: nmon_x86_opensuse10

使用对应的操作系统文件:
chmod +x nmon_x86_ubuntu810
mv nmon_x86_ubuntu810 /usr/local/bin/nmon

对于 Debian 还要做以下操作(不做也同样能运行):
apt-get install lsb-release
lsb_release -d | sed 's/Description:\t//' > /etc/debian_release

然后直接运行 nmon 即可。
全文阅读 »

使用 DenyHosts 阻止 SSH 暴力破解

2009-08-29 17:34  |  分类:操作系统

项目主页:
http://denyhosts.sourceforge.net/

安装:
CentOS:
yum install denyhosts

Debian:
apt-get install denyhosts

配置:
vi /etc/denyhosts.conf
# 用户登录的日志文件
SECURE_LOG = /var/log/auth.log

# 禁止登陆的主机文件
HOSTS_DENY = /etc/hosts.deny

# 清除已禁止主机的时间
PURGE_DENY = 5d

# 禁止的服务名
BLOCK_SERVICE = sshd

# 允许无效用户登录失败的次数
DENY_THRESHOLD_INVALID = 1

# 允许普通用户登陆失败的次数
DENY_THRESHOLD_VALID = 3

# 允许 root 用户登陆失败的次数
DENY_THRESHOLD_ROOT = 3

# 是否做域名反解
HOSTNAME_LOOKUP=NO

# 管理员邮件地址
ADMIN_EMAIL = admin@domain.com

# SMTP 的相关设置
SMTP_HOST = mail.domain.com
SMTP_PORT = 25
SMTP_USERNAME=denyhosts@domain.com
SMTP_PASSWORD=password
SMTP_FROM = DenyHosts
SMTP_SUBJECT = DenyHosts Report from domain.com

# DenyHosts 的日志文件
DAEMON_LOG = /var/log/denyhosts

页码: 1 2 3 4 5 6 7 8 ...11 12 13 下一页