CENTOS7+LNMP+zabbix3.2.6安装配置

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

1、安装MySQL

1.1、安装MySQL

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

yum -y install mysql-server

1.2、修改MySQL的配置文件

vim /etc/my.cnf

[mysqld]

default-storage-engine = innodb

innodb_file_per_table

collation-server = utf8_general_ci

init-connect = 'SET NAMES utf8'

character-set-server = utf8

1.3、设置MySQL自动启动并启动MySQL(CENTOS 7):

# systemctl start mysqld

# systemctl enable mysqld

1.4、设置MySQL安全选项

mysql_secure_installation 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
NOTE: RUNNING  ALL  PARTS  OF  THIS SCRIPT  IS  RECOMMENDED  FOR  ALL  MySQL
       SERVERS  IN  PRODUCTION USE!  PLEASE  READ  EACH STEP CAREFULLY!
In  order  to  log  into  MySQL  to  secure it, we 'll need the current
password for the root user.  If you' ve just installed MySQL,  and
you haven 't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
  ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
  ... Success!
Normally, root should only be allowed to connect from ' localhost '.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
  ... Success!
By default, MySQL comes with a database named ' test ' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
  - Dropping test database...
ERROR 1008 (HY000) at line 1: Can' drop  database  'test' database  doesn 't exist
  ... Failed!  Not critical, keep moving...
  - Removing privileges on test database...
  ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
  ... Success!
All done!  If you' ve completed  all  of  the above steps, your MySQL
installation should now be secure.
Thanks  for  using MySQL!
Cleaning up...

1.5、创建Zabbix数据库

mysql -uroot -pkingdee

mysql> create database zabbix character set utf8 collate utf8_bin;

Query OK, 1 row affected (0.04 sec)

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

Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql> quit

Bye

2、安装PHP

2.1、安装PHP

先安装第三方组件:

yum  -y groupinstall  "Development Tools"

yum install libxml2* -y  

yum install curl curl-devel

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64

yum install libjpeg-devel

wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz

tar zxvf bzip2-1.0.6.tar.gz

cd bzip2-1.0.6

make install

再下载安装PHP 5.5.38:

wget http://php.net/distributions/php-5.5.38.tar.gz

tar zxvf php-5.5.38.tar.gz

./configure --prefix=/usr/local/php-5.5.38 --with-config-file-path=/usr/local/php-5.5.38/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

make

make install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Installing shared extensions:     /usr/local/php-5.5.38/lib/php/extensions/no-debug-non-zts-20121212/
Installing PHP CLI binary:        /usr/local/php-5.5.38/bin/
Installing PHP CLI man page:      /usr/local/php-5.5.38/php/man/man1/
Installing PHP FPM binary:        /usr/local/php-5.5.38/sbin/
Installing PHP FPM config:        /usr/local/php-5.5.38/etc/
Installing PHP FPM man page:      /usr/local/php-5.5.38/php/man/man8/
Installing PHP FPM status page:      /usr/local/php-5.5.38/php/php/fpm/
Installing PHP CGI binary:        /usr/local/php-5.5.38/bin/
Installing PHP CGI man page:      /usr/local/php-5.5.38/php/man/man1/
Installing build environment:     /usr/local/php-5.5.38/lib/php/build/
Installing header files:          /usr/local/php-5.5.38/include/php/
Installing helper programs:       /usr/local/php-5.5.38/bin/
   program: phpize
   program: php-config
Installing man pages:             /usr/local/php-5.5.38/php/man/man1/
   page: phpize.1
   page: php-config.1
Installing PEAR environment:      /usr/local/php-5.5.38/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.3.0
[PEAR] PEAR           - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php-5.5.38/etc/pear.conf
You may want to add: /usr/local/php-5.5.38/lib/php to your php.ini include_path
/root/php-5.5.38/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.5.38/bin
ln -s -f phar.phar /usr/local/php-5.5.38/bin/phar
Installing PDO headers:          /usr/local/php-5.5.38/include/php/ext/pdo/


cp php.ini-production /usr/local/php-5.5.38/etc/php.ini

cp /usr/local/php-5.5.38/etc/php-fpm.conf.default /usr/local/php-5.5.38/etc/php-fpm.conf

vim /usr/local/php-5.5.38/etc/php.ini

post_max_size=16M

max_execution_time=300

max_input_time=300

date.timezone=Asia/Shanghai

always_populate_raw_post_data=1

启动PHP

/usr/local/php-5.5.38/sbin/php-fpm

3、安装NGINX

yum install pcre*

yum install openssl*

mkdir -p /data/logs/nginx/

mkdir -p /data/site/centos7/

编译安装:

wget http://nginx.org/download/nginx-1.13.3.tar.gz

tar zxvf nginx-1.13.3.tar.gz

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre

make

make install

其它安装方法:(可选)

rpm安装:

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

启动,停止

/usr/local/nginx/sbin/nginx  

/usr/local/nginx/sbin/nginx  -s stop

重置:当你有修改配置文件的时候,只需要reload一下即可

