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

[经验分享] 基于lamp环境编译安装zabbix

[复制链接]
YunVN网友  发表于 2019-1-21 11:14:42 |阅读模式
  环境:lamp
  系统:centos 6
  前提:编译安装软件需要安装开发环境,关闭iptables和selinux
# yum groupinstall "Development Tools"  "Server Platform Development"  一、编译安装httpd
  httpd2.4需要apr、apr-util依赖包
1.编译安装apr、apr-util

  
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# tar  xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
2.编译安装httpd

  在安装之前需要安装pcre-devel包,因为在编译安装http时会安装pcre,这个包依赖于pcre-devel,系统自带没有pcre-devel这个包
# yum install pcre-devel
# tar xf httpd-2.4.10.tar.bz2  
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install  
  
  3.启动httpd服务

  编译安装的httpd自带有启动脚本:apachectl,所以执行/usr/local/apache/bin/apachectl命令即可启动httpd服务

  直接使用apachectl命令需做一下步骤:
# vim /etc/profile.d/httpd.sh
# .  /etc/profile.d/httpd.sh
# echo $PATH
# cat   /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH  
  4.修改httpd的主配置文件 vim  /etc/httpd24/httpd.conf ,添加下行即可:
PidFile  "/var/run/httpd.pid"  5.将之前的httpd sysv服务脚本拷贝过来并修改配置文件中的以下数据:
cp /etc/rc.d/init.d/httpd   /etc/rc.d/init.d/httpd24
# pidfile: /var/run/httpd.pid
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}  给脚本执行权限:
# chmod +x /etc/rc.d/init.d/httpd24  6.加入服务列表并启动服务:
# chkconfig --add httpd24
# chkconfig httpd24 on
# service httpd24 status
# service httpd24 start  二、编译安装mysql
  1.新建一个lvm,然后将其挂载到数据库目录下:
# mkdir -pv /mydata/data
//此处省略lvm的创建和挂载  
  2.新建用户以安全方式运行
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data  3.安装并初始化mysql
# tar xf mariadb-5.5.43-linux-x86_64.tar.gz  -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db  --datadir=/mydata/data/ --user=mysql     //初始化数据库  4.为数据库创建主配置文件
# mkdir /etc/mysql
# cp support-files/my-large.cnf  /etc/mysql/my.cnf  5.修改配置文件:添加如下几行,并修改此文件中thread_concurrency的值为你的CPU个数乘以2
datadir = /mydata/data           //数据存放目录
innodb_file_per_table= on       //每个innnodb表使用单个表文件
skip_name_resolve = on        //跳过主机名称解析  6.在配置文件中定义“pid-file”文件路径,否则启动mysql会出现错误
vim /etc/my.cnf
pid-file=/mydata/data/mysql.pid
vim /etc/rc.d/init.d/mysqld
mysqld_pid_file_path=/mydata/data  7.为mysql提供sysv服务脚本,并添加至服务列表
# cp support-files/mysql.server   /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start  8.输出mysql的man手册至man命令中:
# vim /etc/man.config   添加下行即可:
MANPATH  /usr/local/mysql/man  9.输出mysql的头文件至系统文件路径/usr/include:
# ln -sv /usr/local/mysql/include  /usr/include/mysql  10.输出mysql的库文件给系统库查找路径:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
重新加载系统库:
# ldconfig  11.修改PATH环境变量,让系统可以直接使用mysql的相关命令:
vim /etc/profile.d/mysqld.sh
# export PATH=/usr/local/mysql/bin:$PATH  三、编译安装php
  1.开始安装php所需依赖环境:

# yum -y groupinstall "Desktop Platform Development"
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
// libmcrypt-devel  本地光盘没有在epel源里面。其他的是epel源.,编译安装libmcrypt  
  2.编译安装libmcrypt
# tar xf libmcrypt-2.5.7.tar.gz  
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install  
  3.开始编译安装php:
  
# tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
#./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  --enable-sockets --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-maintainer-zts  --with-mcrypt=/usr/local/libmcrypt  --with-gd --with-gettext  --enable-bcmath
//msqli:对应mysql另外的一个接口  ,freetype:多种字体 libxml:处理xml的文档 socket:支持socket   apxs:支持http第三方模块   zts:如果之前安装过httpd且模块是prefork则不需要,否则必须安装上去
# make -j     //启用多线程安装(由于php安装比较耗时)
# make install
默认情况下http但是不支持php的,所以需要修改配置文件:
# cp  /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak  
4.为php提供配置文件:
# cp  php.ini-production  /etc/php.ini
5.编辑apache文件使其支持php:
在文件中添加入下行:
DirectoryIndex   index.php  index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
6.重置下httpd服务:
# /usr/local/apache/bin/apachectl reload


