[root@cacti ~]# tar xf apr-1.5.1.gz [root@cacti ~]# cd apr-1.5.1 [root@cacti apr-1.5.1]# ./configure --prefix=/usr/local/apr151 [root@cacti apr-1.5.1]#echo $? [root@cacti apr-1.5.1]#make && make install
[root@cacti ~]# tar xf apr-util-1.5.2.tar.bz2 [root@cacti ~]# cd apr-util-1.5.2 [root@cacti apr-util-1.5.2]# ./configure --prefix=/usr/local/aprutil152 --with-apr=/usr/local/apr151 [root@cacti apr-util-1.5.2]# echo $? 0 [root@cacti apr-util-1.5.2]# make && make install
[root@cacti ~]# tar xf pcre-8.35.tar.bz2 [root@cacti ~]# cd pcre-8.35 [root@cacti pcre-8.35]# ./configure --prefix=/usr/local/pcre835 [root@cacti pcre-8.35]# echo $? 0 [root@cacti pcre-8.35]# make && make install
[root@cacti ~]# tar xf httpd-2.4.9.tar.gz [root@cacti ~]# cd httpd-2.4.9 [root@localhost httpd-2.4.9]# ./configure \ > --prefix=/usr/local/httpd249 \ > --sysconfdir=/etc/httpd \ > --enable-so \ > --enable-ssl \ > --enable-rewrite \ > --enable-modules=most \ > --enable-mods-shared=most \ > --enable-mpms-shared=all \ > --with-mpm=event \ > --with-zlib \ > --with-apr=/usr/local/apr151 \ > --with-apr-util=/usr/local/aprutil152 \ > --with-pcre=/usr/local/pcre835 [root@cacti httpd-2.4.9]# echo $? 0 [root@cacti httpd-2.4.9]# make && make install [root@cacti ~]# ln -sv /usr/local/httpd249/include/ /usr/include/httpd `/usr/include/httpd' -> `/usr/local/httpd249/include/' [root@cacti ~]#echo 'export PATH=/usr/loca/httpd249/bin:$PATH' > /etc/profile.d/httpd.sh
[root@cacti ~]# vim /etc/init.d/httpd #!/bin/bash # #chkconfig: 2345 85 15 # #Source functions . /etc/rc.d/init.d/functions PidFile=/var/run/httpd/httpd.pid LockFile=/var/lock/subsys/httpd prog=httpd HTTPD=/usr/local/httpd249/bin/httpd start(){ echo -n "Starting $prog:" daemon $HTTPD RETVAL=$? echo [ $RETVAL -eq 0 ] && touch ${PidFile} ${LockFile} return $RETVAL } stop(){ echo -n "Stopping $prog:" killproc $HTTPD RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f ${PidFile} ${LockFile} return $RETVAL } reload(){ echo -n "Reloading $prog:" killproc $HTTPD -HUP RETVAL=$? echo } restart(){ stop start } case $1 in start) start;; stop) stop;; reload) reload;; restart) restart;; *) echo "Usage:start|stop|restart|reload" esac [root@cacti ~]# bash -n /etc/init.d/httpd [root@cacti ~]# chmod +x /etc/init.d/httpd [root@cacti ~]# service httpd start Starting httpd: [ OK ] [root@cacti ~]# netstat -tnl | grep 80 tcp 0 0 :::80 :::* LISTEN [root@cacti ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@cacti ~]# service httpd reload Reloading httpd: [ OK ] [root@cacti ~]# service httpd stop Stopping httpd: [ OK ] [root@cacti ~]# netstat -tnl | grep 80
测试:
[root@cacti ~]# curl -I http://192.168.10.39 HTTP/1.1 200 OK
[root@cacti ~]# tar xf mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [root@cacti ~]# cd /usr/local/ [root@cacti local]# ln -sv mysql-5.6.13-linux-glibc2.5-x86_64/ mysql `mysql' -> `mysql-5.6.13-linux-glibc2.5-x86_64/' [root@cacti local]#cd mysql [root@cacti mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@cacti mysql]# cat /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@cacti mysql]# . /etc/profile.d/mysql.sh [root@cacti mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql `/usr/include/mysql' -> `/usr/local/mysql/include' [root@cacti mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf [root@cacti mysql]# cat /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@cacti mysql]# ldconfig -v | grep mysql /usr/local/mysql/lib: libmysqlclient.so.18 -> libmysqlclient_r.so.18.1.0 /usr/lib64/mysql: libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0 libmysqlclient.so.16 -> libmysqlclient.so.16.0.0 [root@cacti mysql]# vim /etc/man.config MANPATH /usr/local/mysql/man [root@cacti mysql]# useradd -r mysql [root@cacti mysql]# id mysql uid=498(mysql) gid=498(mysql) groups=498(mysql) [root@cacti mysql]# chown -R root.mysql * [root@cacti mysql]# mv /etc/my.cnf /etc/my.cnf.bak [root@cacti mysql]# cp support-files/my-default.cnf /etc/my.cnf [root@cacti mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@cacti mysql]# vim /etc/init.d/mysqld 将有关datadir的值改为/mydata/data [root@cacti mysql]# mkdir -pv /mydata/data mkdir: created directory `/mydata' mkdir: created directory `/mydata/data' [root@cacti mysql]# chown -R mysql.mysql /mydata/data/ [root@cacti mysql]# ll -d /mydata/data/ drwxr-xr-x. 2 mysql mysql 4096 Jul 1 21:12 /mydata/data/ [root@cacti mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ [root@cacti mysql]# service mysqld start Starting MySQL......... [ OK ] [root@cacti mysql]# netstat -tnl | grep 3306 tcp 0 0 :::3306 :::* LISTEN [root@cacti mysql]# mysqladmin -uroot -hlocalhost password 'rootroot' -p
[root@cacti mysql]# cat << EOF >> /etc/yum.repos.d/aliyun.repo [epel] name=epel -- aliyun baseurl=http://mirrors.aliyun.com/epel/\$releasever/\$basearch gpgcheck=1 gpgkey=http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-6 EOF [root@cacti mysql]# cat /etc/yum.repos.d/aliyun.repo [epel] name=epel -- aliyun baseurl=http://mirrors.aliyun.com/epel/$releasever/$basrarch gpgcheck=1 gpgkey=http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-6 [root@cacti ~]#yum -y install libmcrypt-devel libxml2-devel mhash-devel bzip2-devel php-mbstring [root@cacti ~]# ntpdate 192.168.4.2 12 Jan 10:54:35 ntpdate[7550]: adjust time server 192.168.4.2 offset -0.010928 sec [root@cacti ~]# tar xf php-5.4.31.tar.bz2 [root@cacti ~]# cd php-5.4.31 [root@cacti php-5.4.31]# ./configure \ > --prefix=/usr/local/php \ > --with-mysql=/usr/local/mysql \ > --with-mysqli=/usr/local/mysql/bin/mysql_config \ > --with-apxs2=/usr/local/httpd249/bin/apxs \ > --enable-maintainer-zts \ > --with-openssl \ > --enable-mbstring \ > --with-jpeg-dir \ > --with-freetype-dir \ > --with-png-dir \ > --with-zlib \ > --with-libxml-dir \ > --enable-xml \ > --with-mcrypt \ > --with-config-file-path=/etc \ > --with-config-file-scan-dir=/etc/php.d \ > --with-bz2 > --enable-sockets
[root@cacti php-5.4.31]# echo $? 0 [root@cacti php-5.4.31]# make && make install
[root@cacti cacti]# cd /usr/local/php/ [root@cacti php]# ls bin etc include lib php [root@cacti php]# echo 'export PATH=/usr/local/php/bin:$PATH' > /etc/profile.d/php.sh [root@cacti php]# cat /etc/profile.d/php.sh export PATH=/usr/local/php/bin:$PATH [root@cacti php]# . /etc/profile.d/php.sh [root@cacti php]# ln -sv /usr/local/php/include /usr/include/php `/usr/include/php' -> `/usr/local/php/include' [root@cacti php]# echo '/usr/local/php/lib' > /etc/ld.so.conf.d/php.conf [root@cacti php]# ldconfig -v | grep php /usr/local/php/lib:[root@cacti php-5.4.31]# mv /etc/php.ini /etc/php.ini.bak [root@cacti php-5.4.31]# cp php.ini-production /etc/php.ini [root@cacti php-5.4.31]# vim /etc/php.ini date.timezone = Asia/Shanghai [root@cacti php-5.4.31]# vim /etc/httpd/httpd.conf DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps [root@cacti php-5.4.31]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@cacti php-5.4.31]# vim /usr/local/httpd249/htdocs/index.php <?php phpinfo(); ?>
[root@cacti htdocs]# vim /etc/httpd/httpd.conf #注释主配置的DocumentRoot #DocumentRoot "/usr/local/httpd249/htdocs" #启用虚拟主机配置文件 Include /etc/httpd/extra/httpd-vhosts.conf [root@cacti htdocs]# vim /etc/httpd/extra/httpd-vhosts.conf <VirtualHost 192.168.10.39:80> DocumentRoot "/web/htdocs/cacti" ServerName cacti.wsh.com <Directory "/web/htdocs/cacti"> Options None AllowOverride None Require all granted </Directory> ErrorLog "logs/cacti_error.log" CustomLog "logs/cacti_access.log" common </VirtualHost> </VirtualHost> [root@cacti ~]# tar xf cacti-0.8.8c.tar.gz -C /web/htdocs/ [root@cacti htdocs]# ln -sv cacti-0.8.8c cacti [root@cacti htdocs]# ll total 4 lrwxrwxrwx. 1 root root 12 Jan 12 11:49 cacti -> cacti-0.8.8c drwxr-xr-x. 13 1000 users 4096 Nov 24 04:18 cacti-0.8.8c
[root@cacti cacti]# mysqladmin -uroot -hlocalhost create cactidb -p Enter password: [root@cacti cacti]# mysql -uroot -hlocalhost -p cactidb < cacti.sql Enter password: [root@cacti cacti]# vim include/config.php $database_type = "mysql"; $database_default = "cactidb"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactiuser"; $database_port = "3306"; $database_ssl = false; /* 才能使用http://cacti.wsh.com直接访问 Edit this to point to the default URL of your Cacti install ex: if your cacti install as at http://serverip/cacti/ this would be set to /cacti/ */ $url_path = "/"; [root@cacti cacti]# mysql -uroot -hlocalhost -p -e "GRANT ALL ON cactidb.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser'" Enter password:
说明:我们所使用的有关SNMP的软件有两个—>net-snmp , net-snmp-utils;
          net-snmp:这是Agent端需要安装的
          net-snmp-utils:这是NMS需要安装的;如果使用trap,NMS端还需要安装net-snmp
