個人安裝過程

系統環境:php

系統版本:centos 6.2html

安裝狀況:最小化安裝mysql

一,安裝LAMP環境linux

1.[root@mls]# yum -y install  gcc make vim unzip wget install httpd mysql mysql-devel mysql-server php php-devel php-mysql php-comman php-pdo php-gd lm_sensor net-snmp php-snmp net-snmp-utilsios

2.[root@mls]# chkconfig mysqld onweb

[root@mls]# chkconfig httpd onsql

[root@mls]# chkconfig snmpd on數據庫

[root@mls]# service mysqld startapache

[root@mls]#service httpd startjson

[root@mls]#service snmpd start

3.[root@mls]# mysqladmin -u root password '123456'

[root@mls]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on cacti.* to cactiuser@localhost identified by '654321';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

4.安裝rrdtool

wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.6.tar.gz

[root@mls ~]# tar xf rrdtool-1.4.4.tar.gz
[root@mls ~]# cd rrdtool-1.4.4
[root@mls rrdtool-1.4.4]# ./configure --prefix=/usr/local/rrdtool && make && make install

報錯:

configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no cairo-png.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of cairo-png. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libcairo and its header files. If
you have not installed cairo-png, you can get it either from its original home on

http://cairographics.org/releases/

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of cairo-png is 1.4.6.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for cairo_svg_surface_create in -lcairo... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no cairo-svg.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of cairo-svg. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libcairo and its header files. If
you have not installed cairo-svg, you can get it either from its original home on

http://cairographics.org/releases/

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of cairo-svg is 1.4.6.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for cairo_pdf_surface_create in -lcairo... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no cairo-pdf.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of cairo-pdf. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libcairo and its header files. If
you have not installed cairo-pdf, you can get it either from its original home on

http://cairographics.org/releases/

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of cairo-pdf is 1.4.6.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for cairo_ps_surface_create in -lcairo... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no cairo-ps.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of cairo-ps. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libcairo and its header files. If
you have not installed cairo-ps, you can get it either from its original home on

http://cairographics.org/releases/

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of cairo-ps is 1.4.6.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for glib_check_version in -lglib-2.0... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no glib-2.0.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of glib-2.0. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libglib-2.0 and its header files. If
you have not installed glib-2.0, you can get it either from its original home on

ftp://ftp.gtk.org/pub/glib/2.12/

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of glib-2.0 is 2.12.12.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for pango_cairo_context_set_font_options in -lpangocairo-1.0... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no pangocairo.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of pangocairo. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libpangocairo-1.0 and its header files. If
you have not installed pangocairo, you can get it either from its original home on

http://ftp.gnome.org/pub/GNOME/sources/pango/1.17

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of pangocairo is 1.17.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for xmlParseFile in -lxml2... no
checking for pkg-config... (cached) pkg-config
configure: WARNING:
----------------------------------------------------------------------------
* I found a copy of pkgconfig, but there is no libxml-2.0.pc file around.
You may want to set the PKG_CONFIG_PATH variable to point to its
location.
----------------------------------------------------------------------------

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of libxml-2.0. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libxml2 and its header files. If
you have not installed libxml-2.0, you can get it either from its original home on

http://xmlsoft.org/downloads.html

You can find also find an archive copy on

http://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of libxml-2.0 is 2.6.31.

LIBS=-lm
LDFLAGS=
CPPFLAGS= -I/usr/include/libxml2

----------------------------------------------------------------------------

configure: error: Please fix the library issues listed above and try again.
[root@bogon rrdtool-1.4.4]#

yum -y install libxml2-devel

yum -y install pango*

 

 

 

