Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181230
  • 博文数量: 26
  • 博客积分: 215
  • 博客等级: 入伍新兵
  • 技术积分: 346
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-21 15:00
文章分类

全部博文(26)

文章存档

2017年(10)

2016年(1)

2015年(2)

2014年(1)

2013年(7)

2012年(5)

我的朋友

分类: 系统运维

2017-09-13 10:16:52

一、准备搭建环境
esxi5.5 安装的CentOS7,并请升级到最新版一下升级命令
[root@localhost ~]# yum upgrade

二、安装前端的准备
1、关闭SELinux
1)首先查看SELinux状态
[root@localhost ~]# getenforce
Enforcing
2)修改SELinux状态,这个修改是重启后永久生效
[root@localhost ~]# vim /etc/selinux/config
在文件中查找一下这行
SELINUX=Enforcing
把后面的Enforcing参数修改为disabled
SELinux=disabled
-----------------下面说下三个参数-------------------------
i、enforcing    开启防火墙
ii、permissive    关闭防火墙,但是会产生相应的日志
iii、disabled        彻底关闭防火墙,没日志产生
-----------------continue---------------------------------

3)不重启的情况下关闭SElinux,注意此操作在重启之后会失效,但重要的是当前有效^_^
[root@localhost ~]# setenforce 0

2、关闭防火墙
1)永久关闭防火墙(修改自启动)
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.se
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.servic

2)当前环境关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service

3)安装支持软件 curl wget vim
[root@localhost ~]# yum -y install curl wget vim mlocate
-----------------关于上述软件简介-------------------------
i、curl    命令行模式下的常用下载工具之一
ii、wget    命令行模式下的常用下载工具之一
iii、vim    命令行模式下的文本编辑工具
VI、mlocate 实际命令是locate,是命令模式下的搜索工具之一(和find类似)
-----------------continue---------------------------------

3、安装数据库和授权
1)安装MariaDB数据库
-----------------背景介绍-------------------------
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,10.0.9版起使用XtraDB(名称代号为Aria(英语:Aria (storage engine)))来代替MySQL的InnoDB。 MariaDB由MySQL的创始人麦克尔·维德纽斯(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自麦克尔·维德纽斯的女儿玛丽亚(英语:Maria)的名字。
PS:mariadb-devel是开发的头文件和静态库。
参考链接:
https://mariadb.com/kb/zh-cn/about-the-mariadb-rpm-files/
http://www.bing.com/knows/search?q=mariaDB&mkt=zh-cn
-----------------continue---------------------------------
[root@localhost ~]# yum -y install mariadb-server mariadb-devel

2)开启MariaDB数据库
[root@localhost ~]# systemctl start mariadb.service

3)查看MariaDB数据库在进程的状态
[root@localhost ~]# ss -tulnp | grep mysqld
tcp    LISTEN     0      50        *:3306                  *:*

-----------------关于ss命令资料,请查看以下链接---------------------------------
ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容。但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效。
ss参数解释:
-t, --tcp 仅显示 TCP套接字(sockets)
-u, --udp 仅显示 UCP套接字(sockets)
-l, --listening 显示监听状态的套接字(sockets)
-n:把服务名称显示成端口号
-p, --processes 显示使用套接字(socket)的进程
更详细的命令介绍可以使用man来查看系统内的文档或者查看下面这个链接:
http://www.cnblogs.com/peida/archive/2013/03/11/2953420.html
----------------------continue------------------------------------------------------------
4)配置数据库授权
---------------------------about command------------------------------------------------------
[root@localhost ~]# mysql
直接进入mysql数据库命令行模式
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
create database zabbix是创建zabbix数据库
charcater set utf8是把默认字符集设置为utf8
collate utf8_bin是数据库校对规则
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123456';
这是为zabbix访问mysql数据库赋权用的,请记住你的密码(在这里是123456)
MariaDB [(none)]> use mysql  
进入mysql库
MariaDB [mysql]> select * from user\G;
查看服务器授权信息
参考链接:
http://www.cnblogs.com/thinksasa/archive/2013/01/11/2856228.html
---------------------------continue---------------------------------------------------------

[root@localhost ~]# mysql
WWelcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select * from user\G;
*************************** 5. row ***************************
                  Host: localhost
                  User: zabbix
              Password: *34757C1337D8000484BB6513159265C470DD581C
           Select_priv: N
           Insert_priv: N
           Update_priv: N
           Delete_priv: N
           Create_priv: N
             Drop_priv: N
           Reload_priv: N
         Shutdown_priv: N
          Process_priv: N
             File_priv: N
            Grant_priv: N
       References_priv: N
            Index_priv: N
            Alter_priv: N
          Show_db_priv: N
            Super_priv: N
 Create_tmp_table_priv: N
      Lock_tables_priv: N
          Execute_priv: N
       Repl_slave_priv: N
      Repl_client_priv: N
      Create_view_priv: N
        Show_view_priv: N
   Create_routine_priv: N
    Alter_routine_priv: N
      Create_user_priv: N
            Event_priv: N
          Trigger_priv: N
