关联安装 mysql ,zabbix , nginx, php

/usr/local/zabbix-3.2.6

/usr/local/php-5.6.3

/usr/local/mysql-5.7.26

 

安装mysql

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup  #先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份一下原来的源镜像文件,以免出错后可以恢复

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  #下载新的CentOS-Base.repo 到/etc/yum.repos.d/

 

更改/etc/yum.repos.d/CentOS-Media.repo使其为不生效:

enabled=0

运行yum makecache生成缓存:

yum clean all
yum makecache
yum update

安装MySQL 5.7版本,官网http://dev.mysql.com/downloads/repo/yum/ 

rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

 

可以看到已经有了,并且5.7版本已经启用,可以直接安装:

复制代码
root@192 yum.repos.d]# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community         启用:    24
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64      MySQL Tools Community              启用:    38
mysql-tools-community-source      MySQL Tools Community - Source     禁用
mysql-tools-preview/x86_64        MySQL Tools Preview                禁用
mysql-tools-preview-source        MySQL Tools Preview - Source       禁用
mysql55-community/x86_64          MySQL 5.5 Community Server         禁用
mysql55-community-source          MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64          MySQL 5.6 Community Server         禁用
mysql56-community-source          MySQL 5.6 Community Server - Sourc 禁用
mysql57-community/x86_64          MySQL 5.7 Community Server         启用:   146
mysql57-community-source          MySQL 5.7 Community Server - Sourc 禁用
mysql80-community/x86_64          MySQL 8.0 Community Server         禁用
mysql80-community-source          MySQL 8.0 Community Server - Sourc 禁用
[root@192 yum.repos.d]# 
复制代码

如果没有开启,或者你想要选择需要的版本进行安装,修改 /etc/yum.repos.d/mysql-community.repo,选择需要的版本把enable改为1即可,其它的改为0:

修改好后查看可用的安装版本:

[root@192 yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  24
mysql-tools-community/x86_64      MySQL Tools Community                       38
mysql57-community/x86_64          MySQL 5.7 Community Server                 146

不用犹豫,开始安装吧!

yum -y install mysql-community-server

开始启动mysql:

service mysqld start
Redirecting to /bin/systemctl start  mysqld.service

开机启动设置:

systemctl enable mysqld
systemctl daemon-reload

 

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

[root@192 yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2016-10-23T14:51:45.705458Z 1 [Note] A temporary password is generated for root@localhost: a&sqr7dou7N_
mysql -uroot -p

修改root密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wang****992!';

修改不了密码是因为这个版本增加了安全级别插件,可以把安全策略去掉

vim /etc/my.cnf
添加一下字段值

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
validate_password=off #停止密码策略

 

flush privileges; #刷新系统授权表
systemctl restart mysqld  #重启

 

添加远程登录用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我们添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'evai'@'%' IDENTIFIED BY '@evai2016' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

这样远程就可以用账户名为evai,密码为@evai2016来登录数据库了,运行 select host, user from mysql.user 查看下:

复制代码
mysql> select host,user from mysql.user;

 

 

关联【mysql】

cd /usr/local/zabbix-3.2.6/database/mysql   #进入mysql数据库创建脚本目录

ls #列出文件,可以看到有schema.sql、images.sql、data.sql这三个文件

mysql -u root -p  #进入数据库密码Wang****992!

create database zabbix character set utf8; 

alter user 'zabbix'@'localhost' identified by 'Wang***992!';  #新建账户

grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'Wang****992!' with grant option; #允许账户zabbix能从本机连接到数据库zabbix

flush privileges; #刷新系统授权表

use zabbix  #进入数据库

source /usr/local/zabbix-3.2.6/database/mysql/schema.sql  #导入脚本文件到zabbix数据库

source /usr/local/zabbix-3.2.6/database/mysql/images.sql  #导入脚本文件到zabbix数据库

source /usr/local/zabbix-3.2.6/database/mysql/data.sql  #导入脚本文件到zabbix数据库

exit #退出

cd /usr/lib64/mysql  #32位系统为/usr/lib/mysql

ln -s libmysqlclient_r.so.18.1.0 libmysqlclient_r.so #添加软连接
ln -s libmysqlclient.so.18.1.0 libmysqlclient.so    #添加软连接

 

  

 

安装【zabbix】

yum install net-snmp-devel curl curl-devel mysql-devel  #安装依赖包

cd /usr/local/src #这是软件包下载目录

tar zxvf zabbix-3.2.6.tar.gz #解压

cd /usr/local/src/zabbix-3.2.6/  #进入zabbix安装目录
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config  #选择安装目录/usr/local/zabbix,并关联mysql
make #编译

make install #安装

ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/    #添加系统软连接

ln -s /usr/local/zabbix/bin/* /usr/local/bin/   #添加系统软连接

groupadd zabbix #创建用户组zabbix
useradd zabbix -g zabbix -s /bin/false #创建用户zabbix,并且把用户zabbix加入到用户组zabbix中

 

  

 

 

#find / -name mysql_config 查找位置,如果没有mysql_config,需要安装yum install mysql-devel

#确认服务对应端口

添加zabbix服务对应的端口

vi /etc/services #编辑,在最后添加以下代码

# Zabbix

zabbix-agent 10050/tcp # Zabbix Agent

zabbix-agent 10050/udp # Zabbix Agent

zabbix-trapper 10051/tcp # Zabbix Trapper

zabbix-trapper 10051/udp # Zabbix Trapper

:wq! #保存退出

 

  

 

修改zabbix配置文件(服务端)

vim /usr/local/zabbix/etc/zabbix_server.conf

DBName=zabbix #数据库名称

DBUser=zabbix #数据库用户名,或者root,在web页面填写zabbix信息时要保持一致,否则报错

DBPassword=Wangz****! #数据库密码,可以修改简单密码,要进入数据库修改密码策略

ListenIP=127.0.0.1 #数据库ip地址
ListenPort=10051  #这个必填
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录 :wq! #保存退出

 

  

 修改zabbix配置文件(客户端)

vim /usr/local/zabbix/etc/zabbix_agentd.conf

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

UnsafeUserParameters=1 #启用自定义key

:wq! #保存退出

 

  

 修改zabbix脚本权限和启动项

cp /usr/local/zabbix-3.2.6/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server #服务端 添加开机启动脚本
cp /usr/local/zabbix-3.2.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd #客户端 添加开机启动脚本
chmod +x /etc/rc.d/init.d/zabbix_server #服务端 #添加脚本执行权限 
chmod +x /etc/rc.d/init.d/zabbix_agentd #客户端 #添加脚本执行权限 
chkconfig zabbix_server on #服务端 #添加开机启动
chkconfig zabbix_agentd on #客户端 #添加开机启动

chmod +x /etc/rc.d/init.d/zabbix_server #添加脚本执行权限

chmod +x /etc/rc.d/init.d/zabbix_agentd #添加脚本执行权限

chkconfig zabbix_server on #添加开机启动

chkconfig zabbix_agentd on #添加开机启动

 

  

 

#修改zabbix开机启动脚本中的zabbix安装目录

vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录

:wq! #保存退出

 

 

 #编辑客户端配置文件 

vi /etc/rc.d/init.d/zabbix_agentd

BASEDIR=/usr/local/zabbix/ #zabbix安装目录

:wq! #保存退出

 

#修改php等文件配置来支持zabbix安装要求
vim  /usr/local/php/etc/php.ini

max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
#注释以下
;mbstring.func_overload = 2
:wq!

 

#若bcmath检查项failed,需要执行此步骤:

动态安装模块bcmath

cd /usr/local/src/php-5.6.30/ext/bcmath/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install cp
/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/bcmath.so /usr/local/src/php-5.6.30/ext/bcmath/ vim /usr/local/php/etc/php.ini extension=bcmath.so killall php-fpm ps -ef | grep php-fpm

  rm -rf /usr/local/php/var/run/php-fpm.pid
  /usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf -c /usr/local/php/etc/php.ini  #这样才能够让zabbix重新检测到php.ini配置文件

service php-fpm start

 

#若zabbix报错 PHP gettext off Warning:

动态安装模块gettext

cd /usr/local/src/php-5.6.30/ext/gettext/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/gettext.so /usr/local/src/php-5.6.30/ext/gettext/
vim /usr/local/php/etc/php.ini
#最后一行粘贴
extension=gettext
:wq!
killall php-fpm
ps -ef | grep php-fpm
  rm -rf /usr/local/php/var/run/php-fpm.pid
  /usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf -c /usr/local/php/etc/php.ini  #这样才能够让zabbix重新检测到php.ini配置文件

service php-fpm start

 

#若报错Databaseerror:

The frontend does not match Zabbix database. Current database version (mandatory/optional): 3000000/3020000. Required mandatory version: 3020000. Contact your system administrator.

进入数据库:
mysql> show databases;
mysql> use zabbix;
mysql> update dbversion set mandatory=3020000;
mysql> flush privileges;

重新刷新web页面zabbix即可

 

#web页面填写zabbix读写数据库信息时:

DBHost=192.168.1.12(localhost)
DBPort=0(默认端口3306)
DBName=zabbix(数据库名)
DBUser=root(数据库用户)
DBPassword=Wangz****!

  • Database type
    MySQL
  • Database server
    localhost
  • Database port
    default
  • Database name
    zabbix
  • Database user
    root
  • Database password
  • Zabbix server
    localhost
  • Zabbix server port
    10051
  • Zabbix server name
    zabbix-server

 

#若报错Unable to create the configuration file:

设置 web服务器用户在zabbix网页的conf/目录具有写权限,配置文件会自动保存。

chmod -R 777 /usr/local/nginx/html/zabbix/conf/

 

问题:Failed to restart zabbix-agent.service: Unit not found.
问题:Unit zabbix-server.service could not be found.
问题:/usr/local/etc/zabbix_agentd.conf.d: [2] No such file or directory
解决:Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
问题:linux上 zabbix-server服务启动了但是没有开启10051端口
解决:cat /tmp/zabbix_server.log #登录mysql ,set password=password("123456");  #在配置文件中把端口注释那一项去掉,

 

#检查web页面初始化设置时候的php设置。

find / -name zabbix.conf.php (Linux下的全局搜索命令)

vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php

$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'root';
$DB['PASSWORD'] = 'Wangzq';

 

上面的信息与数据库信息也要同步

因为一开始zabbix初始化IP设置是另一个IP

查看php初始化配置是否一致

 

 

[root@nginx ~]# netstat -lntp | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      38838/zabbix_agentd 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      96922/zabbix_server 
[root@nginx ~]# ps -ef | grep zabbix
... ... ... ... ...
... ... ... ... ...
以上起来就OK

 

 

#配置web站点关联nginx

cd /usr/local/src/zabbix-3.2.6

cp -r /usr/local/src/zabbix-3.2.6/frontends/php /usr/local/nginx/html/zabbix

chown www.www -R /usr/local/nginx/html/zabbix

备注:/usr/local/nginx/html为Nginx默认站点目录 www为Nginx运行账户

service zabbix_server start #启动zabbix服务端

service zabbix_agentd start #启动zabbix客户端

  

#修改php配置文件参数关联php

1、vi /usr/local/php/etc/php.ini #编辑修改

post_max_size =16M

max_execution_time =300

max_input_time =300

date.timezone = "Asia/Shanghai"

:wq! #保存退出

2、vi /usr/local/php/etc/php-fpm.conf #编辑修改

request_terminate_timeout = 300

:wq! #保存退出

 

 

 

 

 

  

service php-fpm reload #重启php-fpm # 命令失败就添加一下代码

#添加一下启动脚本代码

 vim /etc/init.d/php-fpm  #添加开机启动

#! /bin/sh
# Comments to support chkconfig on CentOS
# chkconfig: 2345 65 37
#
set -e
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php/sbin/$NAME
 
CONFIGFILE=/usr/local/php/etc/php-fpm.conf
PIDFILE=/usr/local/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
 
d_start() {
  $DAEMON -y $CONFIGFILE || echo -n " already running"
}
 
d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
 
d_reload() {
  kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
 
case "$1" in
  start)
        echo -n "Starting $DESC is success"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC is success"
        d_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        d_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC is success"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
  *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
         exit 3
        ;;
esac 

 

chmod -R 777 /etc/init.d/php-fpm  #赋予最大权限

/etc/init.d/php-fpm reload  #重启php

#或者这样重启

ps aux|grep php-fpm #查看php-fpm的master进程号
kill -USR2 42891 #重启

 

五、安装web

在浏览器中打开:

http://192.168.1.12/zabbix/setup.php

 

#zabbix忘记登陆账号密码

[root@nginx zabbix]# mysql -uroot -p -e "select * from zabbix.users\G"
Enter password: 
*************************** 1. row ***************************
        userid: 1
         alias: Admin
          name: Zabbix
       surname: Administrator
        passwd: 5fce1b3e34b520afeffb37ce08c7cd66
           url: 
     autologin: 1
    autologout: 0
          lang: en_GB
       refresh: 30
          type: 3
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
*************************** 2. row ***************************
        userid: 2
         alias: guest
          name: 
       surname: 
        passwd: d41d8cd98f00b204e9800998ecf8427e
           url: 
     autologin: 0
    autologout: 900
          lang: en_GB
       refresh: 30
          type: 1
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50

 

#通过mysql修改zabbix密码

[root@abcdocker ~]# mysql -uroot -p
由于密码是md5加密的,我们可以查看默认的zabbix密码的md5
mysql> use zabbix;
mysql> update users set passwd='5fce1b3e34b520afeffb37ce08c7cd66' where userid='1';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
解释:5fce1b3e34b520afeffb37ce08c7cd66  = zabbix
因为zabbix默认密码就是zabbix

 

登录 Web

用户名:Admin
密码:zabbix

 

安装zabbix-agent(客户端)

还是使用zabbix-3.2.6.tar.gz这个包进行安装,与server共用安装目录,不会冲突
cd /usr/local/src/zabbix-3.2.6/
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
ln -s /usr/local/zabbix/sbin/zabbix_agent /usr/local/sbin/
source /etc/profile #刷新下,不然可能执行zabbix_agent命令不生效
2、修改zabbix_agentd.conf配置文件,指定server IP,等信息。
vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix-agent-12

3、将zabbix_agentd启动脚本cp至/etc/init.d/中,zabbix_agentd默认监听10050端口
cd zabbix-3.2.6/
cp ./misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod o+x /etc/init.d/zabbix_agentd
4、若安装客户端时,需要创建zabbix用户,server已创建
useradd -M -s /sbin/nologin zabbix
5、启动agent(默认也是用zabbix用户启动)
/etc/init.d/zabbix_agentd start
或:service zabbix_agentd start
6、查看是否启动
ps -ef|grep zabbix_agentd

 

posted @ 2019-05-22 15:00  快闪开,我要起飞了  阅读(571)  评论(0编辑  收藏  举报