2)安装MysqL5.7并安装gcc编译器如下
[root@yankerp-zabbix ~]# yum install gcc gcc-c++ -y
因为在Centos7中默认安装了MysqL的分支mariadb 所以需要卸载mariadb
[root@yankerp-zabbix src]# rpm -qa | grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64 [root@yankerp-zabbix src]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
安装MysqL
下载MysqL二进制包
[root@yankerp-zabbix src]# wget http://mirrors.sohu.com/MysqL/MysqL-5.7/MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz
解压MysqL二进制包,并拷贝到/usr/local/MysqL目录下
[root@yankerp-zabbix src]# tar zxf MysqL-5.7.18-linux-glibc2.5-x86_64.tar.gz [root@yankerp-zabbix src]# mv MysqL-5.7.18-linux-glibc2.5-x86_64 /usr/local/MysqL
进入/usr/local/MysqL/目录创建data目录以及log目录,并给予data755权限。
[root@yankerp-zabbix src]# cd /usr/local/MysqL/ [root@yankerp-zabbix MysqL]# mkdir data [root@yankerp-zabbix MysqL]# mkdir log [root@yankerp-zabbix MysqL]# chmod +755 data/
设置变量
echo "export PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile && source /etc/profile
[root@yankerp-zabbix MysqL]# groupadd MysqL && useradd -r -g MysqL -s /bin/false MysqL打开/etc/my.cnf添加MysqL的主配置文件如下:
vim /etc/my.cnf
[client] socket=/usr/local/MysqL/MysqL.sock [MysqLd] basedir=/usr/local/MysqL datadir=/usr/local/MysqL/data pid-file=/usr/local/MysqL/data/MysqLd.pid socket=/usr/local/MysqL/MysqL.sock log_error=/usr/local/MysqL/log/MysqL.err
[root@yankerp-zabbix MysqL]# chmod 750 data/ && chown -R MysqL . && chgrp -R MysqL . && bin/MysqLd --initialize --user=MysqL
cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd && service MysqLd start
启动完成后MysqL的密码存放到了/usr/local/MysqL/log/目录下
[root@yankerp-zabbix MysqL]# cat /usr/local/MysqL/log/MysqL.err | grep password 2018-01-06T06:31:34.837627Z 1 [Note] A temporary password is generated for root@localhost: s>2%8=/q>sKP进入MysqL数据库并修改MysqL数据库密码
到这里MysqL的安装正式完成
二、安装Nginx
1)安装pcre-devel zlib-devel相关支持包
[root@yankerp-zabbix ~]# yum install zlib-devel pcre-devel -y
2)创建www组以及www用户
[root@yankerp-zabbix ~]# groupadd www [root@yankerp-zabbix ~]# useradd -g www www -s /sbin/nologin
3)下载Nginx源码包
[root@yankerp-zabbix ~]# wget http://Nginx.org/download/Nginx-1.10.2.tar.gz
[root@yankerp-zabbix ~]# tar zxf Nginx-1.10.2.tar.gz [root@yankerp-zabbix ~]# cd Nginx-1.10.2[root@yankerp-zabbix Nginx-1.10.2]# ./configure --prefix=/usr/local/Nginx1.10 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
make && make install
5)创建软连接,优化执行路径,并启动Nginx服务
访问测试:
三、安装PHP
[root@yankerp-zabbix ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz[root@yankerp-zabbix ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@yankerp-zabbix ~]# cd libmcrypt-2.5.7/
[root@yankerp-zabbix libmcrypt-2.5.7]# ./configure && make && make install
ln -s /usr/local/MysqL/lib/libMysqLclient.so.20.3.0 /usr/local/MysqL/lib/libMysqLclient_r.so
下载PHP源码包
[root@yankerp-zabbix ~]# tar zxf PHP-5.6.27.tar.gz [root@yankerp-zabbix ~]# cd PHP-5.6.27/
[root@yankerp-zabbix PHP-5.6.27]#./configure --prefix=/usr/local/PHP5.6 --with-config-file-path=/etc --with-MysqL=/usr/local/MysqL --with-MysqLi=/usr/local/MysqL/bin/MysqL_config --with-MysqL-sock=/usr/local/MysqL/MysqL.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/PHP.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl && make && make install
[root@yankerp-zabbix PHP-5.6.27]# cp PHP.ini-production /etc/PHP.ini
编辑配置文件/etc/PHP.ini ,修改后的内容如下:
找到:
;date.timezone =
修改为:
date.timezone = PRC #设置时区
找到:
expose_PHP = On
修改为:
expose_PHP = Off #禁止显示PHP版本的信息
找到:
short_open_tag = Off
修改为:
short_open_tag = On //支持PHP短标签
找到:
post_max_size = 8M
修改为:
post_max_size = 16M //上传文件大小
找到:
max_execution_time = 30
修改为:
max_execution_time = 300 //PHP脚本最大执行时间
找到:
max_input_time = 60
修改为:
max_input_time = 300 //以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
always_populate_raw_post_data = -1
mbstring.func_overload = 0
创建PHP服务启动脚本
[root@yankerp-zabbix PHP-5.6.27]# cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm [root@yankerp-zabbix PHP-5.6.27]# chmod +x /etc/init.d/PHP-fpm [root@yankerp-zabbix PHP-5.6.27]# chkconfig --add PHP-fpm [root@yankerp-zabbix PHP-5.6.27]# chkconfig PHP-fpm on[root@yankerp-zabbix PHP-5.6.27]#cp /usr/local/PHP5.6/etc/PHP-fpm.conf.default /usr/local/PHP5.6/etc/PHP-fpm.conf
[root@yankerp-zabbix PHP-5.6.27]#vim /usr/local/PHP5.6/etc/PHP-fpm.conf
修改内容如下:
pid = run/PHP-fpm.pid
user = www
group = www
listen =127.0.0.1:9000
pm.max_children = 300
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers =50
启动PHP-FPM服务
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/Nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.PHP index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.PHP$ { # proxy_pass http://127.0.0.1; #} # 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 /scripts$fastcgi_script_name; include fastcgi.conf; } # deny access to .htaccess files,if Apache's document root # concurs with Nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-,name-,and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
在html目录下创建test.PHP写入测试页访问测试:
写入MysqL测试页
vim /usr/local/Nginx/html/test2.PHP
<?PHP $link=MysqL_connect('localhost','root','123456'); if($link) echo "ok"; MysqL_close(); ?>
出现以上图片证明LNMP环境已经可以正常工作!
四、正式安装Zabbix,以上只是搭建环境下面正式安装zabbix
此环境需要提前安装好LNMP环境(MysqL,Nginx,PHP的安装目录均是/usr/local/下)
创建zabbix运行用户
[root@yankerp-zabbix ~]# groupadd zabbix [root@yankerp-zabbix ~]# useradd -g zabbix zabbix
安装所需的包
[root@yankerp-zabbix ~]#yum install -y net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel
安装fping
[root@yankerp-zabbix ~]# tar zxf fping-3.10.tar.gz [root@yankerp-zabbix ~]# cd fping-3.10/ [root@yankerp-zabbix fping-3.10]# ./configure && make && make install [root@yankerp-zabbix fping-3.10]# chown root:zabbix /usr/local/sbin/fping [root@yankerp-zabbix fping-3.10]# chmod 4710 /usr/local/sbin/fpin
安装zabbix-server
[root@yankerp-zabbix ~]# tar zxf zabbix-3.2.1.tar.gz [root@yankerp-zabbix ~]# cd zabbix-3.2.1/[root@yankerp-zabbix zabbix-3.2.1]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-MysqL=/usr/local/MysqL/bin/MysqL_config --with-net-snmp --with-libcurl --with-openipmi
在编译的时候最好带上--enable-java这个参数,方便后续监控tomcat等程序。
make && make install
添加系统软连接
[root@yankerp-zabbix zabbix-3.2.1]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/ [root@yankerp-zabbix zabbix-3.2.1]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
MysqL> create database zabbix character set utf8; Query OK,1 row affected (0.18 sec) MysqL> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK,0 rows affected,1 warning (0.37 sec) MysqL>
导入zabbix初始数据;(切换到zabbix目录)
/root/zabbix-3.2.1/database/MysqL [root@yankerp-zabbix MysqL]# MysqL -uzabbix -pzabbix -hlocalhost zabbix < schema.sql MysqL: [Warning] Using a password on the command line interface can be insecure. [root@yankerp-zabbix MysqL]# MysqL -uzabbix -pzabbix -hlocalhost zabbix < images.sql MysqL: [Warning] Using a password on the command line interface can be insecure. [root@yankerp-zabbix MysqL]# MysqL -uzabbix -pzabbix -hlocalhost zabbix < data.sql MysqL: [Warning] Using a password on the command line interface can be insecure.编辑/usr/local/zabbix/etc/zabbix_server.conf(修改如下)
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
FpingLocation=/usr/local/sbin/fping
[root@yankerp-zabbix MysqL]# mkdir -p /usr/local/zabbix/logs [root@yankerp-zabbix MysqL]# chown -R zabbix:zabbix /usr/local/zabbix/
启动zabbixserver
在ld.so.conf中加入/usr/local/MysqL/lib
[root@yankerp-zabbix ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/MysqL/lib
/usr/local/lib
插入完后执行
我们发现还是没有启动那么接下来查看zabbix_server的日志如下:
上面的提示MysqL.sock问题,接下来打开zabbix主配置文件修改如下:
添加启动脚本
[root@yankerp-zabbix zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server [root@yankerp-zabbix zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd [root@yankerp-zabbix zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_server [root@yankerp-zabbix zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_agentd [root@yankerp-zabbix zabbix-3.2.1]# chkconfig --add zabbix_server [root@yankerp-zabbix zabbix-3.2.1]# chkconfig --add zabbix_agentd [root@yankerp-zabbix zabbix-3.2.1]# chkconfig zabbix_server on [root@yankerp-zabbix zabbix-3.2.1]# chkconfig zabbix_agentd on
修改zabbix开机启动脚本中的zabbix安装目录
vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件
BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #pid文件路径
:wq! #保存退出
vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件
BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #pid文件路径
:wq! #保存退出
正式启动zabbix_server
启动成功后配置zabbix的web界面
[root@zabbix-yankerp ~]# cd /root/zabbix-3.2.1/ [root@zabbix-yankerp zabbix-3.2.1]# cp -r frontends/PHP/ /usr/local/Nginx/html/zabbix [root@zabbix-yankerp zabbix-3.2.1]# chown -R www:www /usr/local/Nginx/html/zabbix/出现以下界面证明
出现以上图片那么证明zabbix正式搭建成功!
2018年新的开始,加油!!!
希望对您有所帮助,再见~~