设为首页 收藏本站
查看: 1109|回复: 0

[经验分享] 最全最详细的Apache+php+mysql+nagios+cacti 安装配置 以及出错处理过程

[复制链接]

尚未签到

发表于 2019-1-11 13:49:45 | 显示全部楼层 |阅读模式
apache+php+mysql+nagios+cacti
我是在完全干净的Ubuntu10.04下源码编译安装的,如有些地方不妥,还请指出。由于本人运气不太好,安装配置过程中把网上出现的问题都遇见了,顾也写出FAQ解决方法。
Begin 安装前保证一些开发包如gcc,g++已经装上。

1. 安装apache2.2.19
    tar zxvf httpd-2.2.19.tar.gz
    cd httpd-2.2.19
    ./configure --prefix=/usr/local/apache --enable-so   
    #记得enable-so,不然后面会出问题
    make
    make install
   
    vim /usr/local/apache/conf/httpd.conf
    设置  ServerName 为 0.0.0.0:80
    ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd  #启动项
    /usr/local/apache/bin/apachectl start
    打开浏览器,输入http://0.0.0.0:80 会出现It's works  #查看apache是否安装正确
2. 安装mysql-5.5.14
    如果没有安装cmake,首先安装cmake才能编译。
    tar -zxvf cmake-2.8.5.tar.gz
    cd cmake-2.8.5
    ./bootstrap;make;make install
    安装完后,安装mysql
    tar zxvf mysql-5.5.14.tar.gz  
    cd mysql-5.5.14
    groupadd mysql
    useradd -r -g mysql mysql

    /usr/local/bin/cmake .    #cmake当前文件,注意有个点“.”

    安装过程中可能会报以下错误
    Curses library not found.  Please install appropriate package,

    remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
    发现少库, Ubuntu下要安装libncurses5-dev
    apt-get install libncurses5-dev
    不知道库名可以用aptitude-search 来搜索
    删除mysql文件夹,重新解压,tar zxvf mysql-5.5.14.tar.gz
    cd  mysql-5.5.14
    重新 执行 /usr/local/bin/cmake .
    make
    make install
   
    cd /usr/local/mysql/
    chown -R mysql:mysql *
    scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
    chown -R root .
    chown -R mysql data
    cp support-files/my-medium.cnf /etc/my.cnf
    cp support-files/mysql.server  /etc/init.d/mysql
    /usr/local/bin/mysqld_safe --user=mysql
    bin/mysqladmin -u root password '123'
    /etc/init.d/mysql start



   
3. 安装php-5.3.6
   在安装PHP之前要先安装zlib libpng jpeg freetype fontconfig gd,
  /usr/local/zlib   apt-get install libxml2-dev
  /usr/local/libpng apt-get install libpng12-dev
  /usr/local/jpeg   ubuntu 默认安装
  /usr/local/freetype apt-get install libfreetype6-dev
  /usr/local/fontconfig ubuntu 默认安装
  
  
  安装 /usr/local/gd
  tar zxvf gd-2.0.35.tar.gz
  cd gd/2.0.35/
  ./configure --prefix=/usr/local/gd
  make
  make install
  tar xvf php-5.3.6.tar.bz2
  cd  php-5.3.6
  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --enable-gd-native-ttf  --enable-gd-jis-conv --enable-xml --enable-mbstring --enable-sockets --enable-bcmath



#--enable-bcmath  是以后装zabbix需要的。     
    make
    make install
   
    vim /usr/local/apache/conf/httpd.conf
    在合适位置加上 LoadModule php5_module modules/libphp5.so

4.安装rrdtool
    Rrdtool需要一些库文件的支持,这些库文件的安装非常耽误时间,在此我们使用
   apt-get install 相关库文件来装,装得不全会报错的。一定要装完
    cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel intltool
    不然就会    configure: error: Please fix the library issues listed above and try again.
    tar -zxvf rrdtool-1.4.5.tar.gz
    cd rrdtoos-1.4.5
    ./configure --prefix=/usr/local/rrdtool --disable-tcl
    make
    make install
    ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
     cp -r gbsn00lp.ttf /usr/share/fonts/zh_CN/TrueType/ 复制字体给rrdtool 使用

