配置yum环境
[[email protected] yum.repos.d]#wget https://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] yum.repos.d]#yum clean all && yum install -y epel-release
[[email protected] yum.repos.d]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
部署LNMP环境
[[email protected] ~]# yum install -y nginx mariadb-server mariadb mariadb-devel net-snmp-devel libevent-devel php71w php71w-fpm php71w-mbstring php71w-common php71w-gd php71w-mcrypt php71w-mysql php71w-xml php71w-cli php71w-devel php71w-pecl-memcached php71w-pecl-redis php71w-opcache php71w-tidy php71w-bcmath
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl start php-fpm.service
[[email protected] ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service
[[email protected] ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[[email protected] ~]# php -v
PHP 7.1.25 (cli) (built: Dec 6 2018 22:54:10) ( NTS )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright © 1998-2018 Zend Technologies
with Zend OPcache v7.1.25, Copyright © 1999-2018, by Zend Technologies
修改nginx的配置文件
[[email protected] ~]# vim /etc/nginx/nginx.conf
47 location / {
48 index index.html index.php;
49 try_files $uri query_string;
50 }
51
52 location ~* .php$ {
53 root /;
54 fastcgi_index index.php;
55 fastcgi_pass 127.0.0.1:9000;
56 fastcgi_param SCRIPT_FILENAME fastcgi_script_name;
57 include fastcgi_params;
58 }
[[email protected] ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected] ~]# nginx -s reload
编写php测试页面
[[email protected] ~]# cd /usr/share/nginx/html/
[[email protected] html]# vim index.php
web访问查看
http://192.168.1.200/index.php
mariadb数据库配置
[[email protected] html]# mysqladmin -u root password 123123
[[email protected] html]# mysql -u root -p123123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server
Copyright © 2000, 2018, 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 [email protected]’%’ identified by “zabbixpasswd”;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected]’localhost’ identified by “zabbixpasswd”;
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
修改php配置文件
[[email protected] ~]# cp /etc/php.ini{,.bak}
[[email protected] ~]# vim /etc/php.ini
368 max_execution_time = 300
378 max_input_time = 300
656 post_max_size = 16M
877 date.timezone = Asia/Shanghai
源码安装zabbix4.0
笔者这里介绍一下为什么笔者要使用源码编译安装zabbix,因为目前线上环境比较复杂,有ubuntu和centos搭配着使用如果使用源码可能还有趟坑很多
[[email protected] ~]# wget https://sourceforge.net/projects/zabbix/files/ZABBIX Latest Stable/4.0.3/zabbix-4.0.3.tar.gz
[[email protected] ~]# tar xf zabbix-4.0.3.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/zabbix-4.0.3/
[[email protected] zabbix-4.0.3]# useradd -M -s /sbin/nologin zabbix
对于所有zabbix守护进程,需要一个非特权用户。如果从非特权用户帐户启动zabbix守护程序,它将以该用户身份运行。但是,如果守护程序是从“root”帐户启动的,它将切换到“zabbix”用户帐户,该帐户必须存在。要创建这样的用户帐户(在其自己的组中,“zabbix”)
[[email protected] zabbix-4.0.3]# ./configure —prefix=/usr/local/zabbix —enable-server —enable-agent —with-mysql —enable-ipv6 —with-net-snmp —with-libcurl —with-libxml2 && make && make install
[[email protected] zabbix-4.0.3]# cp -r frontends/php/ /usr/share/nginx/html/zabbix
配置zabbix
[[email protected] ~]# cd /usr/local/zabbix/etc/
[[email protected] etc]# cp zabbix_server.conf{,.bak}
[[email protected] etc]# vim zabbix_server.conf
118 DBPassword=zabbixpasswd
导入数据库
[[email protected] ~]# mysql -u zabbix -pzabbixpasswd zabbix < /usr/src/zabbix-4.0.3/database/mysql/schema.sql
[[email protected] ~]# mysql -u zabbix -pzabbixpasswd zabbix < /usr/src/zabbix-4.0.3/database/mysql/images.sql
[[email protected] ~]# mysql -u zabbix -pzabbixpasswd zabbix < /usr/src/zabbix-4.0.3/database/mysql/data.sql
web页面安装zabbix
http://192.168.1.200/zabbix/setup.php
在保证 Web服务器用户具有对 conf/ 目录的写访问权,则会自动保存配置文件,并且可以直接继续执行下一步。
上传下载的配置文件
[[email protected] etc]# cd /usr/share/nginx/html/zabbix/conf/
[[email protected] conf]# ll
总用量 8
-rw-r—r— 1 root root 1036 1月 21 17:41 maintenance.inc.php
-rw-r—r— 1 root root 741 1月 21 17:41 zabbix.conf.php.example
[[email protected] conf]# rz
[[email protected] conf]# ll
总用量 12
-rw-r—r— 1 root root 1036 1月 21 17:41 maintenance.inc.php
-rw-r—r— 1 root root 437 1月 22 09:09 zabbix.conf.php
-rw-r—r— 1 root root 741 1月 21 17:41 zabbix.conf.php.example
重新登录zabbix
http://192.168.1.200/zabbix/
启动zabbix_server&&agent
[[email protected] ~]# /usr/local/zabbix/sbin/zabbix_server
[[email protected] ~]# /usr/local/zabbix/sbin/zabbix_agentd
[[email protected] ~]# netstat -lnpt | egrep ‘10050|10051’
tcp 0 0 0.0.0.0:10050 0.0.0.0: LISTEN 9652/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0: LISTEN 9586/zabbix_server
tcp6 0 0 :::10050 ::: LISTEN 9652/zabbix_agentd
tcp6 0 0 :::10051 ::: LISTEN 9586/zabbix_server
web页面查看报错是否解决
修改zabbix字符集为中文
关于改中文乱码的解决方案
[[email protected] ~]# cd /usr/share/nginx/html/zabbix/fonts/
[[email protected] fonts]# ls
DejaVuSans.ttf
[[email protected] fonts]# mv DejaVuSans.ttf DejaVuSans.ttf.bak
[[email protected] fonts]# rz
上传在windows中找到的中文楷体字体
C:/windows/fronts
[[email protected] fonts]# ls
DejaVuSans.ttf.bak simkai.ttf
[[email protected] fonts]# mv simkai.ttf DejaVuSans.ttf
[[email protected] fonts]# ls
DejaVuSans.ttf DejaVuSans.ttf.bak
[[email protected] fonts]# ll
总用量 4780
-rw-r–r-- 1 root root 4135804 9月 22 2017 DejaVuSans.ttf
-rw-r–r-- 1 apache apache 756072 6月 25 16:57 DejaVuSans.ttf.bak
[[email protected] fonts]# chown -R nginx:nginx *
[[email protected] fonts]# ll
总用量 4780
-rw-r–r-- 1 nginx nginx 4135804 9月 22 2017 DejaVuSans.ttf
-rw-r–r-- 1 nginx nginx 756072 6月 25 16:57 DejaVuSans.ttf.bak