cacti監控安裝

cacti是用PHP實現的一個軟件,它用snmp服務獲取數據,而後用rrdtool存儲和更新數據,並生成圖表展現。比較適合用於交換機、路由器的網絡監控,插件衆多,可圖示化顯示網絡情況。php

cacti官方推薦版本以下:
PHP 5.4+
MySQL 5.1+
RRDtool 1.3+, 1.5+ recommended
NET-SNMP 5.5+
Web Server with PHP support

html

centos7.5上安裝記錄:
#安裝php7.1和apache2.4
yum install -y epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php71w php71w-devel php71w-common php71w-ldap php71w-gd php71w-xml php71w-cli php71w-pear php71w-mbstring php71w-mysql php71w-snmp httpd
mysql

#php配置
vi /etc/php.ini
date.timezone = Asia/Shanghai
error_log = syslog
web

systemctl start httpd
systemctl enable httpd
sql

#安裝MySQL5.7.23
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum install -y mysql-community-server mysql-community-devel
systemclt start mysqld
systemctl enable mysqld
數據庫

grep password /var/log/mysqld.log
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
apache

#安裝cacti
yum -y install net-snmp net-snmp-devel net-snmp-utils net-snmp-libs rrdtool help2man
centos

wget https://www.cacti.net/downloads/cacti-1.1.38.tar.gz
tar zxvf cacti-1.1.38.tar.gz
服務器

cd cacti-1.1.38
#創建cacti用戶並導入數據結構
mysql -u root -p
create databases cacti;
create user 'cacti'@'localhost' identified by 'Uiop!789';
grant all privileges on *.* to 'cacti'@'localhost';
flush privileges;
use cacti;
source cacti.sql;
網絡

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

mv cacti-1.1.38 /var/www/html/cacti
adduser -d /var/www/html/cacti -s /sbin/nologin cacti
echo "*/5 * * * * cacti php /var/www/html/cacti/poller.php &>/dev/null" >> /etc/cron.d/cacti
cd /var/www/html/cacti
chown -R cacti.apache rra log  
chmod 775 rra log

#修改cacti數據庫配置
vi /var/www/html/cacti/include/config.php
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'Uiop!789';
$database_port     = '3306';
$database_ssl      = false;

#httpd配置,注意apache2.4和2.2寫法不太同樣
cat > /etc/httpd/conf.d/cacti.conf <<EOF
# Cacti - the complete rrdtool-based graphing solution

# Allows only localhost by default
#
# Allowing cacti to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

# Make sure, that httpd can read your cacti directories.
# At minimum, you need
#    chmod ugo+r -R /your/cacti/dir
# Make sure to replace with your directories

# When using SELinux, set the following:
#    chcon -R -h -t httpd_sys_content_t /your/cacti/dir
# when using SELinux and you private homedir, enable
#    setsebool -P httpd_enable_homedirs 1
#    setsebool -P httpd_read_user_content 1

Alias /cacti /var/www/html/cacti
<Directory /var/www/html/cacti>
   AllowOverride All
   Require all granted
   Options Indexes Includes FollowSymLinks
</Directory>

# These directories do not require access over HTTP 
#
<Directory /var/www/html/cacti/cli>
   Require all denied
   Require all granted
</Directory>
EOF

systemctl restart httpd

#http://serverIP/cacti,按提示配置MySQL
vi /etc/my.cnf
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
port            = 3306
default-character-set=utf8mb4

[mysqld]
port            = 3306
skip-name-resolve
character-set-server=utf8mb4
max_connections=1000
max_heap_table_size=1024M
max_allowed_packet=32M
tmp_table_size=128M
join_buffer_size=128M
innodb_buffer_pool_size=4096M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=5
innodb_read_io_threads=32
innodb_write_io_threads=16
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

systemctl restart mysqld

#安裝cacti-spine抓包工具
wget https://www.cacti.net/downloads/spine/cacti-spine-1.1.38.tar.gz
tar zxvf cacti-spine-1.1.38.tar.gz
cd cacti-spine-1.1.38
./configure
make && make install

cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
vi /usr/local/spine/etc/spine.conf
DB_Host                 localhost
DB_Database             cacti
DB_User                 cacti
DB_Pass                 Uiop!789
DB_Port                 3306

#測試是否正常
[root@localhost ~]# /usr/local/spine/bin/spine -C /usr/local/spine/etc/spine.conf
SPINE: Using spine config file [/usr/local/spine/etc/spine.conf]
SPINE: Version 1.1.38 starting
SPINE: Time: 0.1116 s, Threads: 5, Devices: 0

http://IP/cacti便可按提示安裝
chown -R apache.apache /var/www/html/cacti/resource/
chown -R apache.apache /var/www/html/cacti/cache

1,cacti官方網站https://docs.cacti.net-> forums -> Scripts and Templates, 搜索須要的模板,可本身修改
在cacti控制頁面
2,導入模板
3,添加device,並將device添加到對應模板,創建對應圖形,將圖形添加到tree。
隨後便可在圖形選項卡看到生成的圖表

例如監控esxi主機172.16.90.205
開啓ssh服務器登陸

ESXI5.5開啓snmp+zabbix 監控esxi 須要開啓的服務
esxcli system snmp set --communities public 
esxcli system snmp set --enable true
####容許全部主機訪問snmp服務
esxcli network firewall ruleset set --ruleset-id snmp --allowed-all true 
esxcli network firewall ruleset set --ruleset-id snmp --enabled true
/etc/init.d/snmpd restart

####若是要只容許特定的IP地址訪問snmp服務
esxcli network firewall ruleset set --ruleset-id snmp --allowed-all false
esxcli network firewall ruleset allowedip add --ruleset-id snmp --ip-address 10.0.101.0/24
esxcli network firewall ruleset set --ruleset-id snmp --enabled true
/etc/init.d/snmpd restart

vi /etc/vmware/snmp.xml
將enable修改成true
/sbin/services.sh  restart

cacti服務器端測試使用命令snmpwalk -c public -v 1 172.16.90.205,收到數據即OK

相關文章
相關標籤/搜索