5.安装net-snamp
    tar zxvf net-snmp-5.4.2.1.tar.gz
    cd  net-snmp-5.4.2.1
    ./configure --prefix=/usr/local/net-snmp --enable-developer
    make
    如果报错
    /usr/bin/ld: cannot find -lperl
    collect2: ld returned 1 exit status
   
    ln -s /usr/lib/libperl.so.5.10 /usr/lib/libperl.so
   
    make install
   
    vim /usr/local/neit-snmp/share/snmp/snmpd.conf修改可以访问SNMP的网段和community
    比如
    #       sec.name  source          community
    com2sec local     localhost       public
    com2sec mynetwork 192.168.15.1    public
    com2sec mynetwork 192.168.1.1    public
   
    ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
    启动
    /usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf
    测试
    snmpwalk -v 2c -c public 127.0.0.1  有数据返回则成功。

6.安装cacti
    tar zxvf cacti-0.8.7g.tar.gz
    cd cacti-0.8.7g
    cp -r * /usr/local/apache/htdocs
    useradd cacti
    chown -R cacti /usr/local/apache/htdocs/rra
    chown -R cacti:cacti  /usr/local/apache/htdocs
   
    登录MySQL,新建数据,并授权
    mysql -uroot -p123

    Mysql>create database cacti;
    Mysql>grant all on cacti.* to cacti@'localhost' identified by 'cacti';
    Mysql>flush privileges;
   
    导入cacti数据库

    #cd /usr/local/apache/htdocs
    gedit cacti.sql
    将 TYPE=MyISAM 全部替换为 ENGINE=MyISAM
    导入数据库
    #mysql -uroot -p123 cacti < cacti.sql

    修改cacti安装配置文件

    #vim /usr/local/apache/htdocs/include/config.php
    修改为
    * make sure these values refect your actual database/host/user/password */
    $database_type = "mysql";
    $database_default = "cacti";
    $database_hostname = "localhost";
    $database_username = "cacti";
    $database_password = "cacti";
    $database_port = "3306";
    终端运行 crontab -e,加入以下内容
*/5 * * * *  /usr/local/php/bin/php /usr/local/apache2/htdocs/poller.php > /dev/null 2>&1

运行以下步骤
启动apahce ,mysql,snmp
/etc/init.d/httpd start
/etc/init.d/mysql
/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf

访问http://0.0.0.0/install/index.php
如果出现以下情况:

    1.直接显示php代码,php没有装好,重装php。
    2.页面是空白
    vim /usr/local/apache/conf/httpd.conf
    在相应位置加入
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php .phtml .php3 .php4
    AddType application/x-httpd-php-source .phps
    AddType image/x-icon .ico
    设置为以下
   
        DirectoryIndex index.php
   

    重启apache
这个时候cacti可以正常运行了。

7.安装nagios
    /usr/sbin/useradd nagios
    passwd nagios

    /usr/sbin/groupadd nagios
    /usr/sbin/usermod -G nagios nagios
   
    /usr/sbin/groupadd nagcmd
    /usr/sbin/usermod -G nagcmd nagios
    /usr/sbin/usermod -G nagcmd www-data
   
    tar -xvf nagios-cn-3.2.3.tar.bz2
    cd nagios-cn-3.2.3
   
    先要安装用apt-get install
    libgd
    libgd-devel
    libpng
    libpng-devel
    libjpeg
    libjpeg-devel
    zlib
   
    ./configure --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-command-group=nagcmd  gd非常重要,不然不能生成nagios的stausmap.cgi

  
    make install
    make install-init
    make install-config
    make install-commandmode
   
    创建一个 nagiosadmin 的用户用于 Nagios 的 WEB 接口登录。记下你所设置的登录口令,一会儿你会用到它。
    htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios

    验证 Nagios 的样例配置文件
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
   
    编译并安装 Nagios 插件
     tar -zxvf nagios-plugins-1.4.15.tar.gz
     cd nagios-plugins-1.4.15
     ./configure --with-nagios-user=nagios --with-nagios-group=nagios

     make
     make install
     vim /usr/local/apache/conf/httpd.conf
     添加以下到最后
     

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin


    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    Require valid-user


