基于lamp环境编译安装zabbix
环境: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
# tarxf 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 install2.编译安装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提供配置文件:
# cpphp.ini-production/etc/php.ini
5.编辑apache文件使其支持php:
在文件中添加入下行:
DirectoryIndex index.phpindex.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 chkconfigzabbix_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_serverrestart
$ sudo service zabbix_server status
$ sudo service zabbix_serverrestart
Shutting down zabbix_server: [确定]
Starting zabbix_server: [确定]
$ sudo service zabbix_server status
zabbix_server (pid 11831) 正在运行...
$ sudo service zabbix_agentdstatus
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
http://s4.运维网.com/wyfs02/M00/7A/85/wKioL1arGZOzLb35AANAM-7WRNo512.png
http://s2.运维网.com/wyfs02/M00/7A/85/wKioL1arGZai7BhjAAJuqCVuvGY154.png
http://s4.运维网.com/wyfs02/M00/7A/85/wKiom1arGVCQYPhNAAMZh_6Zx2g722.png
http://s1.运维网.com/wyfs02/M02/7A/85/wKioL1arGZuQ4mCbAALl7AaZrMU762.png
http://s3.运维网.com/wyfs02/M01/7A/85/wKiom1arGVWBUqK8AAKrFJ3ziC8996.png
http://s2.运维网.com/wyfs02/M02/7A/85/wKioL1arGaCAWdKwAAKCPUEti7k282.png
http://s2.运维网.com/wyfs02/M02/7A/85/wKiom1arGVuRUNxgAALB_9ovljE498.png
http://s4.运维网.com/wyfs02/M01/7A/85/wKiom1arGV2wGkMRAAJK1CXB7h4533.png
http://s3.运维网.com/wyfs02/M01/7A/85/wKioL1arGajz0eAZAAK9SdnQV3U179.png
http://s3.运维网.com/wyfs02/M02/7A/85/wKiom1arGWKjQGHCAAMG51lrCPU726.png
http://s3.运维网.com/wyfs02/M00/7A/85/wKiom1arGWXRtegbAANKf7KZHpM402.png
页:
[1]