最小化安裝 CentOS 7.3 部署 Cacti-1.1.23 詳細步驟

支持原創(轉載地址):https://www.centos.bz/2017/09/%E6%9C%80%E5%B0%8F%E5%8C%96%E5%AE%89%E8%A3%85-centos-7-3-%E9%83%A8%E7%BD%B2-cacti-1-1-23-%E8%AF%A6%E7%BB%86%E6%AD%A5%E9%AA%A4/

•    一、安裝環境

•    二、軟件安裝

o    2.1 更新 YUM 源

o    2.2 安裝 Cacti 部署環境所需軟件包

•    三、環境配置

o    3.1 配置 PHP

o    3.2 配置 Web 服務器 Apache httpd

o    3.3 配置數據庫 MariaDB

o    3.4 配置 SNMP

•    四、安裝配置 Cacti

o    4.1 下載解壓 Cacti 安裝包

o    4.2 創建 cacti 數據庫,創建 cactiuser 用戶,設置相關授權

o    4.3 導入 Cacti 默認數據庫

o    4.4 編輯 /var/www/html/cacti-1.1.23/include/config.php,給Cacti指定數據庫類型,名稱,用戶名,密碼等

o    4.5 創建 cacti 系統用戶,設置 graph/log 目錄權限

o    4.6 添加定時任務

•    五、配置防火牆

o    5.1 配置 firewalld 防火牆

o    5.2 關閉selinux

•    六、設置開機啓動相關服務

•    七、重啓相關服務

•    八、登錄 Cacti Web 安裝界面

•    九、安裝 spine

o    9.1 下載解壓與 Cacti 相同版本號 Spine 源碼安裝包

o    9.2 源碼編譯安裝 spine

o    9.3 複製修改配置文件

o    9.4 登錄 Cacti WEB 頁面修改 Cacti 配置

•    十、特別提示

Cacti 是一個利用 RRDTool 數據存儲和繪圖功能的完整的網絡圖形解決方案。Cacti 提供了快速的數據輪詢、高級圖形模板、多樣的數據獲取方法以及用戶管理等功能。並以直觀易於使用的接口來呈現,這在具有成千上萬個設備的複雜網絡上是有意義的。

一、安裝環境

安裝 Cacti 需要 Mysql,PHP,RRDTool,net-snmp 和 支持 PHP 的 Web服務器,如 Apache,Nginx 或 IIS等。

版本要求:

•    RRDTool 1.3 或更高版本,http://oss.oetiker.ch/rrdtool/

•    MySQL 5.1 或更高版本,https://mysql.com/

•    MariaDB 5.5 或更高版本,https://mariadb.org/

•    PHP 5.4 或更高版本,https://php.net/