Alias /nagios /usr/local/nagios/share


    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    Require valid-user

   
    由于创建的用户为nagios,所以还要修改cgi.cfg,不然权限不够。
    vim /usr/local/nagios/etc/cgi.cfg
    在nagiosadmin后加上nagios 注意用‘,’号隔开
   
     重启apache,启动nagios
    /etc/init.d/httpd restart
    /etc/init.d/nagios start
   
正常工作。

以下是在安装过程中出现的问题和处理方法。
1.It appears as though you do not have permission to view information for any of the services you requested...

打开cgi.cfg配置文件,里面有个参数:
use_authentication=1
为了保障系统的安全性,nagios设置了这个参数,默认为1,改为0即可
这个只是临时解决方案,其实该在cgi.cfg的nagiosadmin后面加上你建立的nagios用户名,我就用的nagios


2.It seems that you have chosen to not use the authentication functionality of the CGIs.
I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Nagios,so you'll have to disable this safeguard if you are really stubborn and want to invite trouble.

原因 : 认证用户不正确
开启认证 认证的用户必须是 cgi.cfg 配置文件里有的 默认是 nagiosadmin
如果你新建的其他用户 需要添加进去 多用户用逗号分开
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin

如果不是 nagiosadmin 需要到后面添加
例子 authorized_for_system_information=nagiosadmin,admin
3.Ubuntu下安装MySQL出现FATAL ERROR: Could not find mysqld的处理
错误信息:
#./bin/mysql_install_db –user=mysql
FATAL ERROR: Could not find mysqld
The following directories were searched:
/usr/libexec
/usr/sbin
/usr/bin
If you compiled from source, you need to run ‘make install’to copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top of the level of the extracted archivem or pass the –basedir option pointing to that location.

解决办法:
在安装目录下运行 scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(这里mysql是所使用的用户名,basedir是mysql的安装目录)
4.安装cacti时,在导入cacti.sql 这个文件时报错:
The command "mysql -u root -p cacti < cacti.sql' gets the following error:
ERROR 1064 (42000) at line 5: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 6
原因是mysql5这后不再支持 TYPE=MyISAM  这样的语法了,改成  ENGINE=MyISAM 就可以了。
5.Warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/local/apache2/htdocs/include/global_constants.php on line 154

解决方法
1:改 php.ini
cp php-5.3.6/php.ini-production /usr/local/php/lib/php.ini
改date.timezone ='Asia/Shanghai'
date.timezone=PRC 重启apache 然后再试试
2:在程序代码中写入
第一行写入:date_default_timezone_set ('Asia/Shanghai');
ini_set('date.timezone','Asia/Shanghai');


6.cacti无法显示图片,在rra文件夹下没有生成*.rra文件。
解决方法:
/usr/local/php/bin/php /usr/local/apache/htdocs/poller.php  > /dev/null 2>&1
php 问题,重新编译php
cacti配置中rrdtool 版本选1.2,rra文件夹权限问题
7.进入cacti后显示白板
解决方法:
php-mysql 没装好,重装php,编译加入php-mysql

8.访问cacti会提示:Error
解决方法:
编译php 需要加参数--enable-sockets
9.编译net-snmp出现 command 'gcc' failed with exit status 1
重新编译 net-snmp ./configure --prefix=/usr/local/net-snmp --enable-developer --with-python-modules=/usr/local/bin/python --with-ipython-modules=/usr/local/bin/ipython
10.nagios 乱码问题
在apache http.conf 中加入AddDefaultCharset UTF-8
11.nagios 无法执行命令开通知
在apache http.conf 中加入 User nagios  Group nagios
如还有不全,请大家提出。










运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-662107-1-1.html 上篇帖子: 装cacti的痛苦经历 下篇帖子: ceneos5.5的中文cacti安装部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表