Create_tablespace_priv: N
              ssl_type:
            ssl_cipher:
           x509_issuer:
          x509_subject:
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin:
 authentication_string:
5 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye

4、安装zabbix的基础安装
本部分主要包括mysql、zabbix的rpm包、db数据导和zabbix基础配置优化
1)获取并安装zabbix的yum源(实际为repos文件)
[root@localhost ~]#rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

2)创建yum元数据缓存
yum makecache

3)查看文件:
[root@localhost ~]# yum search zabbix
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.cn99.com
 * updates: mirrors.btte.net
======================================= N/S matched: zabbix ========================================
pcp-export-zabbix-agent.x86_64 : Module for exporting PCP metrics to Zabbix agent
zabbix-agent.x86_64 : Zabbix Agent
zabbix-get.x86_64 : Zabbix Get
zabbix-java-gateway.x86_64 : Zabbix java gateway
zabbix-proxy-mysql.x86_64 : Zabbix proxy for MySQL or MariaDB database
zabbix-proxy-pgsql.x86_64 : Zabbix proxy for PostgreSQL database
zabbix-proxy-sqlite3.x86_64 : Zabbix proxy for SQLite3 database
zabbix-release.noarch : Zabbix repository configuration
zabbix-sender.x86_64 : Zabbix Sender
zabbix-server-mysql.x86_64 : Zabbix server for MySQL or MariaDB database
zabbix-server-pgsql.x86_64 : Zabbix server for PostgresSQL database
zabbix-web.noarch : Zabbix web frontend common package
zabbix-web-mysql.noarch : Zabbix web frontend for MySQL
zabbix-web-pgsql.noarch : Zabbix web frontend for PostgreSQL
zabbix-web-japanese.noarch : Japanese font settings for frontend

  名称和简介匹配 only,使用“search all”试试。

----------------------------------about rpm---------------------------------
zabbix-agent:zabbix客户端,用来收集客户端各种参数
zabbix-get:zabbix的一个工具,用来检查是否可以获取服务器信息(一般服务端要安装)
zabbix-java-gateway:用于监控JMX应用的程序,它把收集到的信息发送个(这个看需求安装,我暂时没装)
zabbix-proxy:zabbix proxy可以代替zabbix server检索客户端的数据,然后把数据汇报给zabbix server,并且在一定程度上分担了zabbix server的压力。zabbix proxy可以非常简便的实现了集中式、分布式监控。
zabbix-release:会生成一个zabbix的yum源,可以直接下载相关软件包。
zabbix-sender:用于发送数据给server或者proxy。
zabbix-web.noarch:zabbix要使用web前端界面,这个包是用来处理Apache和php,mysql等之间的依赖关系。
zabbix-web-mysql:这个是zabbix前段支持mysql的
zabbix-web-japanese:支持日语

参考资料链接:
http://ju.outofmemory.cn/entry/97105
http://www.ttlsa.com/zabbix/zabbix-section-3-of-chapter-1/
http://www.ttlsa.com/zabbix/zabbix-proxy-proxies/
-----------------------------------continue---------------------------------

4)选择自己需要的安装包进行安装,我只选了几个需要的:
[root@localhost ~]#yum install -y zabbix-get zabbix-sender zabbix-server-mysql zabbix-web-mysql zabbix-web zabbix-agent

5)开始查找create.sql文件位置
[root@localhost ~]# locate create.sql
如果返回结果是空的话则说明没有找到
[root@localhost opt]# rpm -qa|grep zabbix
zabbix-get-3.4.1-1.el7.x86_64
zabbix-release-3.4-2.el7.noarch
zabbix-web-pgsql-3.4.1-1.el7.noarch
zabbix-server-mysql-3.4.1-1.el7.x86_64
zabbix-agent-3.4.1-1.el7.x86_64
zabbix-web-3.4.1-1.el7.noarch
zabbix-sender-3.4.1-1.el7.x86_64
[root@localhost opt]# rpm -ql zabbix-server-mysql-3.4.1-1.el7.x86_64
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-3.4.1
/usr/share/doc/zabbix-server-mysql-3.4.1/AUTHORS
/usr/share/doc/zabbix-server-mysql-3.4.1/COPYING
/usr/share/doc/zabbix-server-mysql-3.4.1/ChangeLog
/usr/share/doc/zabbix-server-mysql-3.4.1/NEWS
/usr/share/doc/zabbix-server-mysql-3.4.1/README
/usr/share/doc/zabbix-server-mysql-3.4.1/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
----------------------------------about create.sql---------------------------------
首先使用locate没有找到,同样试了find(这里也没有,就忽略了),于是搞不好就直接干
rpm -ql ***.rpm
是查看安装包内的文件存放列表的
-----------------------------------continue---------------------------------

