安装cacti1.1到centos7

1.安装LAMP环境
CentOS 7, Apache 2.4, MariaDB 10.2, and PHP 7.1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 Install Apache 2.4
sudo yum install httpd -y
sudo sed -i 's/^/&/g' /etc/httpd/conf.d/welcome.conf
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
sudo yum install httpd -y
sudo sed -i 's/^/&/g' /etc/httpd/conf.d/welcome.conf
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Install MariaDB 10.2
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Secure MariaDB 10.2
sudo /usr/bin/mysql_secure_installation
When prompted, answer questions as below:
- Enter current password for root (enter for none): Just press the Enter button
- Set root password? [Y/n]: Y
- New password: your-MariaDB-root-password
- Re-enter new password: your-MariaDB-root-password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y

Create a MariaDB database for Cacti
mysql -u root -p
For security purposes, be sure to replace "cacti", "cactiuser", and "yourpassword" with your own ones.
CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Install required PHP 7.1 components for Cacti
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-process php71w-common php71w-pdo php71w-xml php71w-ldap php71w-mbstring php71w-gd php71w-snmp php71w-mysqlnd php71w-cli php71w-mcrypt php71w-opcache php71w-imap php71w-intl
sudo cp /etc/php.ini /etc/php.ini.bak
sudo sed -i 's;date.timezone =date.timezone = America/Los_Angeles' /etc/php.ini

Modify firewall rules
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

2.安装依赖

1
2
3
sudo yum install -y net-snmp net-snmp-utils rrdtool
sudo systemctl start snmpd.service
sudo systemctl enable snmpd.service

3.准备cacti安装包和配置数据库
下载Cacti安装包

1
2
3
cd
wget http://www.cacti.net/downloads/cacti-1.1.20.tar.gz
tar -zxvf cacti-1.1.20.tar.gz

移动文件到服务器目录,创建log日志文件,给予适当权限

1
2
3
4
sudo mv ~/cacti-1.1.20 /opt
sudo ln -s /opt/cacti-1.1.20 /var/www/html/cacti
sudo touch /opt/cacti-1.1.20/log/cacti.log
sudo chown -R apache:apache /opt/cacti-1.1.20

数据库导入时区信息

1
2
3
4
5
6
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql -u root -p cacti < /var/www/html/cacti/cacti.sql
mysql -u root -p
GRANT SELECT ON mysql.time_zone_name TO [email protected] IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
EXIT;

设置cacti参数

1
sudo vi /var/www/html/cacti/include/config.php

按需求设置以下参数

1
2
3
4
5
6
7
8
$database_type     = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'yourpassword';
$database_port = '3306';
$database_ssl = false;
$url_path = '/cacti/';

保存退出
设置定时任务

1
2
sudo crontab -u apache -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

4.为cacti设置Apache虚拟机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat <<EOF | sudo tee -a /etc/httpd/conf.d/cacti.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/
ServerName cacti.example.com
ServerAlias www.cacti.example.com
<Directory /var/www/html/cacti/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/cacti.example.com-error_log
CustomLog /var/log/httpd/cacti.example.com-access_log common
</VirtualHost>
EOF

重启Apache服务器

1
sudo systemctl restart httpd.service

5.更新mariaDB设置
备份my.cnf

1
2
sudo cp /etc/my.cnf /etc/my.cnf.bak
sudo vi /etc/my.cnf

找到[client-server],追加下列文本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
max_heap_table_size=64M
tmp_table_size=80M
join_buffer_size=80M
innodb_buffer_pool_size=256M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16

重启MariaDB

1
sudo systemctl restart mariadb.service

6.在web浏览器中打开安装向导
url: http://203.0.113.1/cacti