安装ZABBIX教程

一、配置host,network,iptables

cat /etc/hosts

vim /etc/sysconfig/network-script/ifcfg-eth0

service iptables stop

二、配置yum及安装依赖包

mkdir  /media/yum

mount /dev/cdrom /media/mount

或mount -t iso9660 /dev/cdrom /media/rhel5

cp /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/bak.rhel-source.repo.bak

vi /etc/yum.repos.d/rhel-source.repo

rhel-source.repo文件内容以下:

[Server]

name=Server

baseurl=file:///media/rhel5/Server

enabled=1

gpgcheck=0

yum安装rpm包如下报错:

warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

执行如下命令完成修复:

rpm --import /etc/pki/rpm-gpg/RPM*

安装依赖包

yum install  compat-lib* binutils-2* gcc* glibc-2* glibc-devel-2* ksh libgcc-4* libstdc++-4*  libstdc++-d* libaio-0* libaio-d* sysstat-9* make-3*

三、安装nginx

1.安装nginx相关依赖包

yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel

2.解压压缩包

tar -xvf nginx-1.10.3.tar.gz

3.安装nginx到目录/usr/local/nginx

cd nginx-1.10.3

./configure --prefix=/opt/nginx #nginx安装到此目录

make #编译

make&make install #编译安装

4.为后续配合PHP,故需要配置nginx.conf

#在如下目录新建目录web_root

cd /opt/nginx

mkdir web_root

#编辑nginx.conf以支持PHP,修改部分见如下红字。

修改项:

#新建一行:root /opt/nginx/web_root

#修改一行:将之前的scripts修改为/opt/nginx/web_root

[root@ZABBIX conf]# more nginx.conf

listen 80;

server_name localhost;

############add by guanyy#################

root /opt/nginx/web_root;

##########################################

location / {

root html;

index index.php index.html index.htm;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /opt/nginx/web_root$fastcgi_script_name;

include fastcgi_params;

}

location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ {

              root          /opt/nginx/web_root;

          }

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one #

#location ~ /\.ht {

# deny all;

#}

}

5.启动nginx

/opt/nginx/sbin/nginx

6.新建一个测试文件index.php,测试成功后再删除

cd /usr/local/nginx/web_root/

[root@ZABBIX web_root]# more index.php

<?php

phpinfo();

?>


四、安装mysql

1、安装依赖包

yum install cmake gacc* ncurses-devel -y

yum -y install libail perl autoconf 

2、修改配置文件

vim /etc/my.cnf

[mysqld]

basedir= /opt/mysql/mysql

datadir=/opt/mysql/mysql_data

socket=/opt/mysql/mysql_data/mysql.sock

log-error=/opt/mysql/error.log

pid-file_=/opt/mysql/mysql.pid

user=root

tmpdir=/tmp

port=3306

3、创建用户

useradd -g mysql mysql -s /sbin/nologin

chown -R mysql.mysql /opt/mysql

4、设置开启自启

cp /opt/mysql/mysql/support-files/mysql.server /etc/init.d/mysql

chmod 755 /etc/init.d/mysql

chkconfig mysql on 

5、修改配置环境

echo "/opt/mysql/mysql/lib/">>/etc/ld.so.conf.d/mysql.conf

ldconfig -v | grep mysql

echo  "export PATH=$PATH:/opt/mysql/mysql/bin">> /etc/profile.d/mysql.sh

chmod +x /etc/profile.d/mysql.sh

source /etc/profile.d/mysql.sh

6、编译安装

./mysqld --defaults-file=/etc/my.cnf --initialize  --user=root --pid-file=/opt/mysql/mysql.pid  --basedir=/opt/mysql/mysql  --datadir=/opt/mysql/mysql_data --tmpdir=/tmp  --log-error=/opt/mysql/error.log

make install #编译安装

7、开启数据库

service mysql start

A temporary password is  generated for root@localhost:Eidr>vv1moy:

7.1、更改数据库账号密码及登录权限

mysql -uroot -p  //登录数据库

set password for root@localhost = password('gacHZroot@2018');

flush privileges

create database zabbix character set utf8 collate utf8_bin;

grant all privileges on zabbix.*  to zabbix@'%' identified by 'zabbix';

flush privileges

7.2将zabbix安装中的数据写入数据库

ls /opt/zabbix-3.0.25/database/mysql

mv zabbix-3.0.25/ zabbix/     

mysql -uroot -p zabbix < schema.sql  

mysql -uroot -p zabbix < images.sql

mysql -uroot -p zabbix < data.sql

