lbdbzj110 发表于 2019-1-9 10:54:17

记录一次cacti中文乱码解决经过

  背景:公司一台老机器,上面有个cacti。系统为centos5.X,有天手滑卸载了httpd,但yum源已经不支持centos5系列了,无奈百度上找了一个源内容如下:
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the   
# remarked out baseurl= line instead.
#
#


name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://vault.centos.org/5.11/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates   

name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://vault.centos.org/5.11/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful

name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://vault.centos.org/5.11/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


#additional packages that extend functionality of existing packages

name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://vault.centos.org/5.11/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


#contrib - packages by Centos Users

name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=http://vault.centos.org/5.11/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5  装上后发现原本有中文支持的cacti图片全部不显示中文了,百度上找了一圈。全是说要么重新编译rrdtool,要么修改src/cacti/lib/function.php加入setlocale(LC_CTYPE,"zh_CN.UTF-8");之类的全部试遍了还是乱码,最后google到一篇文章,参考其思路解决问题。https://www.iyunv.com/thread-366540-1-1.html
  检查cacti配置页面setting中path的RRDTool Default Font已选择字体文件;
  检查httpd/conf/httpd.conf中发现已有AddDefaultCharset GB2312,且cacti的grph栏中可以正常显示中文,编码格式确定;
  检查/etc/sysconfig/httpd文件中发现HTTPD_LANG行为注销状态,取消此行前面的#号,修改为HTTPD_LANG=zh_CN.gb2312。
  保存,重启httpd,刷新cacti页面,大功告成,流量图中已成功显示中文。
p.s:
spine编译安装碰到的问题:
    ./configure --prefix=/usr/local/spine报错configure: error: C compiler cannot create executables
    解决方法:sh bootstrap //所要支持的依赖包net-snmp-devel mysql-devel openssl-devel dos2unix autoconf automake binutils libtool gcc cpp glibc-headers kernel-headers glibc-devel
    make && make install报错false // No help2man // --output=spine.1 --name='Data Collector for Cacti' --no-info --version-option='--version' ./spine
    解决方法:安装help2man


后续:
    将cacti0.8.7b升级至1.1.24过程中遇到的问题

    过程:

    保存原cacti路径下的rra文件夹所有文件,拷贝至新cacti的rra下;

    使用mysqldump保存数据库,还原至新数据库中;
      遇到的问题为流量图及流量图页面左边的树均为乱码,最后查询数据库发现这些数据均从数据库中读取,在还原时已经是乱码了。原来是旧数据库中使用的编码为latin1,新数据库使用编码为utf8,解决过程如下:
            旧数据库使用mysqldump时加上--create-options=false参数:
                备份时:mysqldump--default-character-set=latin1 --create-options=false --set-charset=false -uroot -p 数据库名称 > 数据库名称.sql
                还原时:mysql -ucacti -p --default-character-set=gbk 数据库名称 < 数据库名称.sql
    流量图不显示问题解决:用脚本将旧的rrd文件转换成xml格式,再使用脚本将xml格式还原为rrd文件放置在新cacti的rrd路径下,脚本使用rrdtool命令,详情见附件。

  



附件:http://down.运维网.com/data/2367004

页: [1]
查看完整版本: 记录一次cacti中文乱码解决经过