环境CentOS7.2,php-7.3.2,cacti-1.2.17,httpd-2.4.46
一、安装配置
1、安装httpd
1.0查看系统httpd包
[root@localhost opt]# rpm -qa|grep httpd
1.1 #卸载httpd
[root@localhost opt]# rpm -e httpd-2.2.3-22.1AXS3 --nodeps
[root@localhost opt]# rpm -e httpd-manual-2.2.3-22.1AXS3 --nodeps
[root@localhost opt]# rpm -e httpd-2.2.15-5.0.2.AXS4.x86_64 --nodeps
[root@localhost opt]# rpm -e httpd-manual-2.2.15-5.0.2.AXS4.noarch --nodeps
[root@localhost opt]# rpm -e httpd-tools-2.2.15-5.0.2.AXS4.x86_64 --nodeps
[root@localhost opt]# rpm -e httpd-devel-2.2.15-5.0.2.AXS4.x86_64 --nodeps
安装apache
1.2 准备安装包和辅助包(自己去下载,一定注意版本和位数)
1.3/tmp/software 建立software文件夹,用xftp上传安装包
1.4安装apr-1.7.0.tar.gz安装目录是/usr/local/apr
进入安装包目录解压
[root@localhost]# tar -zxvf apr-1.7.0.tar.gz
[root@localhost]# cd apr-1.7.0
[root@localhost]# ./configure --prefix=/usr/local/apr
[root@localhost]# make
[root@localhost]# make install
#解决报错
[root@localhost]# vim configure
搜索cfgfile 添加#注释 cfgfile
R M " RM " RM"cfgfile"
1.5安装apr-util-1.5.4.tar.bz2安装目录是/usr/local/apr-util
进入目录
[root@localhost]# yum -y install expat-devel
[root@localhost]# tar -zxvf apr-util-1.6.1.tar.gz
[root@localhost]# cd apr-util-1.6.1
[root@localhost]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost]# make
[root@localhost]# make install
1.6安装pcre-8.36.tar.gz
[root@localhost]# yum install -y gcc-c++
[root@localhost]# tar -zxvf pcre-8.44.tar.gz
[root@localhost]# cd pcre-8.44
[root@localhost]# ./configure --prefix=/usr/local/pcre
[root@localhost]# make && make install
1.7安装apache2.4.23安装目录是/usr/local/apache
[root@localhost software]# tar -zxvf httpd-2.4.46.tar.gz
[root@localhost software]# cd httpd-2.4.46
[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-module=so --enable-mods-shared=all --enable-module=rewirte --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --disable-cgid --disable-cgi
[root@localhost httpd-2.4.23]# make
[root@localhost httpd-2.4.23]# make install
1.8修改httpd.conf
[root@localhost]# vim /usr/local/apache/conf/httpd.conf
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5
找到:
DirectoryIndex index.html
添加:
DirectoryIndex index.html index.php
找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerName localhost:80
1.9#启动
[root@localhost]# /usr/local/apache/bin/httpd -k start
2.安装PHP
[root@localhost]# yum -y install gcc openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
2.1. php下载以及安装
下载: wget http://am1.php.net/distributions/php-7.3.2.tar.gz
[root@localhost]# tar -zxvf php-7.3.2.tar.gz
[root@localhost]# cd php-7.3.2
[root@localhost]# ./configure --prefix=/data/app/php-cgi --with-config-file-path=/data/app/php-cgi/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli=/usr/bin/mysql_config --with-openssl --with-pdo-mysql --enable-fpm --with-curl
[root@localhost]# make
[root@localhost]# make install
2.2编译成功完成,结果在 make 的时候报错
libtool: link: `ext/opcache/ZendAccelerator.lo’ is not a valid libtool object
解决办法:
make distclean
重新编译 make
编译成功完成,结果在 make 的时候报错
make: *** [sapi/cli/php] Error 1
解决办法:
make ZEND_EXTRA_LIBS=’-liconv’
#启动报错Directive ‘register_globals’ is no longer available in PHP in
register_globals = Off
2.3拷贝一份配置文件
[root@localhost]#cp /data/app/php-cgi/etc/www.conf.default /data/app/php-cgi/etc/php-fpm.conf
[root@localhost]# /data/app/php-cgi/sbin/php-fpm
[root@localhost]# vim /var/www/html/index.php
<?php
phpinfo();
?>
测试 httpd可以访问php
http://21x.6x.7x.16x/index.php
3.安装mysql
01.安装前检查mysql是安装了其他包
[root@localhost]# rpm -qa | grep mysql
[root@localhost]# rpm -qa |grep -i mariadb
如果存在先卸载
[root@localhost]# rpm -e --nodeps XXX
02卸载
[root@localhost]# yum remove mariadb-libs-5.5.44-2.el7.centos.x86_64
03.安装
依次安装如下rpm包
[root@localhost]# rpm -ivh mysql-community-devel-5.7.14-1.el7.x86_64.rpm
[root@localhost]# rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
[root@localhost]# rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
[root@localhost]# rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
[root@localhost]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
[root@localhost]# systemctl start mysqld
[root@localhost]# grep 'temporary password' /var/log/mysqld.log
Z??uC>r>/7+i
- 修改root用户密码
(MySQL的密码策略比较复杂,要大小写,过于简单的密码会被拒绝,这里我用了a1sda35S345.!X)
[root@localhost]# mysql -u root -p
mysql> Enter password: (输入刚才查询到的随机密码)
mysql> SET PASSWORD FOR 'root'@'localhost'= "a1sda35S345.!X";
mysql> exit
mysql>use mysql
下一步开放外部网段访问3306端口。
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'a1sda35S345.!X' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>exit;
mysql> CREATE DATABASE cacti DEFAULT CHARACTER SET utf8;
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'a1sda35S345.!X';
mysql> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost IDENTIFIED BY 'a1sda35S345.!X';
mysql> ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> flush privileges;
mysql> quit
mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql
4、安装rrdtool
[root@localhost]# yum install rrdtool rrdtool-perl -y
4.1、安装net-snmp
[root@localhost]# rpm -ivh mysql-community-libs-compat-5.7.14-1.el7.x86_64.rpm
[root@localhost]# yum install net-snmp net-snmp-libs net-snmp-utils
4.2、配置net-snmp
复制代码
[root@localhost]# vim /etc/snmp/snmpd.conf
#41行 1将default 改为监控服务器ip;2 将public 改成复杂些的识别的字符串
com2sec notConfigUser 127.0.0.1 public
#62行 1将systemview 改为all,供所有snmp 访问权限
access notConfigGroup "" any noauth exact all none none
#85行 将#注释符号去掉
view all included .1 80
5.安装cacti
[root@localhost]# tar xzf cacti-0.8.8a.tar.gz
[root@localhost]# mv cacti-0.8.8a /var/www/html/cacti
[root@localhost]# cd /var/www/html/cacti
#导入cacti.sql数据库
[root@localhost]# mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql
6.设置目录权限
[root@localhost]# cd /var/www/html/cacti
[root@localhost]# useradd cacti
[root@localhost]# chown -R cacti rra/ log/
7、配置计划任务
[root@localhost]# crontab -e
*/5 * * * * /data/app/php-cgi/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1 //让系统每5分钟收集
[root@localhost]# systemctl restart crond.service
8问题.显示无法连接mysql
[root@localhost]# vim /var/www/html/cacti/include/config.php
#将localhost改为127.0.0.1,不然cacti界面报mysql连接失败
#$database_hostname="localhost"
$database_hostname='127.0.0.1'
[root@localhost]# chown -R cacti /var/www/html/cacti/log/
[root@localhost]# chown -R cacti /var/www/html/cacti/rra/
[root@localhost]# chmod a+w /var/www/html/cacti/log/cacti.log
9.修改php参数
[root@localhost]# cp -R /opt/php-7.3.2/php.ini-production /data/app/php-cgi/etc/php.ini
[root@localhost]# vim /data/app/php-cgi/etc/php.ini
date.timezone = PRC
max_execution_time = 60
memory_limit = 512M
PHP7-永久环境变量设置
[root@localhost]# echo -e 'export PATH=/data/app/php-cgi/bin/:/data/app/php-cgi/sbin/:$PATH' >> /etc/profile && source /etc/profile
configure: error: Cannot find ldap libraries in /usr/lib
解决办法
[root@localhost]# cp -frp /usr/lib64/libldap* /usr/lib/
[root@localhost]# ./configure --prefix=/data/app/php-cgi --with-config-file-path=/data/app/php-cgi/etc --with-apxs2=/usr/local/apache/bin/apxs --with-openssl --with-pdo-mysql --enable-fpm --with-curl --with-gd --with-gmp --with-ldap
./configure后
编辑MakeFile
找到 开头是 ‘EXTRA_LIBS’ 这一行 在结尾加上 ‘-llber’ 然后执行
make install
[root@localhost]# yum install net-snmp php-snmp net-snmp-devel -y
#设置msyql时区
[root@localhost]# /usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -p mysql
mysql优化满足cacti需求
[root@localhost]# vim /etc/my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
skip-character-set-client-handshake = true
#default-character-set=utf8
max_allowed_packet = 100M
max_heap_table_size = 2048M
tmp_table_size = 2048M
join_buffer_size = 300M
innodb_buffer_pool_size=2048M
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_buffer_pool_instances=17
解决办法:
1、安装字体库
[root@localhost]# yum -y install fontconfig ttmkfdir
#2、创建字体目录
[root@localhost]# mkdir /usr/share/fonts/chinese
#3、下载字体
[root@localhost]# curl -o /usr/share/fonts/chinese/msyhl.ttc https://down.whsir.com/downloads/msyhl.ttc
最后直接刷新cacti页面即可,无需重启服务
二、Cacti1.2.x新版教程之监控Centos主机
远程主机配置
当前远程主机IP地址为192.168.1.186
1、安装启动snmp服务
[root@localhost]# yum install net-snmp net-snmp-libs net-snmp-utils
[root@localhost]# systemctl restart snmpd
2、配置snmp
[root@localhost]# vim /etc/snmp/snmpd.conf
1)根据使用情况来决定是否更改default和public,其中default允许哪台主机来监控(默认不限制),public表示团体名,可以理解成用于通信的密钥,如果你是Cacti初学者建议不要更改!
2)找到以下字段,将systemview改成all
3)找到以下字段,去掉前面的#注释
4)找到以下字段,增加一行view all included .1
保存退出重启snmp服务
[root@localhost]# systemctl restart snmpd
至此远程Centos主机配置完成,确认selinux关闭,iptables、云防火墙开通udp161端口
Cacti服务端配置
3、验证远程主机snmp能否获取数据
[root@localhost]# snmpwalk -v 2c -c public 192.168.1.186
如果不能获取数据,请检查前面配置是否都正确,一定要确保可以获取到数据后,再进行下一步
4、添加远程主机
在cacti监控系统中,创建新设备,只需要注意下面这几个选项即可,其他保持默认
描述:这个名字自己起的,没有特殊要求
主机名:填写远程主机IP地址
设备模板:我这里选择None,即不使用模板
SNMP团体:默认是public,与远程主机snmp中public一致
创建后会看到SNMP信息内容,表示创OK
5、监控远程主机负载和流量
添加Unix - Load Average图形模板
添加SNMP - Interface Statistics数据查询
然后保存
右上角点击为设备创建图形
这里会自动识别到远程主机的网卡名称,选择你需要监控的网卡及图形类型,点击创建
6、图形展示
其实此时的图形已经在绘制了,为了方便查看,还需要把创建的图形放到树上
在管理→图形中,选择刚才创建的图形,放在树上
默认树上只有一个根,可根据使用需要自行创建
最后在图形树上,可查看到刚刚创建的图形