zabbix简易安装手册

Posted by 4Aiur on 10/15/2010 in SysAdmin with Comments closed |

zabbix简易安装手册

1) 安装zabbix依赖包

# yum install gcc MySQL-python mysql mysql-server mysql-devel mysql-bench php php-mysql php-bcmath php-mbstring freetype php-gd php-xml curl-devel libpurple yum install net-snmp net-snmp-devel

# mkdir package
# cd package/
# wget http://packages.sw.be/iksemel/iksemel-devel-1.4-1.el5.rf.x86_64.rpm
# wget http://packages.sw.be/iksemel/iksemel-1.4-1.el5.rf.x86_64.rpm
# rpm -ivh iksemel-1.4-1.el5.rf.x86_64.rpm iksemel-devel-1.4-1.el5.rf.x86_64.rpm
# wget http://fping.sourceforge.net/download/fping.tar.gz
# tar zxf fping.tar.gz
# cd fping-2.4b2_to/
# ./configure && make && make install

2) 配置zabbix依赖环境

# service httpd restart
# chkconfig httpd on
# chkconfig mysqld on
# service mysqld restart

3) 在mysql中增加zabbix库并配置zabbix库访问权限

# mysql
mysql> create database zabbix character set utf8;
mysql> GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
mysql> quit;

4) 下载并安装zabbix

# wget "http://prdownloads.sourceforge.net/zabbix/zabbix-1.8.3.tar.gz?download"
# tar zxf zabbix-1.8.3.tar.gz 
# cd zabbix-1.8.3
# cd create/schema
# cat mysql.sql | mysql -uroot zabbix
# cd ../data
# cat data.sql | mysql -uroot zabbix
# cat images_mysql.sql | mysql -uroot zabbix
# cd ../../
# ./configure  --enable-server --enable-agent --with-mysql --with-net-snmp --with-jabber --with-libcurl
# enable Jabber 即时通讯功能。Jabber 是著名的Linux即时通讯服务服务器,它是一个自由开源软件,能让用户自己架即时通讯服务器,可以在Internet上应用,也可以在局域网中应用。 Jabber最有优势的就是其通信协议,可以和多种即时通讯对接。比如有第三方插件,能让jabber用户和MSN 、Yahoo、ICQ等IM用户相互通讯。 
# make install

5) 简单配置zabbix

# vim /etc/services
    zabbix-agent    10050/tcp  Zabbix Agent
    zabbix-agent    10050/udp  Zabbix Agent
    zabbix-trapper  10051/tcp  Zabbix Trapper
    zabbix-trapper  10051/udp  Zabbix Trapper 
# mkdir /etc/zabbix/
# cp /root/package/zabbix-1.8.3/misc/conf/zabbix_server.conf /etc/zabbix/zabbix_server.conf
# vim /etc/zabbix/zabbix_server.conf
    LogFile=/var/log/zabbix/zabbix_server.log
    LogFileSize=100
    DebugLevel=3
    PidFile=/tmp/zabbix_server.pid
    DBHost=localhost
    DBName=zabbix
    DBPassword=zabbix
    DBSocket=/var/lib/mysql/mysql.sock
    DBPort=3306
    ListenIP=0.0.0.0
    StartPingers=30
    FpingLocation=/usr/local/sbin/fping

# cp /root/package/zabbix-1.8.3/misc/conf/zabbix_agent.conf /etc/zabbix/
# cp /root/package/zabbix-1.8.3/misc/conf/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf
# mv frontends/php /var/www/html/zabbix

# vim /etc/php.ini
    max_execution_time = 600     ; Maximum execution time of each script, in seconds
    max_input_time = 600    ; Maximum amount of time each script may spend parsing request data
    memory_limit = 256M      ; Maximum amount of memory a script may consume
    post_max_size = 32M
    upload_max_filesize = 16M
    date.timezone = Asia/Shanghai
# service httpd restart
# useradd -s /sbin/nologin zabbix

6) 启动zabbix

# su zabbix -c /usr/local/sbin/zabbix_server
# su zabbix -c /usr/local/sbin/zabbix_agentd

使用http://IP/zabbix登录zabbix,首次登录时按照网页提示进行操作。
默认登录帐户与密码:
admin/zabbix

Tags:

MacOSX使用opensnoop跟踪进程使用情况

Posted by 4Aiur on 09/28/2010 in MacOSX with Comments closed |

MacOSX使用opensnoop跟踪进程使用情况

opensnoop参数如下:

$ opensnoop -hUSAGE: opensnoop [-a|-A|-ceghsvxZ] [-f pathname]
                 [-n name] [-p PID]
       opensnoop                # default output
                -a              # print most data
                -A              # dump all data, space delimited
                -c              # print cwd of process
                -e              # print errno value
                -g              # print command arguments
                -s              # print start time, us
                -v              # print start time, string
                -x              # only print failed opens
                -Z              # print zonename
                -f pathname # pathname name to snoop
                -n name     # process name to snoop
                -p PID      # process ID to snoop
  eg,
       opensnoop -v             # human readable timestamps
       opensnoop -e             # see error codes
       opensnoop -f /etc/motd   # snoop this file only

