监测到的数据可通过Ndoutils插件存到mysql数据库中。在安装Ndoutils插件前,需要先安装mysql(如果先安装Ndo插件,再安装mysql的话,则数据写不到mysql。因为configure Ndo插件时候会找不到mysql库而出现一些错误)。存到数据库中的数据,可以使用cacti等工具,将数据显示出其趋势图来。
#yum install mysql-server
yum install mysql-devel
yum install mysql
service mysqld start
mysqladmin -u root password '111111'
安装mysql-devel
如果找不到相应的包,可以直接yum安装:
yum install mysql-devel
#mysql -u root -h 127.0.0.1 -p
Enter password:
mysql> create database nagios;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on nagios.* to ndouser@localhost identified by 'ndopassword';
grant all on nagios.* to [email protected] identified by 'ndopassword';
grant all on nagios.* to [email protected] identified by 'ndopassword';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
源代码包为mysql-5.6.13.tar.gz。
源码安装configure和make都非常慢,因此,如非必要,请使用rpm包安装。我在测试的时候,发现有些操作系统上使用rpm包,nagios无法写入数据到nagios_hosts表,因此,根据网上有关资料,尝试使用源码安装测试下。
# groupadd mysql
useradd -r -g mysql mysql
tar zxvf mysql-5.6.13.tar.gz
cd mysql-5.6.13
yum install cmake
yum install gcc-c++
yum install bison
rm CMakeCache.txt //如果已经cmake则再次cmake的时候需要删除这个CmakeCache文件
cmake .
make && make install
// 编译结束
// 更改用户和组属性,执行mysql_install_db初始化数据库
cd /usr/local/mysql
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql
如果出现FATAL ERROR: Could not find ./bin/my_print_defaults的错误,则请执行以下命令:
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
chown -R root .
chown -R mysql data
//(以下命令可选)拷贝配置文件到/etc目录下,启动mysql
#cp support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
[client]
socket=/var/lib/mysql/mysql.sock
/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -uroot -p
mysql>use mysql;
mysql> update user set password=PASSWORD(111111) where user='root';
mysql> flush privileges;
正常启动:
/usr/local/mysql/support-files/./mysql.server start
//(以下命令可选)设置mysql开机自启动
//# cp support-files/mysql.server /etc/init.d/mysql.server
#cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig -add mysqld
chkconfg mysqld on
mysqladmin -u root password '111111'
ln -s /usr/local/mysql/bin/mysql /usr/bin
http://blog.csdn.net/westmaniac/article/details/6535000
Linux源码安装mysql 5.5.13 (cmake编译)
2011-06-09 20:59 7163人阅读 评论(4) 收藏举报
mysqllinuxservice编译器工作
1.安装make编译器
下载地址: http://www.gnu.org/software/make/
[c-sharp]view plaincopy
1. tar zxvf make-3.82.tar.gz
2. cd make-3.82
3. ./configure
4. make
5. make install
2.安装bison
下载地址:http://www.gnu.org/software/bison/
[c-sharp]view plaincopy
1. tar zxvf bison-2.5.tar.gz
2. cd bison-2.5
3. ./configure
4. make
5. make install
3.安装gcc-c++
下载地址:http://www.gnu.org/software/gcc/
[c-sharp]view plaincopy
1. tar zxvf gcc-c++-4.4.4.tar.gz
2. cd gcc-c++-4.4.4
3. ./configure
4. make
5. make install
4.安装cmake
下载地址:http://www.cmake.org/
[c-sharp]view plaincopy
1. tar zxvf cmake-2.8.4.tar.gz
2. cd cmake-2.8.4
3. ./configure
4. make
5. make install
5.安装ncurses
下载地址:http://www.gnu.org/software/ncurses/
[c-sharp]view plaincopy
1. tar zxvf ncurses-5.8.tar.gz
2. cd ncurses-5.8
3. ./configure
4. make
5. make install
开始安装MySQL,下载地址:http://dev.mysql.com/
准备工作
[c-sharp]view plaincopy
1. groupadd mysql
2. useradd -r -g mysql mysql
解压并安装MySQL
[c-sharp]view plaincopy
1. tar zxvf mysql-5.5.13.tar.gz
2. cd mysql-5.5.13
3. cmake . /
4. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
5. -DINSTALL_DATADIR=/usr/local/mysql/data
6. make
7. make install
完成后,继续下面的操作
[c-sharp]view plaincopy
1. cd /usr/local/mysql
2. chown -R mysql .
3. chgrp -R mysql .
4. scripts/mysql_install_db --user=mysql
5. chown -R root .
下面的命令是可选的,将mysql的配置文件拷贝到/etc
[c-sharp]view plaincopy
1. cp support-files/my-medium.cnf /etc/my.cnf
启动mysql:
[c-sharp]view plaincopy
1. bin/mysqld_safe --user=mysql &
2. #启动mysql,看是否成功
3. netstat -tnl|grep 3306
上面是一种启动mysql的方法,还有一种简单的方便,如下:
[c-sharp]view plaincopy
1. #将mysql的启动服务添加到系统服务中
2. cp support-files/mysql.server /etc/init.d/mysql.server
3. #现在可以使用下面的命令启动mysql
4. service mysql.server start
5. #停止mysql服务
6. service mysql.server stop
7. #重启mysql服务
8. service mysql.server restart
将mysql服务添加到开机启动项,让mysql服务开机启动
[c-sharp]view plaincopy
1. chkconfig --add mysql.server
重启机器后,mysql服务就会自动启动了。
http://blog.chinaunix.net/uid-13954789-id-3432115.html
源码编译mysql5.5过程记录2012-12-06 17:18:29
分类: Mysql/postgreSQL
CentOS6.3源码安装mysql-5.5.27
#mysql5.5以上使用cmake代替configure编译,首先需要安装cmake
yum install cmake
# 建mysql用户和组
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# 解压tgz包,编译mysql
shell> tar zxvf mysql-5.5.27.src.tar.gz
shell> cd mysql-5.5.27
shell> cmake .
shell> make && make install
# 编译结束
# 更改用户和组属性,执行mysql_install_db初始化数据库
shell> cd /usr/local/mysql
shell> chown -R mysql:mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# (以下命令可选)拷贝配置文件到/etc目录下,启动mysql
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# (以下命令可选)设置mysql开机自启动
shell> cp support-files/mysql.server /etc/init.d/mysql.server
安装过程并不顺利,遇到好几次错误
1.没有安装 gcc 和 gcc-c++,执行cmake报如下错误:
==================================================
[root@ice mysql-5.5.27]# cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
..
-- Configuring incomplete, errors occurred!
==================================================
解决方法:安装gcc和gcc-c++
yum install gcc
yum install gcc-c++
#删除cache文件,不删除还会报错
rm CMakeCache.txt
cmake .
2.编译快结束时,又报如下错误:
Warning: Bison executable not found in PATH
解决方法:安装bison
yum install bison
rm CMakeCache.txt
cmake .
#编译通过
make && make install
#执行时间比较长
3.无法启动mysql
bin/mysqld_safe --user=mysql & 无法启动
解决方法:
再执行一次scripts/mysql_install_db --user=mysql
为什么会这样,原因不明
vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
[client]
socket=/var/lib/mysql/mysql.sock
/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql �Curoot -p
mysql>use mysql;
mysql> update user set password=PASSWORD(111111) where user='root';
mysql> flush privileges;
正常启动:
/usr/local/mysql/support-files/./mysql.server start
将nagios测试到的数据存储到mysql数据库。
#yum install perl_DBI
tar -zxvf ndoutils-1.5.2.tar.gz
cd ndoutils-1.5.2
./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
如果mysql是使用yum安装的,则这里configure安装会有问题,因为mysql有关的lib文件等不在上面configre参数所指的路径中。此时,可以直接使用:
./configure //由于mysql是yum安装无需制定使能mysql和lib参数ndo可以自动找到
make
编译完成后(不需要make install)
cd src/
cp ndomod-3x.o /usr/local/nagios/bin/
cp ndo2db-3x /usr/local/nagios/bin/
chmod 774 /usr/local/nagios/bin/ndo*
chown nagios.nagios /usr/local/nagios/bin/ndo*
cd ../config
cp ndo2db.cfg-sample ndo2db.cfg
cp ndomod.cfg-sample ndomod.cfg
cp ndo2db.cfg ndomod.cfg /usr/local/nagios/etc/
cd ..
cp daemon-init /etc/init.d/ndo2db
chmod 775 /etc/init.d/ndo2db
chkconfig --add ndo2db
chkconfig --level 35 ndo2db on
//上面的这一个创建ndo服务也可以直接使用以下命令启动:
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
如果启动出现Could not bind socket: Address already in use错误的话,可以查看下这个ndo进程是否存在,如果存在的话,则先杀掉;如果不存在的话,则删除以下文件后重新执行上面的命令:rm /usr/local/nagios/var/ndo.sock
chown -R nagios.nagios /usr/local/nagios/etc/ndo*
vi /usr/local/nagios/etc/ndo2db.cfg
修改以下参数(以下为网上拷贝的内容,这里可以不用做任何修改,请记录默认的这些参数值)
socket_name=/usr/local/nagios/var/ndo.sock
db_name=cacti nagios
db_prefix=npc_ nagios_
db_user=viong ndouser
db_pass=viong0623 ndopassword
debug_level=1
debug_file=/usr/local/nagios/var/ndo2db.debug
保存退出
vi ndomod.cfg
修改以下参数(以下为网上拷贝的内容,这里可以不用做任何修改,请记录默认的这些参数值)
output=/usr/local/nagios/var/ndo.sock
buffer_file=/usr/local/nagios/var/ndomod.tmp
保存退出
配置nagios.cfg:
# vi /usr/local/nagios/etc/nagios.cfg
# 复制下面内容粘贴到#broker_module=...下面。
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
此外,请确保您的/usr/local/nagios/etc/nagios.cfg中有如下行出现,否则,请自行添加:
event_broker_options=-1 //为Nagios开启event broker
process_performance_data=1 //这个参数是否有用不清楚,网上有些资料上都会写,但根据其解析,这个参数打开后,后面的几个参数才有用。但后面的参数这里都没有设置。
备注:以上内容是一行连接的,中间使用空格隔开的。
mysql>
./installdb -u root -p -h localhost -d nagios
或者:
# cd ndoutils-1.5.2/db
# mysql -uroot -p nagios<mysql.sql
1, 启动ndo2db
/etc/init.d/ndo2db start 或者
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
如果发现Could not bind socket: Address already in use的错误,请执行以下命令删除ndo.sock文件后重启服务器:
rm /usr/local/nagios/var/ndo.sock
When using the ndoutil in nagios (when you want nagios to connect to a mysql database) you’ll get an error when starting up following proces:
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
Could not bind socket: Address already in use
This is because there is still a lock file of this process. Remove the ‘ndo.sock’ and restart the process.
rm /usr/local/nagios/var/ndo.sock
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
The process will start normally.
2, 重启nagios:
service nagios restart
3, 重启nsca
#killall nsca
/usr/local/nagios/bin/nsca -c /usr/local/nagios/etc/nsca.cfg
http://blog.chinaunix.net/uid-17196076-id-2817707.html
http://www.linuxidc.com/Linux/2011-04/34029.htm
http://zhumeng8337797.blog.163.com/blog/static/10076891420109228431760/
http://www.linuxdiyf.com/bbs/thread-273524-1-1.html
http://www.linuxdiyf.com/viewarticle.php?id=273524
1, 使用yum安装的mysql一直没有插入数据到nagios_hosts表,而是用源代码编译安装的mysql,这个表中就能插入数据;
2, 在使用源代码编译安装mysql时会产生很多不明原因的错误。参见以上mysql源代码安装一节;
3, 而如果/usr/local/nagios/etc/ndo2db.cfg以及/usr/local/nagios/etc/ndomod.cfg属主不是nagios用户的话,将会报一下错误:ndomod: Still unable to connect to data sink,最后chown -R nagios.nagios /usr/local/nagios后,就能查到nagios_hosts表有数据了。
4, 后台/var/log/message一直报如下错误:
Aug 19 13:04:32 nagios-test ndo2db-3x: Warning: queue send error, retrying...
Aug 19 13:04:33 nagios-test ndo2db-3x: Message sent to queue.
处理方法:
vi /etc/sysctl.conf
kernel.msgmax = 131072000
kernel.msgmnb = 131072000
kernel.msgmni = 65536000
* kernel.msgmax is the maximum size of a single message in a message queue (每个消息的最大size)
* kernel.msgmni is the maximum number of messages allowed in any one message queue (整个系统的最大数量的消息队列)
* kernel.msgmnb is the total number of bytes allow in all messages in any one message queue(每个消息队列的最大字节限制,一个队列有多个消息)
5, naigos_hosts表一直没有数据
对这个表进行了跟踪,发现以往用yum安装的mysql数据库一直不会将数据插入到这个表,后来使用mysql的源代码编译安装后,这个表就有数据了。
这个表的数据是在nagios服务启动时生成,因此,如果删除了这个表的数据后,需要重启nagios服务才能生成数据。
在Cacti的Npc安装好后,可能npc_hosts也没有数据,重启nagios服务应该能够写入数据到这个表。
后来发现在centos5.8 64位操作系统中,使用rpm包安装的mysql,npc_hosts就有数据,各种现象还没梳理过有什么规律。但如果要用cacti监测nagios获取的数据,则要保证npc_hosts表中,要有各个host的数据。