make[2]: Entering directory `/root/rrdtool-1.4.4/bindings'
make[3]: Entering directory `/root/rrdtool-1.4.4/bindings'
cd perl-piped && /usr/bin/perl Makefile.PL PREFIX=/usr/local/rrdtool LIB=/usr/local/rrdtool/lib/perl/5.10.1
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
BEGIN failed--compilation aborted at Makefile.PL line 1.
make[3]: *** [perl-piped/Makefile] Error 2
make[3]: Leaving directory `/root/rrdtool-1.4.4/bindings'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/rrdtool-1.4.4/bindings'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/rrdtool-1.4.4'
make: *** [all] Error 2

解決辦法:yum -y install perl-devel

再次執行[root@mls rrdtool-1.4.4]# ./configure --prefix=/usr/local/rrdtool && make && make install

ln -s /usr/local/rrdtool/bin/* /usr/local/bin/

5. 安裝cacti-0.8.7.e

wget  http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz

# tar xf cacti-0.8.7e.tar.gz -C /var/www/html/

# cd /var/www/html/

# mv cacti-0.8.7e/ cacti

# chown -R root.root /var/www/html/cacti/

6.導入數據庫

mysql -u root -p cacti <cacti/cacti.sql

Enter password

 

7.修改cacti配置文件,鏈接數據庫

vim /var/www/html/cacti/include/config.php

$database_username = "cactiuser";

$database_password = "654321";

########################################

 vim /var/www/html/cacti/include/global.php

$database_username = "cactiauser";

$database_password = "654321"

8.安裝cacti-plugin

# wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip

unzip cacti-plugin-0.8.7e-PA-v2.6.zip

cd cacti-plugin-arch/

 cp /root/cacti-plugin-arch/{cacti-plugin-0.8.7e-PA-v2.6.diff,pa.sql} /var/www/html/cacti/

 cd /var/www/html/cacti/

九、打補丁導入數據庫

yum -y install patch

# patch -p1 -N <cacti-plugin-0.8.7e-PA-v2.6.diff

# mysql -uroot -p cacti<pa.sql

10.修改配置文件

修改配置文件,以下:

vim include/global.php

$config['url_path'] = '/cacti/';

十一、添加計劃任務

# crontab -e

*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php

service crond restart

12.關閉iptables和selinux,沒法打開http://ip/cacti/install/界面

13.一切默認安裝 rrd 1.2 

14、被監控端配置(不要了)

# vim /etc/snmp/snmpd.conf

com2sec notConfigUser default public

group notConfigGroup v1 notConfigUser

group notConfigGroup v2c notConfigUser

view systemview included .1.3.6.1.2.1.1

view systemview included .1.3.6.1.2.1.25.1.1

access notConfigGroup "" any noauth exact mib2 none none

view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

syslocation Unknown (edit /etc/snmp/snmpd.conf)

syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

1五、重啓服務(不要了)
# service snmpd restart

到此就差很少了,咱們能夠作些檢測在服務器上,有信息返回說明正常:
# snmpwalk -v 2c -c public ServerIP if

1六、安裝nagios

一、創建用戶

  1. # useradd -s /bin/bash nagios
  2. # mkdir -p /usr/local/nagios
  3. # chown -R nagios.nagios /usr/local/nagios/

二、編譯安裝nagios

  1. # tar xf nagios-3.4.1.tar.gz
  2. # cd nagios
  3. # ./configure --prefix=/usr/local/nagios/
  4. # make all
  5. # make install
  6. # make install-init
  7. # make install-commandmode
  8. # make install-config
  9. # make install-webconf
  10. # chkconfig --add nagios(buyaole)
  11. # chkconfig nagios on
  12. # service nagios start

 

三、安裝插件

  1. # tar xf nagios-plugins-1.4.16.tar.gz
  2. # cd nagios-plugins-1.4.16
  3. # ./configure --prefix=/usr/local/nagios/ && make && make install

 

四、修改apache的配置文件

  1. # vim /etc/httpd/conf/httpd.conf
  2. 最後添加以下內容,設置成須要輸入密碼才能登錄
  3. ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
  4. <Directory "/usr/local/nagios/sbin">
  5. AuthType Basic
  6. Options ExecCGI
  7. AllowOverride None
  8. Order allow,deny
  9. Allow from all
  10. AuthName "Nagions Access"
  11. AuthUserFile /usr/local/nagios/etc/htpasswd
  12. Require valid-user
  13. </Directory>
  14. Alias /nagios "/usr/local/nagios/share"
  15. <Directory "/usr/local/nagios/share">
  16. AuthType Basic
  17. Options None
  18. AllowOverride None
  19. Order allow,deny
  20. Allow from all
  21. AuthName "Nagios Access"
  22. AuthUserFile /usr/local/nagios/etc/htpasswd
  23. Require valid-user
  24. </Directory>

五、配置nagios添加主機,服務信息
在/usr/local/nagios/etc/objects/下創建2個文件:

    1. (1)hosts.cfg定義主機的文件
    2. define host{
    3. use linux-server
    4. host_name 172.16.21.46
    5. address 172.16.21.46
    6. }
    7. (2)services.cfg 定義主機服務的文件
    8. define service{
    9. use local-service 
    10. host_name 172.16.21.46
    11. service_description ssh 
    12. check_command check_ssh 
    13. }
    14. define service{
    15. use local-service
    16. host_name 172.16.21.46
    17. service_description Ping
    18. check_command check_ping
    19. }
    20. # chown nagios.nagios /usr/local/nagios/etc/objects/{hosts.cfg,services.cfg}

 

六、創建登錄的用戶名密碼
# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin(################)

七、修改nagios.cfg文件,添加文件路徑信息:


# You can specify individual object config files as shown below:
#cfg_file=/usr/local/nagios//etc/objects/commands.cfg
#cfg_file=/usr/local/nagios//etc/objects/contacts.cfg
#cfg_file=/usr/local/nagios//etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios//etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

八、啓動nagios之後訪問輸入用戶名密碼就能夠看到Nagios了

檢查配置文件是否正確

[root@mls etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 3.3.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 07-25-2011
License: GPL

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/hosts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/services.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios//etc/objects/localhost.cfg'...
Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
Checked 9 services.
Checking hosts...
Checked 2 hosts.
Checking host groups...
Checked 1 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check

 

4、整合cacti+nagios
整合cacti和nagios是利用了cacti的一個插件nagios for cacti,它的原理是將nagios的數據經過ndo2db導入到mysql數據庫(cacti的庫中),而後cacti讀取數據庫信息將nagios

的結果展現出來。

一、安裝php-json擴展,由於NPC使用了ExtJS,如過沒有json的擴展NPC界面沒法出來。

# tar xf php-json-ext-1.2.1.tar.gz

# cd php-json-ext-1.2.1

# phpize

若是沒有命令的話安裝下面的軟件包

# rpm -ihv /media/CentOS/php-devel-5.1.6-27.el5.i386.rpm

# sh configure && make && make install

二、新建文件,添加信息以下:

# vim /etc/php.d/json.ini

extension=json.so

三、安裝ndoutils,須要安裝mysql-devel前面已經裝過這裏就不用再裝了

# tar xf ndoutils-1.4b9.tar.gz

# cd ndoutils-1.4b9

# ./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --with-ndo2db-user=nagios--with-ndo2db-group=nagios

# make(不用make install)

四、複製文件

# cp src/{ndomod-3x.o,ndo2db-3x,log2ndo,file2sock} /usr/bin/

# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg

# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

# chmod 644 /usr/local/nagios/etc/ndo*

五、修復配置文件信息,鏈接數據庫

# vim /usr/local/nagios/etc/ndo2db.cfg

socket_type=tcp

db_host=127.0.0.1

db_port=3306

db_name=cacti

db_prefix=npc_

db_user=cactiuser

db_pass=654321

debug_level=1

# vim /usr/local/nagios/etc/ndomod.cfg

output_type=tcpsocket

output=127.0.0.1

六、添加啓動腳本,並修改Ndo2dbBin

# cp /download/ndoutils-1.4b9/daemon-init /etc/init.d/ndo2db

# vim  /etc/init.d/ndo2db

/etc/init.d/ndo2dbNdo2dbBin=/usr/bin/ndo2db-3x

# service ndo2db start

[root@mls ndoutils-1.4b9]# service ndo2db start
Starting ndo2db:Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied
: Permission denied
done.

[root@mls ndoutils-1.4b9]# chmod 700 /etc/init.d/ndo2db

Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied  : Permission denied

修改ndo2db.lock的所屬組和用戶對它有寫的權限

七、安裝npc

# tar xf npc-2.0.4.tar.gz

# mv npc /var/www/html/cacti/plugins/

修改配置文件,添加以下信息

# vim /var/www/html/cacti/include/global.php

$plugins = array();

$plugins[]='npc';

 

 八、修改nagios添加信息:

# vim /usr/local/nagios/etc/nagios.cfg

broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

event_broker_options=-1

service nagios restart

啓動以後在cacti中添加npc,以下:

添加npc

9.可是看npc裏發現空白的,沒有數據,是由於php沒有PDO_MYSQL支持,因此安裝PDO_MYSQL(暫時沒有安裝了)

  1. # wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
  2. # tar zxvf PDO_MYSQL-1.0.2.tgz
  3. # cd PDO_MYSQL-1.0.2
  4. # /usr/bin/phpize
  5. #./configure --with-php-config=/usr/bin/php-config
  6. #make
  7. #make install
  8. 修改php.ini,添加以下信息,以後重啓httpd便可
  9. extension = "pdo_mysql.so"

十、以後再訪問還不行,還要修改數據庫結構:

  1. # mysql -u root -p
  2. use cacti
  3. mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
  4. mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
  5. mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
  6. mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
  7. mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
  8. mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
  9. mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
  10. mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;

11.以後再訪問仍是沒有數據了,另外cacti沒法顯示圖片,可是點進去有圖:

解決方法:settings裏面的RRDTOOLS版本設置不對,默認爲1.0.x,改成1.2.x就好了。

相關文章
相關標籤/搜索