失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > CentOS 7.6安装Cacti 1.2.3并解决中文界面乱码的问题

CentOS 7.6安装Cacti 1.2.3并解决中文界面乱码的问题

时间:2024-01-06 15:07:30

相关推荐

CentOS 7.6安装Cacti 1.2.3并解决中文界面乱码的问题

主要参考来源:/networken/article/details/81567337

1、Cacti架构

Cacti三层架构:

– 数据采集层:通过SNMP或自定义脚本进行数据采集

– 数据存储层:通过cacti模板等数据存放至MYSQL中

– 数据展现层:通过WEB方式呈现出来

Cacti实际上就是一个运行php脚本的网站

2、安装相关的软件包

2.1 安装httpd和php

# yum install -y httpd php

2.2 安装php扩展

# yum install –y php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix

2.3 设置php,据系统实际情况设定时区

[root@localhost ~]# vim /etc/php.ini[PHP]……date.timezone = Asia/Shanghai

2.4 启动httpd并设置开机启动

# systemctl start httpd && systemctl enable httpd

2.5 安装MariaDB 10.3数据库

设置yum源

[root@localhost ~]# vim /etc/yum.repos.d/MariaDB.repo# MariaDB 10.3 CentOS repository list - created -05-16 02:03 UTC# /mariadb/repositories/[mariadb]name = MariaDBbaseurl = /10.3/centos7-amd64gpgkey=/RPM-GPG-KEY-MariaDBgpgcheck=1

安装MariaDB

# yum install -y MariaDB-server MariaDB-client MariaDB-devel

启动mysql数据库服务并设为开机启动

# systemctl start mariadb && systemctl enable mariadb

配置MariaDB,初始化数据库,设定密码,除了开始直接回车,其他的选择都输入Y。

[root@localhost ~]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!......Enter current password for root (enter for none): //初始数据库密码为空,直接按回车键OK, successfully used password, moving on.........Set root password? [Y/n] Y //输入root管理员密码New password: Re-enter new password: Password updated successfully!......Remove anonymous users? [Y/n] Y //删除匿名账号... Success!......Disallow root login remotely? [Y/n] Y //禁止root管理员从远程登录... Success!.......Remove test database and access to it? [Y/n] Y //删除test数据库并取消对它的访问权限......Reload privilege tables now? [Y/n] Y //刷新授权表,让初始化后的设定立即生效... Success!

修改MariaDB配置

[root@cacti ~]# vim /etc/f.d/f[server]# this is only for the mysqld standalone daemoncharacter_set_server = utf8mb4collation-server = utf8mb4_unicode_cimax_heap_table_size = 256Mmax_allowed_packet = 16777216tmp_table_size = 64Mjoin_buffer_size = 64Minnodb_file_per_table = ONinnodb_buffer_pool_size = 1024Minnodb_doublewrite = OFFinnodb_flush_log_at_timeout = 3innodb_read_io_threads = 32innodb_write_io_threads =16innodb_file_format = Barracudainnodb_large_prefix = 1

2.6 安装net-snmp

# yum install –y net-snmp net-snmp-libs net-snmp-utils net-snmp-devel net-snmp-perl

配置snmp

# vim /etc/snmp/snmpd.conf//修改default为本机(cacti服务器)的ip,修改public为自己的团体名(一般不改),42行com2sec notConfigUser 192.168.2.186 public//把systemview改成all ,供所有snmp 访问权限 64行access notConfigGroup "" any noauth exact all none none view all included .1 80 // 去掉#号 85行

启动snmp并设置开机启动

# systemctl start snmpd.service && systemctl enable snmpd.service

2.7 安装RRDTool 绘图工具

安装编译时可能使用到的软件

yum -y install lm_sensors gcc gcc-c++ libart_lgpl-devel zlib-devel libpng-devel freetype-devel glib2-devel pcre-devel pango-devel cairo-devel libxml2-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

下载rrdtool 1.7.0

# cd /usr/local/src# wget https://oss.oetiker.ch/rrdtool/pub/rrdtool-1.7.0.tar.gz

编译安装rrdtool

注:网络上有说修改src/rrd_too.c里面的setlocale(LC_ALL, “”),在""内输入zh_CN.utf-8或zh_CN.gbk18030什么的,这是有问题的,会导致cacti英文界面仍显示中文星期的情况。