Tags:

在OpenSolais上的安装与配置awstats

Posted by 4Aiur on 09/17/2010 in OpenSolaris with Comments closed |

在OpenSolais上的安装与配置awstats

安装awstats

# pkgin in awstats

安装GeoIP

# pkgin in GeoIP

安装perl的GeoIP模块

# Geo::IP::PurePerl
# wget http://geolite.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.25.tar.gz
# gtar zxf Geo-IP-PurePerl-1.25.tar.gz
# cd Geo-IP-PurePerl-1.25
# perl Makefile.PL 
# make
# make test
# make install

下载GeoCity库

# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# gzip -d GeoLiteCity.dat.gz
# mv GeoLiteCity.dat /opt/local/share/GeoIP/

配置apache的虚拟主机

# cd /opt/local/etc/httpd/virtualhosts/
# vi blog.4aiur.net.conf

    ServerName blog.4aiur.net
    DocumentRoot /home/4aiur/web/blog.4aiur.net/
    DocumentRoot /home/4aiur/web/blog.4aiur.net/
    CustomLog /home/4aiur/web/logs/blog.4aiur.net_access_log combined
    ErrorLog /home/4aiur/web/logs/blog.4aiur.net_error.log
    
        Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    
    Alias /awstatsclasses "/usr/local/awstats/classes/"
    Alias /awstatscss "/usr/local/awstats/css/"
    Alias /awstatsicons "/usr/local/awstats/icon/"
    ScriptAlias /awstats/ /usr/local/awstats/cgi-bin/
    
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
    
# svcadm restart apache

配置awstats配置文件

# cd /opt/local/etc/awstats/
# mv awstats.model.conf awstats.blog.4aiur.net.conf
# vi awstats.blog.4aiur.net.conf
LogFile="/home/4aiur/web/logs/blog.4aiur.net_access_log"
SiteDomain="blog.4aiur.net"
HostAliases="localhost 127.0.0.1 REGEX[4aiur\.net$]"
DNSLookup=0
DirIcons="/awstatsicons"
SkipFiles="REGEX[^\/wp-]"
LoadPlugin="geoip GEOIP_STANDARD /opt/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /opt/local/share/GeoIP/GeoLiteCity.dat"

增加日志分析程序到crontab

0 * * * * /opt/local/awstats/bin/awstats_updateall.pl now >/dev/null 2>&1

访问方式
http://blog.4aiur.net/awstats/awstats.pl?config=blog.4aiur.net

Tags: ,

在OpenSolaris上安装与配置proftpd

Posted by 4Aiur on 06/17/2010 in OpenSolaris with Comments closed |

在OpenSolaris上安装与配置proftpd

Install proftpd

# pkgin in proftpd

Setup proftpd
proftpd configuration examples /opt/local/share/examples/proftpd
modify /opt/local/etc/proftpd.conf

TimeoutLogin         120
TimeoutIdle          600
TimeoutNoTransfer    900
TimeoutStalled       3600
RootLogin            off
DefaultRoot ~
UseReverseDNS        off
IdentLookups         off

#VALID LOGINS

  AllowUser ftpuser
  DenyALL

Setup openSolaris SMF

# vi /var/svc/manifest/network/proftpd.xml
# svccfg import /var/svc/manifest/network/proftpd.xml
# svcadm enable proftpd
# svcs proftpd

Tags: ,

在不浪费磁盘空间的情况下测试网络

Posted by 4Aiur on 06/09/2010 in SysAdmin with Comments closed |

在不浪费磁盘空间的情况下测试网络

time dd if=/dev/zero bs=1024 count=1048576 | ssh user@remotehost 'cat > /dev/null'

在数据传输过程中可以使用iptraf进行观察

不需要反引号的运行ssh复杂远程命令方式

Posted by 4Aiur on 06/07/2010 in Shell with Comments closed |

不需要反引号的运行ssh复杂远程命令方式

之前当我需要执行复杂的运程命令时,总是要先处理好引号、变量等问题,之后再执行命令写起来太麻烦,今天在commandlinefu上学了一招非常棒的方法,记录一下。

举个例子,之前需要用\反引$符号

[root@localhost ~]# ssh 127.0.0.1 -l root "echo a b c | awk '{print \$2}'"
b

现在我们可以把复杂的命令写到文件中执行。

[root@localhost ~]# cat cmd
echo a b c | awk '{print $2}'

方法1:

[root@localhost ~]# ssh 127.0.0.1 -l root "$(

方法2:

[root@localhost ~]# ssh 127.0.0.1 -l root "cat cmd"
b

方法3,使用标准输入执行,输入完毕后使用ctrl-D提交命令:

[root@localhost ~]# ssh 127.0.0.1 -l root "cat -"
hostname
if [ -d /root/ ];then
  echo "ok"
else
  echo "not ok"
fi
ctrl-D
localhost
ok
[root@localhost ~]#

直接把script嵌入到脚本中