在此,我们的client既是Agent又是NMS所以这两个都安装了
[root@cacti cacti]# yum -y install net-snmp net-snmp-utils [root@cacti cacti]#service snmpd start
[root@cacti cacti]# yum -y install rrdtool rrdtool-perl
以普通用户cactiuser运行该脚本:
[root@cacti cacti]# useradd cactiuser [root@cacti cacti]# echo "*/5 * * * * /usr/local/php/bin/php /web/htdocs/cacti/poller.php" > /var/spool/cron/cactiuser
获取数据需要记录日志和保存数据,修改log和rra的属主属组为cactiuser:
[root@cacti cacti]# chown -R cactiuser.cactiuser log rra [root@cacti cacti]# ll -d log rra drwxr-xr-x. 2 cactiuser cactiuser 4096 Nov 12 09:34 log drwxr-xr-x. 2 cactiuser cactiuser 4096 Nov 12 09:34 rra
通过浏览器访问 http://cacti.wsh.com :
[root@cacti cacti]# rpm -q net-snmp net-snmp-5.5-50.el6_6.1.x86_64 [root@cacti cacti]# rpm -q rrdtool rrdtool-1.3.8-7.el6.x86_64
Finish之后会提示输入用户名:admin、密码:admin,提示输入用户admin的新密码;