# tar zxvf rrdtool-1.7.0.tar.gz# cd rrdtool-1.7.0# ./bootstrap//一定要指定prefix# ./configure --prefix=/usr/local/# make & make install

2.8. 安装spine

先安装编译spine时的相关软件

yum install -y dos2unix autoconf automake binutils libtool cpp glibc-headers glibc-devel help2man

一定要下载与cacti相同版本的

# cd /usr/local/src# wget /downloads/spine/cacti-spine-1.2.3.tar.gz

编译安装

# tar zxvf cacti-spine-1.2.3.tar.gz# cd cacti-spine-1.2.3# ./bootstrap# ./configure# make && make install# chmod +s /usr/local/spine/bin/spine

编辑spine.conf:

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

我测试不作修改,可按实际情况修改/etc/spine.conf如下部分:

# vim /etc/spine.confDB_Host localhostDB_Database cactiDB_User cactiuserDB_Pass cactiuserDB_Port 3306

2.9 安装中文字体库

安装相关软件

# yum -y install fontconfig ttmkfdir

建立存放中文字体库的文件夹

# cd /usr/shared/fonts# mkdir chinese

将字体上传到/usr/shared/fonts/chinese

我这里就只安装个华文楷体和宋体,上传方式就不细说了。

执行ttmkfdir命令

# ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

因为cacti指定的字体库也没有在配置文件内指定,我估计不做下面这一步也是可以的,但我就不测试了。

修改字体配置文件

# vim /etc/fonts/fonts.conf

增加红色框内一行

刷新字体库缓存

# fc-cache

查询已经安装字体

[root@localhost]# fc-list/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique/usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规/usr/share/fonts/chinese/STKAITI.TTF: STKaiti:style=Regular/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book/usr/share/fonts/chinese/simsun.ttc: NSimSun,新宋体:style=Regular,常规/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold/usr/share/fonts/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book/usr/share/fonts/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight/usr/share/fonts/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique/usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique/usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique

3 安装及配置cacti 1.2.3

3.1 下载安装包

# cd /usr/local/src# wget /downloads/cacti-1.2.3.tar.gz# tar zxvf cacti-1.2.3.tar.gz# mv cacti-1.2.3 /var/www/html/cacti

3.2 创建cacti数据库,创建数据库用户cactiuser,设置用户相关授权

[root@localhost src]# mysql -uroot -pMariaDB [(none)]> create database cacti;Query OK, 1 row affected (0.002 sec)MariaDB [(none)]> grant all on cacti.* to cactiuser@localhost identified by "cactiuser";Query OK, 0 rows affected (0.003 sec)MariaDB [(none)]> grant select on mysql.time_zone_name to 'cactiuser'@'localhost' identified by 'cactiuser';Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> flush privileges;Query OK, 0 rows affected (0.002 sec)

3.3 导入 Cacti 默认数据库

MariaDB [(none)]> use cacti;Database changedMariaDB [cacti]> source /var/www/html/cacti/cacti.sql;......MariaDB [cacti]> flush privileges;Query OK, 0 rows affected (0.00 sec)

3.4 配置数据库时区:

[root@localhost ~]# mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysqlEnter password:Warning: Unable to load '/usr/share/zoneinfo//leapseconds' as time zone. Skipping it.Warning: Unable to load '/usr/share/zoneinfo//tzdata.zi' as time zone. Skipping it.

3.5 据实际情况配置cacti的config.php,我测试的所有按默认值,一般是修改第2、4、5行

[root@localhost ~]# vim /var/www/html/cacti/include/config.php......$database_type= 'mysql';$database_default = 'cacti';$database_hostname = 'localhost';$database_username = 'cactiuser';$database_password = 'cactiuser';$database_port= '3306';$database_retries = 5;$database_ssl= false;$database_ssl_key = '';$database_ssl_cert = '';$database_ssl_ca = '';......

3.6 创建 cacti 系统用户,设置目录权限

[root@localhost ~]# useradd cactiuser[root@localhost ~]# chown apache.apache /var/www/html/cacti/ -R[root@localhost ~]# chown cactiuser /var/www/html/cacti/{rra,log}/ -R[root@localhost ~]# chmod 775 /var/www/html/cacti/{rra,log}/ -R

