首页 > 代码库 > centos6.5 yum 安装zabbix

centos6.5 yum 安装zabbix

关掉相关安全设置,要不出现一大堆乱七八糟的问题

 service iptables stop

 chkconfig iptables off

 setenforce 0

 sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config

 

卸载相关软件包(如果有的话),保持干净环境

 yum remove -y mysql* httpd* php* nginx* zabbix*

 

安装软件包和依赖包

yum -y install wget gcc automake autoconf libtool make cmake bzip2 zlib-devel tree \

pam-devel vim-enhanced man ntpdate unzip telnet python perl perl-devel gcc-c++ zcat \

redhat-lsb tcpdump sysstat lsof git nfs-utils expect traceroute htop lrzsz pymysql\

MySQL-python  libffi-devel libxml2 libxml2-devel libxslt-devel readline-devel \

libffi  epel-release openssl-devel python-devel

 

安装msyql数据库

MySQL建议使用5.6版本,CentOS6默认为5.1,不建议使用,性能偏低。

rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

yum install mysql-server -y  #此过程会因为网路问题偏慢,可以去鲁两发

 

修改msyql配置参数

sed -i ‘/^socket/i\port            = 3306‘ /etc/my.cnf

sed -i ‘/^socket/a\skip-external-locking\nkey_buffer_size = 256M\nmax_allowed_packet = 1M\ntable_open_cache = 256\nsort_buffer_size = 1M\nread_buffer_size = 1M\nread_rnd_buffer_size = 4M\nmyisam_sort_buffer_size = 64M\nthread_cache_size = 8\nquery_cache_size= 16M\nthread_concurrency = 4\ncharacter-set-server=utf8\ninnodb_file_per_table=1‘ /etc/my.cnf

 

[root@localhost ~]# egrep -v ‘^#|^$‘ /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

port            = 3306

socket=/var/lib/mysql/mysql.sock

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

thread_concurrency = 4

character-set-server=utf8

innodb_file_per_table=1

symbolic-links=0

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

启动mysql

/etc/init.d/mysqld start

 

创建zabbxi数据和用户

mysql -e ‘CREATE DATABASE `zabbix` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;‘

mysql -e "GRANT ALL PRIVILEGES on *.* to zabbix@‘‘ IDENTIFIED BY ‘zabbix‘;"

mysql -e "flush privileges"

 

安装php5.6

rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm

yum install php56w php56w-mysql php56w-gd php56w-imap \

php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc \

php56w-mcrypt php56w-mbstring php56w-devel php56w-pecl-memcached \

php56w-common php56w-pdo php56w-cli php56w-pecl-memcache php56w-bcmath php56w-fpm

 

快速设置

sed -i "s/post_max_size.*/post_max_size=16M/" /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#;date.timezone.*#date.timezone=Asia/Shanghai#" /etc/php.ini

sed -i "s/apache/nginx/g" /etc/php-fpm.d/www.conf

sed -i "s#;always_populate_raw_post_data = http://www.mamicode.com/-1#always_populate_raw_post_data = -1#" /etc/php.ini

chown nginx.nginx -R /var/lib/php

 

升级libcurl(zabbix3.0以上的版本说需要curl版本最低7.20.0l支持SMTP的验证,自行查看下版本号)

rpm -ivh http://mirror.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm

yum upgrade libcurl

 

升级完成后可以卸载此yum

rpm -e city-fan.org-release

 

常见问题:

国内很多线路都不能访问city-fan.org的,一般情况下会下载升级,当遇到这样的问题时,你可以直接修改本地主机解析,方法如下:

编辑:/etc/hosts 文件,在尾部添加:

212.56.100.58     www.city-fan.org

212.56.100.58     mirror.city-fan.org

 

[root@localhost ~]# curl -V

curl 7.51.0 (x86_64-redhat-linux-gnu) libcurl/7.51.0 OpenSSL/1.0.1e zlib/1.2.3 c-ares/1.12.0 libssh2/1.8.0 nghttp2/1.6.0

Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp

Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets Metalink

 

安装 zabbix

添加用户

groupadd zabbix 

安装yum源和 zabbix

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm

yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent \

zabbix-java-gateway zabbix-proxy-mysql zabbix-sender

 

配置 zabbix

zabbix数据导入zabbix

zcat /usr/share/doc/zabbix-server-mysql-3.0.5/create.sql.gz |mysql -uzabbix -pzabbix zabbix

 

快速设置

sed -i ‘/DBPassword=/a\DBPassword=zabbix‘ /etc/zabbix/zabbix_server.conf

sed -i ‘/DBHost=/a\DBHost=‘ /etc/zabbix/zabbix_server.conf

 

[root@localhost ~]# egrep -v ‘^$|^#‘ /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

Timeout=4

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts

LogSlowQueries=3000

 

安装nginx

useradd nginx

yum install -y nginx

 

root@localhost ~]# sed -i "/worker_processes/cworker_processes $( grep "processor" /proc/cpuinfo| wc -l );" /etc/nginx/nginx.conf

 

 

[root@localhost ~]# cat> /etc/nginx/conf.d/zabbix.conf <<‘EOF‘

server{

   listen       80;

   server_name  _;

  

   index index.php;

   root /data/web/zabbix;

  

   location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {

       expires 30d;

   }

  

   location ~* \.php$ {

       fastcgi_pass   127.0.0.1:9000;

       fastcgi_index  index.php;

       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

       include        fastcgi_params;

   }

}

EOF

 

修改配置文件

设置权限,并把zabbixphp文件放到web目录

chown nginx.nginx -R  /etc/zabbix/

cp -r /usr/share/zabbix/ /data/web/zabbix

 

root@localhost ~]# cd /etc/nginx/conf.d/

root@localhost conf.d]# rm -f virtual.conf

root@localhost conf.d]# mv default.conf default.conf.bak

root@localhost conf.d]# /etc/init.d/nginx restart

Stopping nginx:                                            [  OK  ]

Starting nginx:                                            [  OK  ]

 

启动并访问

/etc/init.d/nginx start

/etc/init.d/php-fpm start

/etc/init.d/zabbix-server start

/etc/init.d/zabbix-agent restart

 

chkconfig nginx on

chkconfig php-fpm on

chkconfig mysql on

chkconfig zabbix-agent on

chkconfig zabbix-server on


本文出自 “默契少年狂” 博客,请务必保留此出处http://visonkun.blog.51cto.com/2267149/1877247

centos6.5 yum 安装zabbix