Friday, June 29, 2012

Oracle数据库监控脚本


  1. 检查实例的可用性
  2. 检查监听器的可用性
  3. 检查alert日志文件中的错误信息
  4. 在存放log文件的地方满以前清空旧的log文件
  5. 分析table和index以获得更好的性能
  6. 检查表空间的使用情况
  7. 找出无效的对象
  8. 监控用户和事务

显示服务器上的可用实例:

$ ps -ef | grep smon
oracle 21832 1 0 Feb 24 ? 19:05 ora_smon_oradb1
oracle 898 1 0 Feb 15 ? 0:00 ora_smon_oradb2
dliu 25199 19038 0 10:48:57 pts/6 0:00 grep smon
oracle 27798 1 0 05:43:54 ? 0:00 ora_smon_oradb3
oracle 28781 1 0 Mar 03 ? 0:01 ora_smon_oradb4

显示服务器上的可用监听器:

$ ps -ef | grep listener | grep -v grep
oracle 23879 1 0 Feb 24 ? 33:36 /8.1.7/bin/tnslsnr listener_db1 -inherit
oracle 27939 1 0 05:44:02 ? 0:00 /8.1.7/bin/tnslsnr listener_db2 -inherit
oracle 23536 1 0 Feb 12 ? 4:19 /8.1.7/bin/tnslsnr listener_db3 -inherit
oracle 28891 1 0 Mar 03 ? 0:01 /8.1.7/bin/tnslsnr listener_db4 -inherit

查看Oracle存档目录的文件系统使用情况

$ df -k | grep oraarch
/dev/vx/dsk/proddg/oraarch 71123968 4754872 65850768 7% /u09/oraarch

列出alert.log文件中的全部Oracle错误信息:

$ grep ORA- alert.log
ORA-00600: internal error code, arguments: [kcrrrfswda.1], [], [], [], [], []
ORA-00600: internal error code, arguments: [1881], [25860496], [25857716], []

检查Oracle实例的可用性

oratab文件中列出了服务器上的所有数据库
$ cat /var/opt/oracle/oratab
############################################################
## /var/opt/oracle/oratab                                 ##
############################################################
oradb1:/u01/app/oracle/product/8.1.7:Y
oradb2:/u01/app/oracle/product/8.1.7:Y
oradb3:/u01/app/oracle/product/8.1.7:N
oradb4:/u01/app/oracle/product/8.1.7:Y


以下的脚本检查oratab文件中列出的所有数据库,并且找出该数据库的状态(启动还是关闭)

## ckinstance.ksh ##
ORATAB=/var/opt/oracle/oratab
echo `date`
echo Oracle Database(s) Status `hostname` :
db=`egrep -i :Y|:N $ORATAB | cut -d: -f1 | grep -v # | grep -v *`
pslist=`ps -ef | grep pmon`
for i in $db ; do
echo $pslist | grep ora_pmon_$i > /dev/null 2>$1
if (( $? )); then
echo Oracle Instance - $i: Down
else
echo Oracle Instance - $i: Up
fi
done


使用以下的命令来确认该脚本是可以执行的:

$ chmod 744 ckinstance.ksh
$ ls -l ckinstance.ksh
-rwxr--r-- 1 oracle dba 657 Mar 5 22:59 ckinstance.ksh*


以下是实例可用性的报表:

Wednesday, June 27, 2012

Openstack Glance 导入ubuntu 10.04 Image

#!/bin/bash

if [ ! -f "lucid-server-cloudimg-amd64.tar.gz" ] ; then
echo "Downloading image"
wget http://cloud-images.ubuntu.com/lucid/current/lucid-server-cloudimg-amd64.tar.gz
fi

if [ ! -f "lucid-server-cloudimg-amd64.img" ] ; then
echo "Extracting image"
tar xfzv lucid-server-cloudimg-amd64.tar.gz
fi

echo "Uploading kernel"
RVAL=`glance add name="ubuntu-lucid-kernel" is_public=true container_format=aki disk_format=aki < lucid-server-cloudimg-amd64-vmlinuz-virtual`
KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`

echo "Uploading image"
glance add name="ubuntu-lucid" is_public=true container_format=ami kernel_id=$KERNEL_ID disk_format=ami < lucid-server-cloudimg-amd64.img

Wednesday, June 20, 2012

Python and Linux Command

import commands
out = commands.getoutput("ls")
print out

Wednesday, June 13, 2012

MySQL调优

1, 查看MySQL服务器配置信息
mysql> show variables;

2, 查看MySQL服务器运行的各种状态值
mysql> show global status;

3, 慢查询
mysql> show variables like '%slow%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| log_slow_queries | OFF |
| slow_launch_time | 2 |
+------------------+-------+
mysql> show global status like '%slow%';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| Slow_launch_threads | 0 |
| Slow_queries | 279 |
+---------------------+-------+


配置中关闭了记录慢查询(最好是打开,方便优化),超过2秒即为慢查询,一共有279条慢查询
4, 连接数
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 500 |
+-----------------+-------+

mysql> show global status like 'max_used_connections';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 498 |
+----------------------+-------+

设置的最大连接数是500,而响应的连接数是498
max_used_connections / max_connections * 100% = 99.6% (理想值 ≈ 85%)

5, key_buffer_size
key_buffer_size是对MyISAM表性能影响最大的一个参数, 不过数据库中多为Innodb
mysql> show variables like 'key_buffer_size';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| key_buffer_size | 67108864 |
+-----------------+----------+

mysql> show global status like 'key_read%';
+-------------------+----------+
| Variable_name | Value |
+-------------------+----------+
| Key_read_requests | 25629497 |
| Key_reads | 66071 |
+-------------------+----------+

一共有25629497个索引读取请求,有66071个请求在内存中没有找到直接从硬盘读取索引,计算索引未命中缓存的概率:
key_cache_miss_rate = Key_reads / Key_read_requests * 100% =0.27%
需要适当加大key_buffer_size
mysql> show global status like 'key_blocks_u%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Key_blocks_unused | 10285 |
| Key_blocks_used | 47705 |
+-------------------+-------+

Key_blocks_unused表示未使用的缓存簇(blocks)数,Key_blocks_used表示曾经用到的最大的blocks数
Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 18% (理想值 ≈ 80%)

Friday, June 1, 2012

nagios 3 + ndoutils-1.5 问题

环境: CentOS 6 ,Nagios3.2 , ndoutils-1.5.
错误

Feb 28 19:04:37 monitor nagios: ndomod: Successfully connected to data sink. 0
queued items to flush.
Feb 28 19:04:37 monitor nagios: Event broker module
'/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
Feb 28 19:04:37 monitor nagios: Finished daemonizing... (New PID=3160)
Feb 28 19:04:37 monitor ndo2db-3x: Error: queue send error.


需要设置

kernel.msgmax = 131072000
kernel.msgmnb = 131072000
kernel.msgmni = 65536000


中文问题解决:
设置为UTF-8
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
default-character-set = utf8
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8