3.7 重启相关服务

# systemctl restart httpd && systemctl restart mariadb && systemctl restart snmpd

3.8 初始化cacti

在浏览器访问:http://192.168.2.186/cacti,进入安装界面。

在进入安装之前建议关闭selinux,另请开放服务器的80端口,我这里是测试,所以我关闭了防火墙和selinux。

选择接受,再按开始,可以选择中文界面

如果出现错误 (Error)提示,请按提示相应修改,如果出现警告(Warning)则可以不修改,建议生产环境按建议修改为好。

按next继续

选择主服务器继续

出现这个继续

如果出现这个提示(Centos 7安装肯定会出现这个页面),请出行以下操作。

# rm -rf /var/www/html/cacti/log/cacti.log# chmod 777 /var/www/html/cacti/log/ -R

然后清理浏览器的缓存(主要是cookie),重新打开浏览器,重新登录(用修改了的密码)

一般就可以了。

注意:要选择正确的RRDtool版本

再按next继续

一般选择5分钟就行了,生产环境也可以了,我为了快点得到结果就选择了一分钟。

网络网段,请据实际情况选择。这个功能挺好用的,Cacti会将同一网段内所有设置好snmp的服务器自动加入监控,不过有些设置选项有问题导致图片没数据,我这里就关闭了。

继续就会出现以下画面:

继续

继续

Install

完成后重新登录

如果刚才已经正确的输入了spine.conf的路径,这里就不用再设置了

将cmd.php改为spine

3.9 管理设备及创建图形

删除自动生成的设备,管理>>设备

打勾,选择删除,点Go

增加设备,点击右上角的 +

主要是留意上面红圏内容,不能有错,其他默认就可以了。

删除没有数据的数据源。

点击那些0项目0列数据源后面的 x,再点保存。

建立图形

据自己的实际需要建立图形,注意红色圈的选择,选择其他的选项可能会没有数据。

加入树,管理>>树

点开Default Tree,再点编辑树,将可用设备的Cacti_server拖到 Local>Machine的里面,出现绿色的勾就可以放手。也可以增加其他的分支,把设备拖到相应的分支里面。最后点完全编辑树。

4、 建立定时任务,让系统每分钟更新一次数据。

建立之前重新刷新一下log目录权限,在Cacti系统初始化时生成的log文件权限不对,且用户及组都是apache。

# chmod -R 775 /var/www/html/cacti/log# chown -R cactiuser /var/www/html/cacti/log

登录用户cactiuser,测试运行,建立crontab。

[root@localhost ~]# su - cactiuserLast login: Fri May 17 17:00:43 CST on pts/0[cactiuser@localhost ~]$ php /var/www/html/cacti/poller.phpOK u:0.01 s:0.00 r:1.21......OK u:0.03 s:0.02 r:1.57/05/17 17:04:41 - SYSTEM STATS: Time:1.9020 Method:cmd.php Processes:1 Threads:N/A Hosts:1 HostsPerProcess:1 DataSources:18 RRDsProcessed:18OK u:0.03 s:0.02 r:1.60OK u:0.03 s:0.02 r:1.60//出现这些表明脚本运行OK[cactiuser@localhost ~]$ crontab -e //输入以下内容,如果是5分钟请把1改为5#For cacti*/1 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

查看图形是否生成。

点左上角的图形就可以查看

可以看到图形已经生成,并且中文正确显示。

我们改为英文界面,看看结果。

系统配置>>设置,基本

把语言改为英文,把自动检测禁用。

退出再重新登录,查看图形(Graph)

可以发现,界面的星期已经变为英文。

到了1.2.3版本,Cacti对中文的支持已经比较成熟了,界面已经基本上支持中文的了,我既不用改rrd_tool.c再编译rrdtoo,也不用修改cacti中的rrd.php,只要装了中文字体库就可以支持中文图形了。

我查了一下系统的默认语言,其实是英文来的。

[root@localhost ~]# echo $LANGen_US.UTF-8

所有的测试安装到此已经完成,如果有其他服务器经加入监控,请安装 net-snmp并按上面的snmpd.conf同样的设置,并开启防火墙相应的端口:161、162就可以了。

如果觉得《CentOS 7.6安装Cacti 1.2.3并解决中文界面乱码的问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。