/usr/local/nginx/sbin/nginx -s reload

4、配置nginx php互通

在nginx.conf的http断中加上如下内容:(注意把原值注释掉)

vim  /usr/local/nginx/conf/nginx.conf

server {

listen 80;

server_name centos7;

access_log /data/logs/nginx/centos7.access.log;

index index.php index.html index.html;

root /data/site/centos7;

location /

{

try_files $uri $uri/ /index.php?$args;

}

location ~ .*\.(php)?$

{

expires -1s;

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass 127.0.0.1:9000;

}

}

建立测试文件

vim /data/site/centos7/info.php

<?php

phpinfo();

?>

3. 访问测试

curl http://centos7/info.php  test php

注:nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/php5fpm.sock;

1、首行,在配置文件/usr/local/php-5.5.38/etc/php-fpm.conf文件中找到

listen = 127.0.0.1:9000

修改为:

listen = /var/run/php5fpm.sock

listen.mode=0666

然后,重启php-fpm

2、接着,配置nginx

在/usr/local/nginx/conf/nginx.conf中找到

fastcgi_pass 127.0.0.1:9000;

修改为:

fastcgi_pass unix: /var/run/php5fpm.sock;

授权然后重启PHP:

chmod 777 /var/run/php5fpm.sock

重启nginx:

注意,不关闭SELINUX可能导致无法启动HTTP服务,参考下面方案关闭:

1、临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

##setenforce 1 设置SELinux 成为enforcing模式

2、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可

5、安装zabbix server

wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz

tar -zxvf zabbix-3.2.0.tar.gz

groupadd zabbix

useradd -g zabbix zabbix

yum install mysql-devel

yum install net-snmp-devel

./configure --prefix=/usr/local/zabbix-3.2/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Configuration:
   Detected OS:           linux-gnu
   Install path:          /usr/local
   Compilation arch:      linux
   Compiler:              gcc
   Compiler flags:         -g -O2
   Library-specific flags:
     database:               -I/usr/include/mysql -g  -m64 -fPIC  -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing   
     libXML2:               -I/usr/include/libxml2
     Net-SNMP:               -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include
   Enable server:         yes
   Server details:
     With database:         MySQL
     WEB Monitoring:        cURL
     Native Jabber:         no
     SNMP:                  yes
     IPMI:                  no
     SSH:                   no
     TLS:                   no
     ODBC:                  no
     Linker flags:             -L/usr/lib64/mysql        -L/usr/lib64      -rdynamic  
     Libraries:               -lmysqlclient      -lxml2    -lnetsnmp      -lcurl -lm -ldl  -lresolv 
   Enable proxy:          no
   Enable agent:          yes
   Agent details:
     TLS:                   no
     Linker flags:              -rdynamic  
     Libraries:                 -lcurl -lm -ldl  -lresolv 
   Enable Java gateway:   no
   LDAP support:          no
   IPv6 support:          no
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************


make

make install

导入表:

mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql

上述导库请务必注意顺序,否则会出现错误:

ERROR 1146 (42S02) at line 2: Table 'zabbix.hosts' doesn't exist  

配置 zabbix_server 配置文件:vim  /usr/local/zabbix-3.2/etc/zabbix_server.conf

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

5.1 拷贝前端文件

mkdir /data/site/centos7/zabbix

