CentOS6.4下编译安装Bandwidthd和Postgrsql

分类:CentOS教程 阅读:7617 次

一、在CentOS6.4环境下编译Bandwidthd和Postgrsql需要注意顺序

(1)下载Postgrsql

wget http://ftp.postgresql.org/pub/source/v8.4.2/postgresql-8.4.2.tar.gz


最好下载在 / 根目录下

tar -zxvf postgresql-8.4.2.tar.gz 解压缩


(2)下载Bandwidthd

wget http://nchc.dl.sourceforge.net/project/bandwidthd/bandwidthd/bandwidthd%202.0.1/bandwidthd-2.0.1.tgz

tar -zxvf bandwidthd-2.0.1.tgz

(3)安装编译需要的软件包

编译Postgresql需要

yum install gcc cpp glibc glibc-devel gcc-c++ make

编译Bandwidthd需要

yum install libpcap libpcap-devel libpng libpng-devel gd gd-devel

(4)进入postgres目录,开始编译postgres

./configure

执行后,看看有没有错误

[root@bwd postgresql-8.4.2]# ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking which template to use... linux checking whether to build with 64-bit integer date/time support... yes checking whether NLS is wanted... no checking fordefault port number... 5432 checking for block size... 8kB checking for segment size... 1GB checking for WAL block size... 8kB checking for WAL segment size... 16MB checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking if gcc supports -Wdeclaration-after-statement... yes checking if gcc supports -Wendif-labels... yes checking if gcc supports -fno-strict-aliasing... yes checking if gcc supports -fwrapv... yes checking whether the C compiler still works... yes checking how to run the C preprocessor... gcc -E checking allow thread-safe client libraries... no checking whether to build with Tcl... no checking whether to build Perl modules... no checking whether to build Python modules... no checking whether to build with GSSAPI support... no checking whether to build with Kerberos 5 support... no checking whether to build with PAM support... no checking whether to build with LDAP support... no checking whether to build with Bonjour support... no checking whether to build with OpenSSL support... no checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ld used by GCC... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for ranlib... ranlib checking for strip... strip checking whether it is possible to strip libraries... yes checking for ar... ar checking for tar... /bin/tar checking whether ln -s works... yes checking for gawk... gawk checking for bison... no configure: WARNING: *** Without Bison you will not be able to build PostgreSQL from CVS nor *** change any of the parser definition files. You can obtain Bison from *** a GNU mirror site. (If you are using the official distribution of *** PostgreSQL then you do not need to worry about this, because the Bison *** output is pre-generated.) checking for flex... no configure: WARNING: *** Without Flex you will not be able to build PostgreSQL from CVS or *** change any of the scanner definition files. You can obtain Flex from *** a GNU mirror site. (If you are using the official distribution of *** PostgreSQL then you do not need to worry about this because the Flex *** output is pre-generated.) checking for perl... /usr/bin/perl checking for main in -lm... yes checking for library containing setproctitle... no checking for library containing dlopen... -ldl checking for library containing socket... none required checking for library containing shl_load... no checking for library containing getopt_long... none required checking for library containing crypt... -lcrypt checking for library containing fdatasync... none required checking for library containing gethostbyname_r... none required checking for library containing shmget... none required checking for -lreadline... yes (-lreadline) checking for inflate in -lz... yes checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking crypt.h usability... yes checking crypt.h presence... yes checking for crypt.h... yes checking dld.h usability... no checking dld.h presence... no checking for dld.h... no checking fp_class.h usability... no checking fp_class.h presence... no checking for fp_class.h... no checking getopt.h usability... yes checking getopt.h presence... yes checking for getopt.h... yes checking ieeefp.h usability... no checking ieeefp.h presence... no checking for ieeefp.h... no checking langinfo.h usability... yes checking langinfo.h presence... yes checking for langinfo.h... yes checking poll.h usability... yes checking poll.h presence... yes checking for poll.h... yes checking pwd.h usability... yes checking pwd.h presence... yes checking for pwd.h... yes checking sys/ipc.h usability... yes checking sys/ipc.h presence... yes checking for sys/ipc.h... yes checking sys/poll.h usability... yes checking sys/poll.h presence... yes checking for sys/poll.h... yes checking sys/pstat.h usability... no checking sys/pstat.h presence... no checking for sys/pstat.h... no checking sys/resource.h usability... yes checking sys/resource.h presence... yes checking for sys/resource.h... yes checking sys/select.h usability... yes checking sys/select.h presence... yes checking for sys/select.h... yes checking sys/sem.h usability... yes checking sys/sem.h presence... yes checking for sys/sem.h... yes checking sys/socket.h usability... yes checking sys/socket.h presence... yes checking for sys/socket.h... yes checking sys/shm.h usability... yes checking sys/shm.h presence... yes checking for sys/shm.h... yes checking sys/tas.h usability... no checking sys/tas.h presence... no checking for sys/tas.h... no checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking sys/un.h usability... yes checking sys/un.h presence... yes checking for sys/un.h... yes checking termios.h usability... yes checking termios.h presence... yes checking for termios.h... yes checking ucred.h usability... no checking ucred.h presence... no checking for ucred.h... no checking utime.h usability... yes checking utime.h presence... yes checking for utime.h... yes checking wchar.h usability... yes checking wchar.h presence... yes checking for wchar.h... yes checking wctype.h usability... yes checking wctype.h presence... yes checking for wctype.h... yes checking kernel/OS.h usability... no checking kernel/OS.h presence... no checking for kernel/OS.h... no checking kernel/image.h usability... no checking kernel/image.h presence... no checking for kernel/image.h... no checking SupportDefs.h usability... no checking SupportDefs.h presence... no checking for SupportDefs.h... no checking netinet/in.h usability... yes checking netinet/in.h presence... yes checking for netinet/in.h... yes checking for netinet/tcp.h... yes checking readline/readline.h usability... yes checking readline/readline.h presence... yes checking for readline/readline.h... yes checking readline/history.h usability... yes checking readline/history.h presence... yes checking for readline/history.h... yes checking zlib.h usability... yes checking zlib.h presence... yes checking for zlib.h... yes checking whether byte ordering is bigendian... no checking for an ANSI C-conforming const... yes checking forinline... inline checking for preprocessor stringizing operator... yes checking forsigned types... yes checking for working volatile... yes checking for __func__... yes checking whether structtm is in sys/time.h or time.h... time.h checking forstructtm.tm_zone... yes checking for tzname... yes checking forunion semun... no checking forstruct sockaddr_un... yes checking forstruct sockaddr_storage... yes checking forstruct sockaddr_storage.ss_family... yes checking forstruct sockaddr_storage.__ss_family... no checking forstruct sockaddr_storage.ss_len... no checking forstruct sockaddr_storage.__ss_len... no checking forstruct sockaddr.sa_len... no checking forstruct addrinfo... yes checking forstruct cmsgcred... no checking forstruct fcred... no checking forstruct sockcred... no checking forstruct option... yes checking for z_streamp... yes checking forint timezone... yes checking types of arguments for accept()... int, int, struct sockaddr *, socklen_t * checking whether gettimeofday takes only one argument... no checking for cbrt... yes checking for dlopen... yes checking for fcvt... yes checking for fdatasync... yes checking for getpeereid... no checking for getpeerucred... no checking for getrlimit... yes checking for memmove... yes checking for poll... yes checking for pstat... no checking for readlink... yes checking for setproctitle... no checking for setsid... yes checking for sigprocmask... yes checking for symlink... yes checking for sysconf... yes checking for towlower... yes checking for utime... yes checking for utimes... yes checking for waitpid... yes checking for wcstombs... yes checking for posix_fadvise... yes checking whether posix_fadvise is declared... yes checking whether fdatasync is declared... yes checking whether strlcat is declared... no checking whether strlcpy is declared... no checking whether F_FULLFSYNC is declared... no checking forstruct sockaddr_in6... yes checking for PS_STRINGS... no checking for snprintf... yes checking for vsnprintf... yes checking whether snprintf is declared... yes checking whether vsnprintf is declared... yes checking for isinf... yes checking for crypt... yes checking for getopt... yes checking for getrusage... yes checking for inet_aton... yes checking for random... yes checking for rint... yes checking for srandom... yes checking for strdup... yes checking for strerror... yes checking for strlcat... no checking for strlcpy... no checking for strtol... yes checking for strtoul... yes checking for unsetenv... yes checking for getaddrinfo... yes checking for getopt_long... yes checking for rl_completion_append_character... yes checking for rl_completion_matches... yes checking for rl_filename_completion_function... yes checking for replace_history_entry... yes checking for sigsetjmp... yes checking whether sys_siglist is declared... yes checking for syslog... yes checking syslog.h usability... yes checking syslog.h presence... yes checking for syslog.h... yes checking for opterr... yes checking for optreset... no checking for strtoll... yes checking for strtoull... yes checking for atexit... yes checking for fseeko... yes checking for _LARGEFILE_SOURCE value needed for large files... no checking test program... ok checking whether longint is 64 bits... yes checking for unsigned long... yes checking size of unsigned long... 8 checking forvoid *... yes checking size of void *... 8 checking forsize_t... yes checking size of size_t... 8 checking whether to build with float4 passed by value... yes checking whether to build with float8 passed by value... yes checking forshort... yes checking alignment of short... 2 checking forint... yes checking alignment of int... 4 checking forlong... yes checking alignment of long... 8 checking fordouble... yes checking alignment of double... 8 checking for int8... no checking for uint8... no checking for int64... no checking for uint64... no checking forsig_atomic_t... yes checking for POSIX signal interface... yes checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking for off_t... yes checking size of off_t... 8 checking for working memcmp... yes checking for onsgmls... no checking for nsgmls... no checking for openjade... no checking for jade... no checking for DocBook V4.2... no checking for DocBook stylesheets... no checking for collateindex.pl... no checking for sgmlspl... no checking for docbook2man... checking if gcc supports -Wl,--as-needed... yes configure: using CFLAGS=-O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv configure: using CPPFLAGS= -D_GNU_SOURCE configure: using LDFLAGS= -Wl,--as-needed configure: creating ./config.status config.status: creating GNUmakefile config.status: creating src/Makefile.global config.status: creating src/include/pg_config.h config.status: src/include/pg_config.h is unchanged config.status: creating src/interfaces/ecpg/include/ecpg_config.h config.status: src/interfaces/ecpg/include/ecpg_config.h is unchanged config.status: linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s config.status: linking ./src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c config.status: linking ./src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c config.status: linking ./src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c config.status: linking ./src/backend/port/dynloader/linux.h to src/include/dynloader.h config.status: linking ./src/include/port/linux.h to src/include/pg_config_os.h config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port [root@bwd postgresql-8.4.2]#