•    支持PHP的Web服務器,如Apache,NGINX 或 IIS(https://www.apache.org/,https://www.nginx.com/)

本次安裝 Cacti-1.1.23 使用相關軟件及版本爲:

•    RRDTool 1.4.8

•    MariaDB 10.2.8 (mariadb mariadb-server)

•    PHP 5.4.16 (php php-snmp php-ldap php-xml php-session php-sockets php-pdo php-pdo-mysql php-mbstring php-pcre php-json php-openssl php-gd php-gmp php-zlib)

•    Apache httpd 2.4.6

•    net-snmp 5.7.2 (net-snmp net-snmp-utils)

•    crond (cronie 或其他類似軟件)

爲了安裝官方補丁,還需要安裝一些工具軟件

•    wget

•    patch

二、軟件安裝

2.1 更新 YUM 源

添加 MariaDB YUM 倉庫

# cat > /etc/yum.repos.d/MariaDB.repo <<EOF

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.2/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

EOF

因爲官網的源下載安裝非常慢,可以用以下源:

# MariaDB 10.2 CentOS repository list - created 2017-07-03 06:59 UTC

# http://downloads.mariadb.org/mariadb/repositories/

# cat > /etc/yum.repos.d/MariaDB.repo <<EOF

[mariadb] 

name = MariaDB

baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64

gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1

EOF

2.2 安裝 Cacti 部署環境所需軟件包

# yum install -y httpd mariadb mariadb-server mariadb-devel net-snmp net-snmp-utils net-snmp-libs net-snmp-agent-libs net-snmp-devel php php-snmp php-ldap php-pdo php-mysql php-devel php-pear php-common php-gd php-mbstring php-xml php-process rrdtool rrdtool-php rrdtool-perl rrdtool-devel gcc openssl-devel dos2unix autoconf automake binutils libtool cpp postfix glibc-headers kernel-headers glibc-devel gd gd-devel help2man ntpdate wget patch

三、環境配置

3.1 配置 PHP

修改 PHP 主配置文件 /etc/php.ini

關閉安全模式,以支持 rrdtool,允許 exec() 訪問

vim /etc/php.ini

[PHP]

safe_mode = Off

設置時區

[Date]

date.timezone = PRC

測試一下php 

在/var/www/html 新建一個文件爲 index.php

cat > /var/www/html/index.php<<EOF

<?php

phpinfo();

EOF

3.2 配置 Web 服務器 Apache httpd

編輯 vim /etc/httpd/conf.d/php.conf 配置文件,確保文件含有

LoadModule php5_module modules/libphp5.so 

AddHandler php5-script .php 

如果你不打算將 Cacti 安裝到 Web 服務器默認目錄,如/var/www/html,就需要將下面內容添加

至 /etc/httpd/conf.d/cacti.conf 文件,並將其中的 /your/cacti/dir 替換爲實際安裝目錄,將

Allow from 127.0.0.1 改爲你公司所在網段。

#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 None

   Order Deny,Allow

   Deny from all

   Allow from all    (如果all改成127.0.0.1無法訪問403錯誤)

   Allow from ::

   Options Indexes Includes FollowSymLinks

</Directory>

#These directories do not require access over HTTP 

<Directory /var/www/html/cacti/cli>

    Order Deny,Allow

    Deny from All

    Allow from None

</Directory>

EOF

3.3 配置數據庫 MariaDB

爲安全起見,設置數據庫 root 用戶密碼

# systemctl start mariadb

#systemctl enable mariadb

# mysqladmin -uroot password ossoup(將數據庫密碼設置成ossoup)

導入時區數據到 mysql 數據庫

image.png

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql -p

修改 vim /etc/my.cnf.d/server.cnf 文件,確保文件含有

[mysqld]

character_set_server = utf8mb4

collation_server = utf8mb4_unicode_ci

character_set_client = utf8mb4

max_connections = 100

max_heap_table_size = 200M

max_allowed_packet = 16777216

join_buffer_size = 80M

tmp_table_size = 80M

innodb_file_per_table = ON

innodb_buffer_pool_size = 240M

innodb_doublewrite = OFF

innodb_lock_wait_timeout = 50

innodb_flush_log_at_timeout = 4

innodb_read_io_threads = 32

innodb_write_io_threads = 16

innodb_buffer_pool_size=1024M

3.4 配置 SNMP

配置 net-snmp-agent, 修改配置文件 vim /etc/snmp/snmpd.conf

將41行改爲監控服務器ip;2 將public 改成複雜些的識別的字符串 

com2sec notConfigUser  default       public

改爲

com2sec notConfigUser  127.0.0.1     public

將62行 供所有snmp 訪問權限 

access  notConfigGroup ""      any       noauth    exact  systemview none none

改爲 

access  notConfigGroup ""      any       noauth    exact  all    none   none

將85行

#view all    included  .1      80

改爲

view all    included  .1        80

測試net-snmp

# service snmpd start

 snmpd 使用 tcp/udp 161 端口,驗證snmpd 服務

使用snmpwalk 命令驗證

snmpwalk -v 2c -c public 127.0.0.1

-v是指版本,-c 是指密鑰,獲取到系統信息則正常!

如果cacti搭建好後很久還是沒出圖,用這個命令試試看能否獲取到數據。

正常情況下,執行完這個命令後會有很多數據出現!

四、安裝配置 Cacti

4.1 下載解壓 Cacti 安裝包

# cd /var/www/html

# wget  https://www.cacti.net/downloads/cacti-1.1.38.tar.gz

# tar -zxvf cacti-1.1.38.tar.gz

4.2 創建 cacti 數據庫,創建 cactiuser 用戶,設置相關授權

# mysql -u root -p

MariaDB [(none)]> CREATE database cacti default character set utf8;

MariaDB [(none)]> create user 'cactiuser'@'localhost' identified by 'cactiuser';

MariaDB [(none)]> grant all privileges on cacti.* to cactiuser@localhost;

MariaDB [(none)]> grant select on mysql.time_zone_name to 'cactiuser'@'localhost' identified by 'cactiuser';

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> quit

4.3 導入 Cacti 默認數據庫

# mysql -uroot -p cacti < /var/www/html/cacti-1.1.38/cacti.sql

4.4 編輯vim /var/www/html/cacti-1.1.38/include/config.php,給Cacti指定數據庫類型,名稱,用戶名,密碼等

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cactiuser";

$database_password = "cactiuser";

/* load up old style plugins here */

$plugins = array();

//$plugins[] = 'thold';

4.5 創建 cacti 系統用戶,設置 graph/log 目錄權限

# useradd -r -M cacti

# ln -s /var/www/html/cacti-1.1.38  /var/www/html/cacti

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

# chown -R cacti /var/www/html/cacti-1.1.38/{rra,log}/或者chown -R cacti /var/www/html/cacti-1.1.38/rra/

chown -R cacti /var/www/html/cacti-1.1.38/log/

4.6 添加定時任務

# crontab -e 

*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1

五、配置防火牆

5.1 配置 firewalld 防火牆

# firewall-cmd --permanent --add-port=3306/tcp

# firewall-cmd --permanent --add-service=http

# firewall-cmd --permanent --add-port=161/udp

# firewall-cmd --permanent --add-port=162/udp

# firewall-cmd --reload

5.2 關閉selinux

# setenforce 0

# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

六、設置開機啓動相關服務

# systemctl enable httpd

# systemctl enable mariadb

# systemctl enable crond

# systemctl enable snmpd

七、安裝 spine

7.1 下載解壓與 Cacti 相同版本號 Spine 源碼安裝包

# cd /usr/local/src

#wget https://www.cacti.net/downloads/spine/cacti-spine-1.1.38.tar.gz

#tar -xzvf cacti-spine-1.1.38.tar.gz

7.2 源碼編譯安裝 spine

# ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient.so

# ntpdate 202.120.2.101

# cd cacti-spine-1.1.38

# ./configure && make && make install

7.3 複製修改配置文件

# cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf

修改spine.conf文件內用戶名及密碼配置

vim /usr/local/spine/etc/spine.conf

DB_Host                 localhost

DB_Database             cacti

DB_User                 cactiuser

DB_Pass                 cactiuser

DB_Port                 3306

RDB_Host                localhost

RDB_Database            cacti

RDB_User                cactiuser

RDB_Pass                cactiuser

RDB_Port                3306

八、重啓相關服務

# systemctl restart httpd

# systemctl restart mariadb

# systemctl restart crond

# systemctl restart snmpd

九、登錄 Cacti Web 安裝界面

使用瀏覽器登錄

http://your-server/cacti/

image.png

勾選 “Accept GPL License Agreement” –> Next –> Next –> 下一步 –> Next –> Next –> 勾選所有預置模版 –> Finish

使用初始登錄用戶名和密碼(admin)登錄,然後更改初始密碼。

進入Cacti Web 管理界面。

9.1 登錄 Cacti WEB 頁面修改 Cacti 配置

Console -> 設置(Cacti Settings) -> Paths -> 在 Spine Binary File Location 文本框內填入配置文件路徑 /usr/local/spine/bin/spine ,在 Spine Config File Path 文本框內填入配置文件路徑 /usr/local/spine/etc/spine.conf,點擊保存 (Save)。

Console -> 設置(Cacti Settings) -> Poller -> 在 Poller Type 下拉框中選擇 spine ,點擊保存 (Save)。

十、特別提示

在添加完設備和圖形後,需要重建採集器緩存。

Console –> 系統工具 –> Rebuild Poller Cache

image.png

1、ERROR: Your Cacti database login account does not haveaccess to the MySQL TimeZone database. Please provide the Cacti databaseaccount "select" access to the "time_zone_name" table inthe "mysql" database, and populate MySQL's TimeZone informationbefore proceeding.

# grant all privileges on *.* to cacti@localhost identified by 'cacti';

# flush privileges;


2、image.png

ERROR: Your MySQL TimeZone database is not populated.Please populate this database before proceeding.

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


3、ERROR: 安裝cacti-spine報錯false// No help2man // --output=spine.1 --name='Data Collector for Cacti' --no-info--version-option='--version' ./spine make: *** [spine.1] 錯誤 1

# 安裝help2man

# yum -y install help2man


Cacti登錄密碼忘記,重置Cacti密碼

2017年04月11日 20:25:18

閱讀數:3099

用root用戶進入系統

[root@localhsot]# mysql -u root -p

mysql> show databases;

mysql> use cacti;

mysql> show tables;

mysql> select from user_auth;

mysql> update user_auth set password=md5("cactipasswd") where id='1';

現在cacti新密碼就是cactipasswd


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章