RHEL/CentOS 在 6.3 版本以后引入了一套新的系统调优工具 tuned/tuned-adm,其中 tuned 是服务端程序,用来监控和收集系统各个组件的数据,并依据数据提供的信息动态调整系统设置,达到动态优化系统的目的;tuned-adm 是客户端程序,用来和 tuned 打交道,用命令行的方式管理和配置 tuned,tuned-adm 提供了一些预先配置的优化方案可供直接使用,比如:笔记本、虚拟机、存储服务器等。
如果你正在使用笔记本(电池电源),想优化系统、节约电源又不想知道太多这方面的细节,就可以用 tuned/tuned-adm 这套工具并应用 laptop-battery-powersave 方案来调整和优化系统。当然不同的系统和应用场景有不同的优化方案,tuned-adm 预先配置的优化策略不是总能满足要求,这时候就需要定制,tuned-adm 允许用户自己创建和定制新的调优方案。
安装和启动 tuned:
# yum update
# yum install tuned
# service tuned start
# chkconfig tuned on
# service ktune start
# chkconfig ktune on

查看当前优化方案:

# tuned-adm active
Current active profile: default
Service tuned: enabled, running
Service ktune: enabled, running

查看预先配置好的优化方案:
# tuned-adm list
Available profiles:
- laptop-battery-powersave
- virtual-guest
- desktop-powersave
- sap
- server-powersave
- virtual-host
- throughput-performance
- enterprise-storage
- laptop-ac-powersave
- latency-performance
- spindown-disk
- default
Current active profile: default

如果服务器是虚拟机母机的话,可以选用 virtual-host 方案优化。如果报错 “kernel.sched_migration_cost” is an unknown key 可以通过编辑 sysctl.ktune 这个文件解决。
# tuned-adm profile virtual-host
Reverting to saved sysctl settings:                        [  OK  ]
Calling '/etc/ktune.d/tunedadm.sh stop':                   [  OK  ]
Reverting to cfq elevator: sda sdb sdc sdd sde sdf sdg     [  OK  ]
Stopping tuned:                                            [  OK  ]
Switching to profile 'virtual-host'
Applying deadline elevator: sda sdb sdc sdd sde sdf sdg    [  OK  ]
Applying ktune sysctl settings:
/etc/ktune.d/tunedadm.conf:                                [FAILED]
  error: "kernel.sched_migration_cost" is an unknown key

Calling '/etc/ktune.d/tunedadm.sh start':                  [  OK  ]
Applying sysctl settings from /etc/sysctl.conf
Starting tuned:                                            [  OK  ]

# vi /etc/tune-profiles/virtual-host/sysctl.ktune
...
#kernel.sched_migration_cost = 5000000
...

# tuned-adm profile virtual-host

如果是企业存储服务器的话,可以用 enterprise-storage 方案:
# tuned-adm profile enterprise-storage
Stopping tuned:                                            [  OK  ]
Switching to profile 'enterprise-storage'
Applying deadline elevator: dm-0 sda sdb sdc sdd           [  OK  ]
Applying ktune sysctl settings:
/etc/ktune.d/tunedadm.conf:                                [  OK  ]
Calling '/etc/ktune.d/tunedadm.sh start':                  [  OK  ]
Applying sysctl settings from /etc/sysctl.conf
Starting tuned:                                            [  OK  ]

上面预定的方案不是总能满足要求,如果有自己的需求可以定制自己的方案。自己定制很容易,切换到优化方案的配置目录,拷贝一个例子,然后编辑里面的相关参数就可以了,使用 tuned-adm list 命令会看到刚创建的新方案 my-virtual-host:
# cd /etc/tune-profiles/
# cp -r virtual-host my-virtual-host
# vi my-virtual-host/*
# tuned-adm list
Available profiles:
- laptop-battery-powersave
- virtual-guest
- desktop-powersave
- sap
- server-powersave
- virtual-host
- throughput-performance
- enterprise-storage
- laptop-ac-powersave
- latency-performance
- spindown-disk
- default
- my-virtual-host
Current active profile: virtual-host



在一个文本文件里有一个主机名(和 IP 地址)列表,通过 vi/vim 的上下键选择某个主机名(IP 地址)后,点击回车键就可以完成相应的 SSH 登陆。
不管 chef/puppet/salt/ansible 这类自动化配置工具多么智能,我们总有需要登陆到单台服务器上找问题的时候。总不能每次去翻 doc/txt 文档找相应的 IP 地址和用户名吧,找到 IP 地址和用户名后、copy 出来、切换窗口、再 ssh?有点累~~
机械的工作总是能找到替代的工具来完成,warp 就是这样一个小工具,确切的说是一个小 bash 脚本,warp 从 .warp 文本文件里读取主机名(IP 地址)信息,然后自动连上 ssh.
$ wget https://raw.githubusercontent.com/jpalardy/warp/master/warp
$ chmod +x warp