mysql -uroot -p 

use zabbix

show table

7.3、初始化报错

初始化后登录mysql报错1:

[root@zabbix mysql]# mysql -uroot -p

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决办法1:把mysql原有sock链接到报错地址

[root@zabbix mysql]# ps -ef | grep mysql

root     10317     1  0 10:38 pts/5    00:00:00 /bin/sh /opt/mysql/mysql/bin/mysqld_safe --datadir=/opt/mysql/mysql_data --pid-file=/opt/mysql/mysql.pid

root     10508 10317  4 10:38 pts/5    00:00:02 /opt/mysql/mysql/bin/mysqld --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql_data --plugin-dir=/opt/mysql/mysql/lib/plugin --user=root --log-error=/opt/mysql/error.log --pid-file=/opt/mysql/mysql.pid --socket=/opt/mysql/mysql_data/mysql.sock --port=3306

root     10564  9024  0 10:39 pts/5    00:00:00 grep mysql

[root@zabbix mysql]# ln  -s /opt/mysql/mysql_data/mysql.sock /tmp/mysql.sock

五、安装zabbix

1、创建用户

useradd zabbix -s /sbin/nologin

2、安装rpm依赖包

yum -y install  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-deve pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip-devel --skip-broken

yum install mysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xm --skip-broken

yum install java*

3、指定目录安装

./configure  --prefix=/opt/zabbix --e nable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl  --with-libxml2

4、编译 安装

make && make install 

5、修改配置文件

vim /opt/zabbix/etc/zabbix_server.conf

LogFile=/opt/zabbix/log/zabbix.server.log

DBPassword=zabbix

Timeout=30

Include=/opt/oracle_shell/

AllowRoot=1

User=root

6、赋权

chown -R zabbix.zabbix /opt/zabbix

六、安装PHP

1、安装PHP--编译安装需删除rpm包

yum install php*

yum install http*

2、修改配置文件

vim /etc/php.ini

date.timezone = Asia/Chongqing

max_execution_time = 300

post_max_size=32M

max_input_time=300

memory_limit=128M

3、针对使用不同的网页配置

3.1、使用http

 cd /var/www/html/

[root@zabbix html]# mkdir zabbix

[root@zabbix html]# cd zabbix/

[root@zabbix zabbix]# cp -r /opt/zabbix/zabbix-3.0.25/frontends/php/  ./

[root@zabbix zabbix]# cp -r php/ ../../

[root@zabbix sbin]# which httpd

/usr/sbin/httpd

[root@zabbix sbin]# pwd

/usr/sbin

[root@zabbix sbin]# service httpd start

[root@zabbix sbin]# service httpd status

httpd (pid  16056) is running...

[root@zabbix sbin]# ps -ef | grep httpd

3.2、使用nginx

 cd /opt/nginx/html/

[root@zabbix html]# mkdir zabbix

[root@zabbix html]# cd zabbix/

[root@zabbix zabbix]# cp -r /opt/zabbix/zabbix-3.0.25/frontends/php/  ./

[root@zabbix zabbix]# cp -r php/ ../../

[root@zabbix sbin]# service php-fpm start

[root@zabbix sbin]# service php-fpm status

httpd (pid  16056) is running...

[root@zabbix sbin]# ps -ef | grep php-fpm

4、编译安装php

4.1、安装依赖包

yum -y install libxml2

yum -y install libxml2-devel

yum -y install openssl

yum -y install openssl-devel

yum -y install curl

yum -y install curl-devel

yum -y install libjpeg

yum -y install libjpeg-devel

yum -y install libpng

yum -y install libpng-devel

yum -y install freetype

yum -y install freetype-devel

yum -y install pcre

yum -y install pcre-devel

yum -y install libxslt

yum -y install libxslt-devel

yum -y install bzip2

yum -y install bzip2-devel

4.2、 指定路径安装

./configure --prefix=/opt/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip

4.3、编译安装

make && make install 


4、配置php环境

#复制php配置文件到安装目录

 cp /opt/php/php-7.1.26/ php.ini-production /opt/php/etc/php.ini

#删除系统自带配置文件

 rm -rf /etc/php.ini

#添加软链接到 /etc目录

 ln -s /opt/php/etc/php.ini  /etc/php.ini

 ls -l /etc/php.ini

#复制模板文件为php-fpm配置

 cp /opt/php/etc/php-fpm.conf.default  /opt/php/etc/php-fpm.conf

#添加软件链接到 /etc目录          

ln -s  /opt/php/etc/php-fpm.conf  /etc/php-fpm.conf