cp -rp frontends/php/* /data/site/centos7/zabbix

启动 zabbix server

/usr/local/zabbix-3.2/sbin/zabbix_server

启动 nginx

/usr/local/nginx/sbin/nginx

启动 PHP

/usr/local/php-5.5.38/sbin/php-fpm

6、其它相关设置及错误解决

做本机HOTS解析

vim /etc/hosts

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

写zabbix_server服务文件:

vim /lib/systemd/system/zabbix_server.service

[Unit]  

Description= zabbix_server

After=network.target  

[Service]  

Type=forking  

ExecStart= /usr/local/zabbix-3.2/sbin/zabbix_server

ExecReload=

ExecStop=

PrivateTmp=true  

[Install]  

WantedBy=multi-user.target

写Nginx服务文件:

vim /lib/systemd/system/nginx.service  

[Unit]  

Description=nginx  

After=network.target  

[Service]  

Type=forking  

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -r reload

ExecStop=/usr/local/nginx/sbin/nginx -s stop

PrivateTmp=true  

[Install]  

WantedBy=multi-user.target

写PHP服务文件:

先启用PHP的PID文件

vim /usr/local/php-5.5.38/etc/php-fpm.conf

pid =/run/php-fpm.pid

再写PHP服务文件

vim /lib/systemd/system/php.service  

[Unit]  

Description=php

After=network.target  

[Service]  

Type=forking  

ExecStart=/usr/local/php-5.5.38/sbin/php-fpm

ExecReload=/usr/local/php-5.5.38/sbin/php-fpm -USR2 `cat ‘run/php-fpm.pid’

ExecStop=/usr/local/php-5.5.38/sbin/php-fpm -INT `cat ‘run/php-fpm.pid’

PrivateTmp=true  

[Install]  

WantedBy=multi-user.target

完成后,授权、启动服务、设置服务自动启动:

chmod 754 /lib/systemd/system/zabbix_server.service

chmod 754 /lib/systemd/system/nginx.service

chmod 754 /lib/systemd/system/php.service

systemctl start zabbix_server

systemctl start php

systemctl start nginx

systemctl start zabbix_server

systemctl enable php

systemctl enable nginx

systemctl enable zabbix_server

以后如何修改了服务文件,需要使用systemctl daemon-reload  重新加载下服务。

如果少安装了PHP的扩展,以bcmath为例:

先安装

yum install php-bcmath

再参考下面方案添加扩展:

http://blog.csdn.net/u014642915/article/details/60868280

PHP连接MySQL报错"No such file or directory"的解决办法

http://www.linuxidc.com/Linux/2012-12/76150.htm

zabbix_server日志(默认位置)

cat /tmp/zabbix_server.log

很多时间权限会导致一些问题(比如NGINX安装向导要向网站中写入配置文件 /data/site/centos7/zabbix/conf/zabbix.conf.php),需要对CONF目录授权:

chmod -R 777 /data/site/centos7/zabbix/conf

安装后设置服务器:

wKiom1lvauqgYWkiAAEH7qBGtm8676.png-wh_50

wKioL1lvauvjIhG_AAF0uP4qPo4576.png-wh_50

wKiom1lvauzjeGa8AAER8jX7rAM233.png-wh_50

wKiom1lvauzjP4NwAAECDTYVdSM016.png-wh_50

wKioL1lvau3iTTBuAAE3CD-eUDA357.png-wh_50

wKiom1lvau6ycXbUAAETEK7_s_g022.png-wh_50

7、安装Zabbix Agent

7.1、下载相关的软件包

wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.6-1.el7.x86_64.rpm

7.2、安装Zabbix Agent

yum localinstall zabbix-agent-3.2.6-1.el7.x86_64.rpm

7.3、修改Zabbix Agent配置

vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.90.127

7.4、设置Zabbix Agent自动启动并启动Zabbix Agent

systemctl start zabbix-agent

systemctl enable zabbix-agent



本文转自 sfih 51CTO博客,原文链接:http://blog.51cto.com/dayday/1949113


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3月前
|
应用服务中间件 Linux 网络安全
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
centos7 下离线安装gcc g++ nginx,并配置nginx进行网络流转发
104 0
|
1月前
|
Java Linux
Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
【2月更文挑战第16天】Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
29 0
|
1月前
|
分布式计算 关系型数据库 MySQL
Sqoop【部署 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
【2月更文挑战第8天】Sqoop CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
93 1
|
10天前
|
网络协议
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
11 0
|
30天前
|
运维 Linux 应用服务中间件
Centos7如何配置firewalld防火墙规则
Centos7如何配置firewalld防火墙规则
40 0
|
1月前
|
存储 监控 Linux
Flume【部署 02】Flume监控工具Ganglia的安装与配置(CentOS 7.5 在线安装系统监控工具Ganglia + 权限问题处理 + Flume接入监控配置 + 图例说明)
【2月更文挑战第17天】Flume【部署 02】Flume监控工具Ganglia的安装与配置(CentOS 7.5 在线安装系统监控工具Ganglia + 权限问题处理 + Flume接入监控配置 + 图例说明)
28 1
Flume【部署 02】Flume监控工具Ganglia的安装与配置(CentOS 7.5 在线安装系统监控工具Ganglia + 权限问题处理 + Flume接入监控配置 + 图例说明)
|
2月前
|
关系型数据库 MySQL Linux
Azkaban【部署 02】CentOS release 7.5安装配置azkaban-3.70.0安装阶段(含已编译的10个安装文件:可直接进行安装)
【2月更文挑战第5天】CentOS release 7.5安装配置azkaban-3.70.0安装阶段(含已编译的10个安装文件:可直接进行安装)
48 7
|
2月前
|
Java Linux 开发工具
Azkaban【部署 01】Linux环境 CentOS Linux release 7.5.1804安装配置azkaban-3.70.0编译阶段(附安装包及gradle-4.6资源)
【2月更文挑战第4天】Linux环境 CentOS Linux release 7.5.1804安装配置azkaban-3.70.0编译阶段(附安装包及gradle-4.6资源)
30 1
|
2月前
|
Ubuntu Linux 网络安全
|
3月前
|
负载均衡 算法 Linux
百度搜索:蓝易云【Centos7系统Haproxy安装配置教程】
现在,HAProxy已经成功安装和配置在您的CentOS 7系统上。它将监听您配置的端口,并根据负载均衡策略将请求转发到后端服务器。您可以根据需要自定义更多的配置,如SSL终止、ACL和更复杂的负载均衡算法。请确保HAProxy的配置符合您的需求,并在进行更改之前备份配置文件,以防止意外的错误。
41 2