狂欢‰一夜 发表于 2019-1-10 07:43:46

企业级监控工具cacti安装配置全过程

  基础信息:
  OS:RHEL 5.8
  SOFT: apr-util-1.4.1.tar.bz2cmake-2.8.6.tar.gzlibmcrypt-2.5.8.tar.gzphp-5.4.36.tar.bz2
  rrdtool-1.4.7.tar.tar    apr-1.4.6.tar.bz2   cacti-0.8.8c.tar.gz       httpd-2.4.2.tar.bz2
  mysql-5.5.22.tar.gz    php-5.4.5.tar.bz2
首先编译安装LAMP平台,建议卸载掉对应rpm包,否则在各程序协作的时候可能会有问题。

[*]  install apr and apr-util:
[*]  tar xf apr-1.4.6.tar.bz2
  cd apr-1.4.6
  ./buildconf
  ./configure --prefix=/usr/local/apr
  make
  make install
  tar xf apr-util-1.4.1.tar.bz2
  cd apr-util-1.4.1
  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  make
  make install
[*]  install apache:
  yum -y install pcre-devel
  tar xf httpd-2.4.2.tar.bz2
  cd httpd-2.4.2
  ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-suexec --enable-ssl --enable-rewrite --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-modules-shared=most --enable-mpms-shared=all
  make
  make install
  echo "PATH=\$PATH:/usr/local/apache/bin" >> /etc/profile
  export PATH=$PATH:/usr/local/apache/bin
  echo "MANPATH/usr/local/apache/man " >> /etc/man.config
  ln -sv /usr/local/apache/include /usr/include/httpd
[*]  install cmake:
  tar xf cmake-2.8.8.tar.gz
  cd cmake-2.8.8
  ./bootstrap
  make
  make install
[*]  install mysql
  groupadd -r mysql
  useradd -g mysql -r -d /data/mysql mysql
  tar xf mysql-5.5.22a.tar.gz
  cd mysql-5.5.22a
  cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1-DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_PROFILING=1
  make
  make install
[*]  cd /usr/local/mysql
  chown -R :mysql .
  mkdir -pv /data/mysql
  chown -R mysql:mysql /data/
  cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
  cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
  chmod +x /etc/rc.d/init.d/mysqld
  chkconfig --add mysqld
  scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  sed -i '/\/a \datadir = /data/mysql' /etc/my.cnf
  sed -i '/\/a \basedir = /usr/local/mysql' /etc/my.cnf
  sed -i 's/thread_concurrency = 8/thread_concurrency = 2/g' /etc/my.cnf
  echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
  export PATH=$PATH:/usr/local/mysql/bin
  echo "MATHPATH /usr/local/mysql/man" >> /etc/man.config
  ln -sv /usr/local/mysql/include /usr/include/mysql
  echo " /usr/local/mysql/lib " >> /etc/ld.so.conf.d/mysql.conf
  ldconfig
  servicemysqld start
  6.install php
  安装php之前有可能会要求安装libmcrypt,我直接在chinaunix下载的源码 编译安装即可,然后编译PHP时加上 --with-mcrypt=DIR
  tar xfphp-5.4.4.tar.bz2
  cdphp-5.4.4
  ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml--with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-sockets
  make
  make install
  cp php-5.4.4/php.ini-production /etc/php.ini
  echo "AddType application/x-httpd-php.php " >> /etc/httpd/httpd.conf
  echo "AddType application/x-httpd-php-source.phps" >> /etc/httpd/httpd.conf
  sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' /etc/httpd/httpd.conf
  上面所有操作无错误执行完以后可以建个测试php页测试下是不是OK,如果没问题,开始装cacti部分:
  1.我为cacti直接建立的虚拟主机:
  首先修改httpd.conf添加:include /etc/httpd/extra/httpd-vhosts.conf
  然后修改http-vhosts.conf:
  
    DocumentRoot "/usr/local/apache/htdocs/cacti
    ServerName cacti.jerry.com
    ErrorLog "logs/cacti-error_log"
    CustomLog "logs/cacti-access_log" common

  2.安装rrdtool:
  tar xf rrdtool-1.4.7.tar.gz
  cd rrdtool-1.4.7
  ./configure --prefix=/usr/local/rrdtool
  make
  make install
  echo "MANPATH/usr/local/rrdtool/share/man" >> /etc/man.config
  echo "PATH=$PATH:/usr/local/rrdtool/bin " >> /etc/profile
  export PATH=$PATH:/usr/local/rrdtool/bin
  ln -sv /usr/local/rrdtool/include /usr/include/rrdtool
  echo "/usr/local/rrdtool/lib" >> /etc/ld.so.conf.d/rrdtool.conf
  ldconfig
  3.yum安装net-snmp、net-snmp-util并设置自动运行,此处不给详细命令了
  4.安装cacti
  为cacti创建数据库,并初始化所需要表:


[*]  mysqladmin create cacti      //此时的密码为mysql的密码
[*]  cd /usr/local/apache/htdocs/cacti
[*]  mysql cacti < cacti.sql
  
创建mysql用户,使用cacti能访问其cacti数据库

  mysql -e "GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'";

[*]  //创建了用户cactiuser 密码也为cactiuser
[*]  mysqladmin -p flush-privileges
[*]  mysql -ucactiuser -p          //验证一下是否正确
  接着创建系统用户cactiuser,以之运行cacti的数据获取和日志记录等工作


[*]  useradd cactiuser
[*]  chown -R cactiuser:cactiuser /usr/local/apache/htdocs/cacti/{log,rra}
  以cactiuser用户的身份,每5钟获取一次数据:


[*]  echo '*/5 * * * */usr/local/php/bin/php /usr/local/apache/htdocs/cacti/poller.php &> /dev/null' > /var/spool/cron/cactiuser
  
修改php时区:



[*]  vim /etc/php.ini
[*]  date.timezone = Asia/Shanghai
  
编辑cacti的配置文件include/config.php启用并修改如下行:
//$url_path = "/cacti/";
我们这里将之修改为:
$url_path = "/";
  而后在浏览器中打开http://cacti.jerry.com,按提示一步步配置即可完成安装。
密码第一次输入的时候,会让修改密码,用户默认为admin 密码为admin
http://s3.运维网.com/wyfs02/M01/57/39/wKioL1SVa-OTd4onAAfxQF1LNec815.jpg



页: [1]
查看完整版本: 企业级监控工具cacti安装配置全过程