6)切到zabbix-server目录
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.1/

7)解压create.sql.gz
[root@localhost /]# cd /usr/share/doc/zabbix-server-mysql-3.4.1/
[root@localhost zabbix-server-mysql-3.4.1]# gunzip create.sql.gz
[root@localhost zabbix-server-mysql-3.4.1]# ls -l create.sql
-rw-r--r--. 1 root root 4970756 8月  28 17:57 create.sql

8)使用sql脚本(create.sql)创建数据库
[root@localhost zabbix-server-mysql-3.2.4]# mysql -uzabbix -p zabbix < create.sql
会提示输入密码,别问我密码是啥(上面有说)

9)查找这个mysql.sock文件路径,一会要用到:
[root@localhost zabbix-server-mysql-3.4.1]# ls -l /var/lib/mysql/mysql.sock
srwxrwxrwx. 1 mysql mysql 0 9月  12 17:01 /var/lib/mysql/mysql.sock
----------------------------------about mysql.sock---------------------------------
可使用以下命令查找
[root@localhost ~]# locate mysql.sock
-----------------------------------continue---------------------------------

10)修改zabbix_server_conf这个配置文件
[root@localhost zabbix-server-mysql-3.4.1]# vim /etc/zabbix/zabbix_server.conf
i)修改DBPassword
#DBPassword=
DBPassword=123456 //new
ii)修改DBSocket
#DBSocket=/tmp/mysql.sock
DBSocket=/var/lib/mysql/mysql.sock //new
-------------------------------正常应该有这几个参数-------------------------------------------
[root@localhost zabbix-server-mysql-3.4.1]# grep -E -vn "^#|^$" /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=123456
133:DBSocket=/var/lib/mysql/mysql.sock
316:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
434:Timeout=4
476:AlertScriptsPath=/usr/lib/zabbix/alertscripts
486:ExternalScripts=/usr/lib/zabbix/externalscripts
522:LogSlowQueries=3000
关于grep:grep是匹配字符的一个工具
-E:”*|*“中的|两侧的字符是”或“的关系,简单理解就是多项匹配
-v:取反匹配到的字符
-n:显示行数
正则:请自行百度
----------------------------------continue----------------------------------------------------

11)编辑/etc/httpd/conf.d/zabbix.conf文件,修改时区
vim /etc/httpd/conf.d/zabbix.conf
   
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai                                //去掉此行前面的#,操作本文改为亚洲/上海
   

12)开启一些列服务,包括Apache、Mariadb、zabbix-server、zabbix-agent
[root@localhost zabbix-server-mysql-3.4.1]# systemctl start httpd.service
[root@localhost zabbix-server-mysql-3.4.1]# systemctl start mariadb
[root@localhost zabbix-server-mysql-3.4.1]# systemctl start zabbix-server
[root@localhost zabbix-server-mysql-3.4.1]# systemctl start zabbix-agent

13)上述4个服务设置成开机自启动
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable mariadb      
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

14)查看ip,直接用浏览器来安装zabbix
[root@localhost ~]# ip addr|grep global
    inet 192.168.1.33/24 brd 192.168.1.255 scope global ens160

5、在浏览器上配置zabbix
1)web访问地址
http://192.168.1.33/zabbix

2)安装步骤
*欢迎界面

*检查预配置

*配置zabbix访问mariaDB,访问zabbix库赋权的用户名(zabbix)和密码(123456)

*配置细节,修改servername名称

*预安装汇总信息

*创建php配置文件,完成web配置

3)登录zabbix修改默认语言为中文
账号密码默认为:Admin  zabbix



6、后续显示问题处理
1)错误 strtotime(): It is not safe to rely on the system's timezone settings.
问题描述:登录后各显示页面报错

问题解决思路:根据安装过程可以看到zabbix的前端用的是httpd和php,之前已经在zabbix-server中配置了市区问题,使用排除法已可以确定是php的时区没有配置导致;
尝试解决:查找php.ini中timezone配置项

[root@localhost ~]# sed -i "s@;date.timezone =@date.timezone = Asia/Shanghai@g" /etc/php.ini
[root@localhost ~]# sed -i "s@post_max_size = 8M@post_max_size = 32M@" /etc/php.ini
[root@localhost ~]# sed -i "s@max_execution_time = 30@max_execution_time = 300@" /etc/php.ini
[root@localhost ~]# sed -i "s@max_input_time = 60@max_input_time = 300@" /etc/php.ini
[root@localhost ~]# sed -i "s@;always_populate_raw_post_data = -1@always_populate_raw_post_data = -1@" /etc/php.ini

[root@localhost ~]# systemctl restart httpd.service    //重启apache
2)待补充

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