然后执行gmake

rm -rf ./testtablespace mkdir ./testtablespace gmake[2]: Leaving directory `/postgresql-8.4.2/src/test/regress' gmake[1]: Leaving directory `/postgresql-8.4.2/src' gmake -C config all gmake[1]: Entering directory `/postgresql-8.4.2/config' gmake[1]: Nothing to be done for `all'. gmake[1]: Leaving directory `/postgresql-8.4.2/config' All of PostgreSQL successfully made. Ready to install.

看到ready to instal 基本就成功了


等编译完成后,没有错误,再执行 gmake install

详细说明,可以看


(5)编译Bandwidthd

在编译Bandwithd前,请检查 /usr/local/pgsql/ 下是否已经有 bandwidthd需要的库和头文件了。

进入bandwidthd目录

./configure

执行configure后,看看是否有错误。注意,如果Postgresq编译有问题化,Bandwidthd编译出来的程序是不会支持Postgresql的。

make

可以通过程序文件大小判断

如果不带Postgresq支持的是11xxxx 的大小。


这2个地方必须是yes,才能编译出支持Postgrsql的程序.

make install后,程序的配置文件在 /usr/local/bandwidthd/etc 目录

#################################################### # Bandwidthd.conf # # Commented out options are here to provide # documentation and represent defaults # Subnets to collect statistics on. Traffic that # matches none of these subnets will be ignored. # Syntax is either IP Subnet Mask or CIDR #subnet 10.0.0.0 255.0.0.0 #subnet 192.168.0.0/16 #subnet 172.16.0.0/12 subnet 10.0.0.0 255.255.0.0 subnet 10.1.0.0 255.255.0.0 subnet 10.2.0.0 255.255.0.0 subnet 10.3.0.0 255.255.0.0 subnet 10.4.0.0 255.255.0.0 subnet 10.5.0.0 255.255.0.0 subnet 192.168.0.0/16 subnet 172.16.25.0/24 subnet 172.16.10.0/24 subnet 172.16.11.0/24 subnet 172.16.12.0/24 subnet 172.16.13.0/24 subnet 172.16.14.0/24 subnet 172.16.15.0/24 subnet 172.16.16.0/24 subnet 172.16.17.0/24 subnet 172.16.18.0/24 subnet 172.16.19.0/24 subnet 172.16.20.0/24 subnet 172.16.31.0/24 subnet 172.16.32.0/24 subnet 172.16.33.0/24 subnet 172.16.34.0/24 subnet 172.16.35.0/24 subnet 172.16.36.0/24 pgsql_connect_string "user = postgres dbname = bandwidthd host = 127.0.0.1" sensor_id "sensor1.cn" # Device to listen on # Bandwidthd listens on the first device it detects # by default. Run "bandwidthd -l" for a list of # devices. dev "eth1" ################################################### # Options that don't usually get changed # An interval is 2.5 minutes, this is how many # intervals to skip before doing a graphing run #skip_intervals 150 # Graph cutoff is how many k must be transfered by an # ip before we bother to graph it graph_cutoff 1024 #Put interface in promiscuous mode to score to traffic #that may not be routing through the host machine. promiscuous true #Log data to cdf file htdocs/log.cdf output_cdf true #Read back the cdf file on startup recover_cdf false #Libpcap format filter string used to control what bandwidthd see's #Please always include "ip" in the string to avoid strange problems filter "ip" #Draw Graphs - This default to true to graph the traffic bandwidthd is recording #Usually set this to false if you only want cdf output or #you are using the database output option. Bandwidthd will use very little #ram and cpu if this is set to false. graph false #Set META REFRESH seconds (default 150, use 0 to disable). meta_refresh 150

二、如果要能成功运行Bandwidthd,还需要创建数据库

在Bandwidthd目录下,有个schema.postgresql脚本,要首先将他导入数据库

su - postgres psql create database bandwidthd; [postgres@bwd bandwidthd-2.0.1]$ psql bandwidthd postgres< schema.postgresql CREATE TABLE CREATE INDEX CREATE INDEX CREATE TABLE CREATE INDEX CREATE INDEX CREATE TABLE CREATE INDEX CREATE TABLE CREATE INDEX NOTICE: CREATE TABLE will create implicit sequence "sensors_sensor_id_seq"for serial column "sensors.sensor_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "sensors_pkey"for table "sensors" CREATE TABLE [postgres@bwd bandwidthd-2.0.1]$

重启bandwidthd 后postgresql数据库,2分钟后,数据库里就有数据了。