我们可以看到这个 .warp 文件格式很自由,只要保证第一列是主机名和 IP 地址(执行 ssh 命令格式的后半部分)就可以了,还可以用 — 和 # 当作注释方便我们区分和归类不同的服务器:
$ vi ~/.warp
# VIRTUAL MACHINE HOSTS

-- production servers

host101.vpsee.com -- xen host
host102.vpsee.com
root@host103.vpsee.com -- kvm host
user@host104.vpsee.com

-- development servers

172.20.2.101
172.20.2.102
root@172.20.2.103
user@172.20.2.104

# SUN GRID ENGINE HOSTS

sge101
sge102.cluster.vpsee.com
192.168.2.15 -- local datacenter

执行 warp 后会自动打开 vi/vim,然后使用 kj 键选择某行后回车即可:
$ ./warp

如果选择多行,warp 还支持 csshx 哦~

Monit 监测 Linux进程 不指定

kangyang , 2014/09/15 15:21 , LINUX系统管理 , 评论(0) , 阅读(5128) , Via 本站原创


Monit 是一个用来监测系统状态的工具,不但可以用来监视进程、服务、文件、目录、文件系统,还可以在服务 down 掉的时候自动重启服务或者当某个进程占用过多的资源的时候自动停掉进程,并且支持 Email 报警功能、远程服务器监测、web 管理界面等,功能很多很强大。VPSee 用 monit 来监测多个 VPS 和独立服务器,如果某个 VPS down 了、某个服务器资源紧张,就能第一时间知道,而且某个服务停了的话可以自动重启服务。
[size=2]安装 monit

在 CentOS 下安装和配置文件:
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# yum install monit
# vi /etc/monit.conf

在 Debian 下安装和配置文件:
# apt-get install monit
# vi /etc/monit/monitrc

配置 monit

修改 monit 的配置文件,/etc/monit.conf(CentOS)或者 /etc/monit/monitrc(Debian),每隔120秒检查一次系统,如果 httpd/mysql/sshd 服务停掉了就重新启动相应服务。对于 httpd 服务器,当发现 CPU/MEM 占用过大、loadavg 太高时就执行相应的报警、重启服务指令。如果使用 Email 报警功能,需要配置 Email 地址、邮件服务器等信息:
set daemon  120

check process sshd with pidfile /var/run/sshd.pid
   start program  "/etc/init.d/sshd start"
   stop program  "/etc/init.d/sshd stop"
   if failed port 22 protocol ssh then restart
   if 5 restarts within 5 cycles then timeout

check process mysql with pidfile /var/run/mysqld/mysqld.pid
   group database
   start program = "/etc/init.d/mysqld start"
   stop program = "/etc/init.d/mysqld stop"
   if failed host 127.0.0.1 port 3306 then restart
   if 5 restarts within 5 cycles then timeout

check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program  = "/etc/init.d/nginx stop"
    if failed host www.vpsee.com port 80 protocol http
       then restart

check process php_cgi with pidfile /var/run/php_cgi.pid
    start program = "/etc/init.d/php_cgi start"
    stop program  = "/etc/init.d/php_cgi stop"
    if failed host 127.0.0.1 port 9000 then restart
    if 5 restarts within 5 cycles then timeout

check process apache with pidfile /var/run/httpd.pid
   group www
   start program = "/etc/init.d/httpd start"
   stop program  = "/etc/init.d/httpd stop"
   if failed host www.vpsee.com port 8080 protocol http
      then restart
   if cpu is greater than 80% for 2 cycles then alert
   if cpu > 80% for 5 cycles then restart
   if totalmem > 512 MB for 5 cycles then restart
   if children > 200 then restart
   if loadavg(5min) greater than 10 for 8 cycles then stop
   if 3 restarts within 5 cycles then timeout

更多详细信息可以参考配置文件,里面注释写得很详细。
启动 monit
在 CentOS 下启动并加入到系统启动脚本:
# /etc/init.d/monit start
# /sbin/chkconfig monit on
在 Debian 下:
[code]# vi /etc/default/monit
# You must set this variable to for monit to start
startup=1
# /etc/init.d/monit start
# update-rc.d monit defaults


[/size]
Tags:
分页: 2/4 第一页 上页 1 2 3 4 下页 最后页 [ 显示模式: 摘要 | 列表 ]