编译安装支持中文的rrdtool

本文可自由转载,但请遵循“署名-非商业用途-保持一致”的创作共用协议。 永久链接:JoeCen's 小猫窝
-----------------------------

update:

1.2之后,rrdtool直接可以支持中文

We now use Pango for all text rendering. Pango integrates with Cairo, Freetype and Fontconfig. This has a number of implications:

    * Fonts are accessed through the fontconfig interface. This means you get access to all fonts on your system, and at the same time loose the ability to use true type fonts directly.

    * All text is passed through Pango Markup. This means it is now possible to switch font properties inside any rrdtool graph text field.

如果是debian系统的话,直接运行以下命令即可:

aptitude install xfonts-wqy

其他发行版的话,只要在系统里面安装中文字体即可。

分割线以下内容已经失效,可以忽略。

----------------------------------分割线------------------------------
编译安装rrdtool其实是一件比较麻烦的事情,因为rrdtool需要zlib、libpng、freetype等多个lib的支持。在rrdtool出了1.2的版本出来以前,这些库是被放在rrdtool的安装包里面,与rrdtool一起编译的,而1.2的版本以后,则是需要自己手工下载并且一个个编译,并且指定库的位置,所以说比较麻烦。

不过,rrdtool的作者还是挺贴心的,他不但在自己的网站上提供了详细的安装文档,还提供了所需库的安装包下载,并且在"./configure"的时候让你清楚自己少了那些包,在哪里可以找到。

我在这里根据自己的安装经验,把我的安装文档也分享一下。
-------------------------------------------------------

以下有部分内容摘抄自rrdtool-1.2.26安装包中的doc/rrdbuild.pod文件。

一、设置系统变量:

BUILD_DIR=/home/joe/rrdtool/lib/lb
INSTALL_DIR=/usr/local/rrdtool-1.2.26

二、安装rrdtool需要的库:

1、debian 的话,zlib自带了,可以找得到,不需要自己安装。

2、安装libpng:

cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.10.tar.gz
tar zxvf libpng-1.2.10.tar.gz
cd libpng-1.2.10
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
    ./configure --disable-shared --prefix=$BUILD_DIR/lb
make && make install

3、安装freetype-2

cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.1.10.tar.bz2
tar jxvf freetype-2.1.10.tar.bz2
cd freetype-2.1.10
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
    ./configure --disable-shared --prefix=$BUILD_DIR/lb
make && make install

4、安装libart_lgpl

cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/libart_lgpl-2.3.17.tar.gz
tar zxvf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
env CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install

三、安装rrdtool

先让你的系统支持zh_CN.UTF-8:
编辑/etc/locale.gen文件(新版本debian改到/var/lib/locales/supported.d/中,详情请man locale-gen),加入"zh_CN UTF-8";
然后运行/usr/sbin/locale-gen,这样就将"zh_CN.utf8"加入了系统支持里。
运行"locale -a"可以看到你的debian当前支持的语言:

C
en_US
en_US.iso88591
en_US.utf8
POSIX
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

编辑"rrdtool-1.2.26/src/rrd_graph.c"文件

查找"LC_TIME"字段,将

setlocale(LC_TIME,"");
setlocale(LC_CTYPE,"");

注释掉。

在后面加入

setlocale(LC_ALL,"zh_CN.utf8");

即可。
有人说只改系统环境变量就可以,但是我试过没有成功。

环境变量:

IR=-I$BUILD_DIR/lb/include
CPPFLAGS="$IR $IR/libart-2.0 $IR/freetype2 $IR/libpng"
LDFLAGS="-L$BUILD_DIR/lb/lib"
CFLAGS=-O3
export CPPFLAGS LDFLAGS CFLAGS

编译:

cd $BUILD_DIR/rrdtool-1.2.26
./configure --prefix=$INSTALL_DIR --disable-python --disable-tcl
make clean
make
make install

完成

随机日志

  • 西安印象
  • Unable to use key file "id_rsa" (OpenSSH SSH-2 private key)
  • 使用php-syslog-ng远程查看与管理系统日志
  • 编译安装支持中文的rrdtool
  • RedHat和FreeBSD下的net-snmp配置方法
  • One Response to “编译安装支持中文的rrdtool”

    1. Nick Says:

      完全看吾明.......

    Leave a Reply