#编辑php配置文件php-fpm.conf

 vim /opt/php/etc/php-fpm.conf

pid = run/php-fpm.pid         //如果这个选项在配置文件存在就取消掉注释使用,如果不存在可以忽略,请勿手动添加,否则PHP启动会报错。

user = apache

group = apache

5、设置php-fpm开机自启动

#复制php-fpm到启动目录

[root@ssticentos65 ~]# cp /opt/php/php-7.1.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm

-rw-r--r--. 1 root root 2354 Jan  6 02:37 /etc/init.d/php-fpm

#赋予php-fpm执行权限

[root@ssticentos65 ~]# chmod 755 /etc/init.d/php-fpm

[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm

-rwxr-xr-x. 1 root root 2354 Jan  6 02:37 /etc/init.d/php-fpm

#设置php-fpm开机启动

[root@ssticentos65 ~]# chkconfig php-fpm on

[root@ssticentos65 ~]# chkconfig --list php-fpm

php-fpm        0:off   1:off   2:on    3:on    4:on    5:on    6:off

6、修改PHP.INI配置

#编辑php配置文件php.ini

[root@ssticentos65 ~]# vim /opt/php/etc/php.ini

找到:disable_functions =

修改成disable_functions= passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

找到:date.timezone =

修改为:date.timezone = PRC #设置时区

找到:expose_php = On

修改为:expose_php = Off #禁止显示php版本的信息

找到:short_open_tag = Off

修改为:short_open_tag = On #支持php短标签

找到opcache.enable=0

修改为opcache.enable=1 #php支持opcode缓存

找到:opcache.enable_cli=1 #php支持opcode缓存

修改为:opcache.enable_cli=0

在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能 (在文本按Shift+G就能跳到最后一行)

:wq!     #保存并退出

7、配置nginx支持php

检查www用户和www用户组是否存在,不存在请手动创建

[root@ssticentos65 ~]# cat /etc/passwd | grep www  

apache:x:48:48:Apache:/var/www:/sbin/nologin

www:x:501:3005::/home/www:/bin/bash

[root@ssticentos65 ~]# cat /etc/group | grep www

www:x:3005:

[root@ssticentos65 ~]# vim /opt/nginx/conf/nginx.conf

user  www www;

#首行user去掉注释,修改Nginx运行组为www www;必须与/opt/php/etc/php-fpm.d/www.conf中的user,group配置相同,否则php运行出错

location / {

           root   html;

           index  index.html index.htm index.php;         #添加index.php

}

location ~ \.php$ {

           root           html;

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

           include        fastcgi_params;

       }

#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径

:wq!   #保存并退出

默认情况下etc/php-fpm.d/下有一个名为www.conf.defalut的配置用户的文件,执行下面命令复制一个新文件并且打开:

cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

vim /usr/local/etc/php-fpm.d/www.conf

默认user和group的设置为nobody,将其改为Apache

#启动nginx服务

[root@ssticentos65 ~]# /etc/init.d/nginx restart

#启动php服务

[root@ssticentos65 ~]# /etc/init.d/php-fpm start

网页访问192.168.47.53  显示nginx欢迎主页

8、测试php配置

#进入nginx默认网站根目录

[root@ssticentos65 ~]# cd /opt/nginx/html/

[root@ssticentos65 html]# ls

50x.html  index.html

#删除默认测试页

[root@ssticentos65 html]# rm -rf /opt/nginx/html/*

[root@ssticentos65 html]# pwd

/opt/nginx/html

#新建index.php文件进行测试

[root@ssticentos65 html]# vim index.php

<?php

phpinfo();

?>

:wq!        #保存并退出

#设置目录所有者为 www

[root@ssticentos65 html]# chown www.www /opt/nginx/html/ -R

#设置目录权限

[root@ssticentos65 html]# chmod 755 /opt/nginx/html/ -R

打开浏览器输入服务器IP地址http://192.168.47.53,会看到下面的界面就是php安装成功

七、安装zabbix

网页访问http://192.168.47.53/zabbix/setup.php 

初始账号密码Admin/zabbix

八、配置zabbix

更改字符

复制字体文件并赋权

[root@zabbix fonts]# cd /opt/nginx/html/zabbix/fonts

chown -R apache.apache msyh.ttf

修改参数文件

[root@zabbix include]# vim /opt/nginx/html/zabbix/include/defines.inc.php

define('ZBX_GRAPH_FONT_NAME',           'msyh'); // font file name

define('DEFAULT_LATEST_ISSUES_CNT', 50);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章