[root@localhost ~]# ssh 127.0.0.1 -l root "$(cat 

来源:
http://www.commandlinefu.com/commands/view/5772/run-complex-remote-shell-cmds-over-ssh-without-escaping-quotes

ssh host -l user $(

run complex remote shell cmds over ssh, without escaping quotes
Much simpler method. More portable version:

ssh host -l user "cat cmd.txt"
perl -e 'system @ARGV, ' ssh host -l user 

run complex remote shell cmds over ssh, without escaping quotes

I was tired of the endless quoting, unquoting, re-quoting, and escaping characters that left me with working, but barely comprehensible shell one-liners. It can be really frustrating, especially if the local and remote shells differ and have their own escaping and quoting rules. I decided to try a different approach and ended up with this.

so we need to save the command in cmd.txt first and then run it?

there’s no way to do this? :

ssh host -l user $(perl -ane "print $F[1]\n" filename )

one alternative I can think of (not to save a file and then use "cat cmd.txt") is;

ssh host -l user "cat -"

And then type your command, press Enter and then ctrl-D. This will allow you run complex commands on remote machine without saving a file..

Tags: ,

unix时间戳转换

Posted by 4Aiur on 05/14/2010 in SysAdmin with Comments closed |

unix时间戳转换, Convert unix timestamp

utime(){ date -d @$1; }
utime(){ date -d "1970-01-01 GMT $1 seconds"; }
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
utime(){ perl -e "print localtime($1).\"\n\""; }
utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }

[root@test test]# utime(){ date -d @$1; }
[root@test test]# utime 1273817956
Fri May 14 14:19:16 CST 2010

[root@test test]# utime 1273817956
Fri May 14 14:19:16 CST 2010

[root@test test]# utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
[root@test test]# utime 1273817956
Fri May 14 14:19:16 2010

[root@test test]# utime(){ perl -e "print localtime($1).\"\n\""; }
[root@test test]# utime 1273817956
Fri May 14 14:19:16 2010

[root@test test]# utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
[root@test test]# utime 1273817956
Fri May 14 14:19:16 2010
[root@test test]#

Tags:

查找使用中的文件与目录相关信息

Posted by 4Aiur on 05/10/2010 in SysAdmin with Comments closed |

查找使用中的文件与目录相关信息

以tmp目录为例,使用下面得方法获得使用tmp目录进程的相关信息。

[root@4aiur ~]# inode=stat -c %i tmp
[root@4aiur ~]# cd tmp
[root@4aiur ~]# lsof -n | awk -v a=$inode 'a==$(NF-1) || a==$(NF-2)'
bash       1963    root  cwd       DIR      253,0     4096   23805953 /root/tmp
lsof       2033    root  cwd       DIR      253,0     4096   23805953 /root/tmp
awk        2034    root  cwd       DIR      253,0     4096   23805953 /root/tmp
lsof       2035    root  cwd       DIR      253,0     4096   23805953 /root/tmp

Tags:

python的ftp应用举例

Posted by 4Aiur on 05/04/2010 in Python with Comments closed |

python的ftp应用举例

使用python可以很方便的进行ftp操作,下面这个小程序的作用是成功下载远程服务器文件后,删除远程服务器上面的文件。

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from ftplib import FTP
import logging
import os
import socket

logger = logging.getLogger("download")
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler("download.log")
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)

def get_del():
    ip = '127.0.0.1'
    user_name = 'foo'
    passwd = 'bar'
    source_path = '/test_sour_dir/'
    try:
        ftp = FTP(ip)
        timeout=10 # in seconds
        socket.setdefaulttimeout(timeout)
        ftp.set_pasv(True)
        ftp.login(user_name, passwd)
        logger.info('login %s success' %(ip))
    except Exception, e:
        logger.error('Can\'t connect ftp server, %s' %(e))
        return
    try:
        ftp.cwd(source_path)
        remote_files = ftp.nlst()
    except Exception, e:
        logger.error('ftp error, %s' %(e))
        return
    try:
        for file_name in remote_files:
            remote_file_size = ftp.size(file_name)
            f = open('/test_dest_dir/' + file_name, 'wb')
            logger.debug('%s download success' %(file_name))
            ftp.retrbinary('RETR %s' %(file_name), f.write, 4096)
            f.close()
            local_file_size = os.stat('/test_dest_dir/' + file_name).st_size
            logger.debug('%s remote size: %d, local size %d' %(file_name, remote_file_size, local_file_size))
            ftp.delete(file_name)
            logger.debug('%s delete success' %(file_name))
    except Exception, e:
        logger.error('ftp error, %s' %(e))
        return
    ftp.close()
    return

if __name__ == "__main__":
    get_del()

Tags:

禁用ConfigParser配置选项转化小写

Posted by 4Aiur on 04/20/2010 in Python with Comments closed |

禁用ConfigParser配置选项转化小写

ConfigParser在读取配置文件后默认会把配置项目转换为小写,调用下面的方法可以关闭转换功能。

cfgparser.optionxform = str

Tags:

Copyright © 2010-2024 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.