Chinaunix首页 | 论坛 | 博客
  • 博客访问: 598466
  • 博文数量: 248
  • 博客积分: 52
  • 博客等级: 民兵
  • 技术积分: 1028
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-23 12:05
文章分类

全部博文(248)

文章存档

2016年(7)

2013年(241)

分类: LINUX

2013-03-11 03:17:49

#!/bin/bash

#1.0 安装zabbix依懒包

yum install -y httpd php mysql mysql-server gcc* php-mysql  httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath  mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel > /dev/null

#1.1 加载php

cat << ok >> /etc/httpd/conf/httpd.conf

DirectoryIndex index.php

ok

#1.2 开机启动web服务和数据库服务

/etc/init.d/httpd restart

chkconfig httpd on

/etc/init.d/mysqld restart

chkconfig mysqld on

#1.3 给数据库设置密码

mysqladmin -uroot -password 'anfenghu'

#1.4 测试phpapachemysql连接情况

cat << ceshi >> /var/www/html/index.php

it works!

$link=mysql_connect('localhost','root','anfenghu');

if($link)

   echo "success";

else

   echo "fail";

?>

测试成功

ceshi

#2.0 开始安装zabbix

#2.1 首先建立zabbix用户与组

groupadd zabbix

useradd -g zabbix zabbix

tar -zxvf /root/zabbix-2.0.3.tar.gz -C /usr/src  > /dev/null

cd /usr/src/zabbix-2.0.3

#2.2 zabbix创建数据库并添加用户

/etc/init.d/mysqld restart

mysql -uroot -p'anfenghu' << ok

create database if not exists zabbix character set utf8;

grant all privileges on zabbix.* to zabbix@localhost identified by 'anfenghu'; 

flush privileges;

ok

#2.3 zabbix源码包中的数据导入到新建的zabbix数据库

cat /usr/src/zabbix-2.0.3/database/mysql/schema.sql | mysql -uzabbix -p'anfenghu' zabbix  

cat /usr/src/zabbix-2.0.3/database/mysql/images.sql | mysql -uzabbix -p'anfenghu' zabbix

cat /usr/src/zabbix-2.0.3/database/mysql/data.sql | mysql -uzabbix -p'anfenghu' zabbix

#创建zabbix的安装目录并初始化zabbix

mkdir /usr/local/zabbix

/usr/src/zabbix-2.0.3/configure  --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl

make install > /dev/null

ln -s /usr/local/zabbix/etc /etc/zabbix

#2.4 更改配置文件中数据库相关的用户名密码

sed -i 's/DBName=/DBName=zabbix/g'/etc/zabbix/zabbix_server.conf

sed -i 's/DBUser=/DBUser=zabbix/g'/etc/zabbix/zabbix_server.conf

sed -i 's/#DBPassword=/DBPassword=anfenghu/g'/etc/zabbix/zabbix_server.conf

zjm=hostname

sed -i 's/Hostname=/Hostname=$zjm/g' /etc/zabbix/zabbix_agentd.conf

ip=ifconfig | head -2 | awk -F":" '{print $2}'| awk -F" " '{print $1}'| tail -1

sed -i 's/ServerActive=/ServerActive=$ip/' /etc/zabbix/zabbix_agentd.conf

#2.5 zabbix服务端程序做软链接

for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done

for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

#2.6 添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效

echo "/usr/local/mysql-5.1.48/lib/mysql/" >> /etc/ld.so.conf

ldconfig

#2.7 拷贝相应的web程序到相关WEB服务目录下

cp -r /usr/src/zabbix-2.0.3/frontends/php/ /var/www/html/zabbix/

chown -R zabbix:zabbix /var/www/html/zabbix

#2.8 拷贝zabbix的启动脚步到/etc/init.d/

cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_server /etc/init.d

cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d

#2.9 修改启动脚本

sed -i 's/ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_server"/ZABBIX_BIN="\/usr\/local\/zabbix\/sbin\/zabbix_server"/g' /etc/init.d/zabbix_server

/etc/init.d/zabbix_server restart

 

sed -i 's/ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_agentd"/ZABBIX_BIN="\/usr\/local\/zabbix\/sbin\/zabbix_agentd"/g' /etc/init.d/zabbix_agentd

/etc/init.d/zabbix_agentd restart

chkconfig zabbix_server on

chkconfig zabbix_agentd on

sed -i 's/date.timezone =/date.timezone =Asia\/Shanghai/' /etc/php.ini

sed -i 's/post_max_size =/post_max_size =32M/' /etc/php.ini

sed -i 's/max_execution_time =/max_execution_time =300/' /etc/php.ini

sed -i 's/max_input_time =/max_input_time =300/' /etc/php.ini

sed -i 's/memory_limit =/memory_limit =128M/' /etc/php.ini

sed -i 's/mbstring\.func_overload =/mbstring\.func_overload =2/' /etc/php.ini

/etc/init.d/httpd restart

chkconfig httpd on









阅读(1219) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~