7.默认测试页面在/usr/local/apache/htdocs,添加一个index.php测试文件:
8.测试网页http://hostloaclIP

四.编译安装zabbix
  1.解压zabbix包
# tar xf zabbix-2.4.7.tar.gz  2.创建用户和用户组
# groupadd zabbix
# useradd -g zabbix zabbix  3.Server和agent端编译安装
  提前安装好libcurl,否则会出错,一般报错都是因为没有安装所需要的包
# yum install libcurl*
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6  --with-libcurl --with-libxml2

  出现问题:
  
configure: error: Not found mysqlclient library
解决办法:
sudo yum install mysql-devel
configure: error: Curl library not found
解决办法:
sudo yum install curl-devel
# make && make install  4.创建zabbix运行所需要的数据库和用户权限
shell> mysql -uroot -p
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql>  GRANT ALL ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix';  5.将zabbix的初始数据导入到数据库中
# mysql -uzabbix -pzabbix zabbix  < database/mysql/schema.sql
# mysql -uzabbix -pzabbix zabbix  < database/mysql/images.sql
# mysql -uzabbix -pzabbix zabbix  < database/mysql/data.sql
//导入的顺序跟目录下的顺序刚好相反  6.编辑zabiix-server配置文件
# vim /usr/local/etc/zabbix/zabbix_server.conf
        LogFile=/var/log/zabbix_server.log
        LogFileSize=10     //日志大小限制
        PidFile=/var/run/zabbix/zabbix_server.pid
        DBHost=172.16.100.67
        DBName=zabbix
        DBUser=zbxuser
        DBPassword=zbxpass
        DBSocket=/var/lib/mysql/mysql.sock
        SNMPTrapperFile=/var/log/snmptt/snmptt.log
        AlertScriptsPath=/usr/lib/zabbix/alertscripts
        ExternalScripts=/usr/lib/zabbix/externalscripts  7.编辑php.ini文件并重启httpd24服务
# cp  /etc/php.ini /etc/php.ini.bak
# vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
# service httpd24 restart  8.设置时区
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# yum install ntpdate      //安装ntpdate
ntpdate us.pool.ntp.org   //同步时间  9.服务启动与配置
cp提供的init.d启动脚本到系统中去
$ sudo cp misc/init.d/fedora/core/* /etc/init.d/
编辑下启动脚本以适应自己的安装环境,由于默认没有指定安装目录所以不用修改,如果指定安装目录的话则修改“BASEDIR=”即可  10.启动server、agent服务
$ sudo /etc/init.d/zabbix_server start    (或者zabbix_server)
$ sudo /etc/init.d/zabbix_agentd start    (或者zabbix_agentd)  11.添加开机启动服务
sudo chkconfig --add zabbix_server
sudo chkconfig zabbix_server on
sudo chkconfig --add zabbix_agentd
sudo chkconfig  zabbix_agentd on  12.创建并授权zabbix日志目录
$ sudo mkdir /var/log/zabbix
$ sudo chown zabbix:zabbix /var/log/zabbix
$ sudo chmod -R 775 /var/log/zabbix  13.检查服务可用性
$ sudo service zabbix_server  restart
$ sudo service zabbix_server status
[cjx@localhost etc]$ sudo service zabbix_server  restart
Shutting down zabbix_server:                               [确定]
Starting zabbix_server:                                    [确定]
[cjx@localhost etc]$ sudo service zabbix_server status
zabbix_server (pid 11831) 正在运行...
[cjx@localhost etc]$ sudo service zabbix_agentd  status
zabbix_agentd (pid 11501 11500 11499 11498 11497 11495) 正在运行...  14.复制网页到http网页目录下
$ cd frontends/php/
$ sudo cp -a . /usr/local/apache/htdocs/zabbix
$ sudo locale/make_mo.sh  15.打开zabbix web界面
  http://hostlocalIP/zabbix

  











  


  





运维网声明 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-665947-1-1.html 上篇帖子: zabbix搭建与基本配置 下篇帖子: zabbix server和client的快速部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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