Centos 6.8 安装lnmp+ zabbix3.0.2

技术小甜 2017-11-08

nginx php mysql zabbix yum 配置 centos index prefix vim service

系统:centos6.8

Zabbix-server(服务端):192.168.137.36

Zabbix-agent(客户端):192.168.137.35

以下是zabbix-server服务端安装操作

 

yum install lrzsz -y

 

安装nginx

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum clean all

yum repolist

yum install -y nginx

 

 

安装mysql

wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

rpm -Uvh mysql57-community-release-el6-9.noarch.rpm

yum install mysql-community-server

service mysqld start

grep 'temporary password' /var/log/mysqld.log  

mysql -uroot -p

set global validate_password_policy=0;

set global validate_password_length=6;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123';   

 

 

 

安装php

 

下载 PHP 源码包

wget http://cn2.php.net/distributions/php-5.6.0.tar.xz

xz -d php-5.6.0.tar.xz

tar xf php-5.6.0.tar -C /usr/local/src/

 

安装依赖

yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel

 

创建 www 用户

groupadd www

useradd -g www -s /sbin/nologin -M www

编译安装

cd /usr/local/src/php-5.6.0/

 

./configure \

--prefix=/usr/local/php56 \

--with-config-file-path=/usr/local/php56/etc \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-opcache \

--enable-fpm \

--with-fpm-user=www \

--with-fpm-group=www \

--with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-gettext \

--enable-mbstring \

--with-iconv \

--with-mcrypt \

--with-mhash \

--with-openssl \

--enable-bcmath \

--enable-soap \

--with-libxml-dir \

--enable-pcntl \

--enable-shmop \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--enable-sockets \

--with-curl \

--with-zlib \

--enable-zip \

--with-bz2 \

--with-readline

 

# make -j8

# make install

 

配置 PHP

配置文件:

cp php.ini-development /usr/local/php56/etc/php.ini

 

php-fpm 服务

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

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56

chmod +x /etc/init.d/php-fpm56

启动 php-fpm

service php-fpm56 start

wKiom1nbM9HQ711kAAAEdCPwLN8172.png-wh_50

php-fpm 可用参数 start|stop|force-quit|restart|reload|status

 

添加 PHP 命令到环境变量

编辑 ~/.bash_profile,将:

 

PATH=$PATH:$HOME/bin

改为:

PATH=$PATH:$HOME/bin:/usr/local/php56/bin

 

使 PHP 环境变量生效:

. ~/.bash_profile

 

查看 PHP 版本

php -v

 wKiom1nbM-SDLFwmAAATxtZrJXc726.png-wh_50

 

测试短语、

vim /usr/share/nginx/html/a.php
<?php

        phpinfo();

    ?>


http://ip/a.php

 

wKioL1nbM6mziaAKAAF6UpW0xxM870.png-wh_50

 如出现以上界面 表示lnmp环境搭建成功

 

 

如果访问网址的时候回报错 解决方法:

 

wKioL1nbM7_x2wkLAAaacqc7Uxw812.png-wh_50

 

location ~ \.php$ {

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

        include        fastcgi_params;  

    }   

 

 

 

zabbix安装

下载zabbix的安装包

 

创建zabbix用户

groupadd zabbix

useradd -g zabbix zabbix -s /sbin/nologin

 

解压源码包

tar zxvf zabbix-3.0.2.tar.gz -C /usr/src/

 

进入数据库

mysql -u root -p

 

创建zabbix数据库

CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

 

创建zabbix授权库账户zabbix,密码是123456

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

 

导入zabbix数据表结构

use zabbix;

source /usr/src/zabbix-3.0.2/database/mysql/schema.sql;

source /usr/src/zabbix-3.0.2/database/mysql/data.sql;

source /usr/src/zabbix-3.0.2/database/mysql/images.sql;

 

安装组件

yum install -y net-snmp net-snmp-devel curl curl-devel

进入解压目录,编译安装

cd /usr/src/zabbix-3.0.2/

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

 

 

会报错:

configure: error: MySQL library not found

the problem is not installed mysql-devel

解决方法:yum install mysql-devel  

 

make && make install

 

创建日志目录

mkdir /usr/local/zabbix/logs

编辑zabbix_agentd配置文件

cd /usr/local/zabbix/etc/

mv zabbix_agentd.conf zabbix_agentd.conf.bak

vim zabbix_agentd.conf

内容如下:

LogFile=/usr/local/zabbix/logs/zabbix_agentd.log

Server=127.0.0.1

#ServerActive=127.0.0.1

Hostname=Zabbix server

 

编辑zabbix_server配置文件

mv zabbix_server.conf zabbix_server.conf.bak

vim zabbix_server.conf

内容如下:

LogFile=/usr/local/zabbix/logs/zabbix_server.log

DBName=zabbix

DBUser=zabbix

DBHost=localhost

DBPassword=123456

AlertScriptsPath=/usr/local/zabbix/alertscripts

 

创建自定义脚本目录,设置权限,目录下的脚步,可以被zabbix调用

mkdir /usr/local/zabbix/alertscripts

chown zabbix:zabbix -R /usr/local/zabbix

 

更改php.ini文件

sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php56/etc/php.ini

sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php56/etc/php.ini

sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php56/etc/php.ini

sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php56/etc/php.ini

sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php56/etc/php.ini

sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php56/etc/php.ini

 

vim /usr/local/php56/etc/php.ini

cgi.fix_pathinfo=0

改为

cgi.fix_pathinfo=1

 

重启php-fpm

service php-fpm56  restart

进入源码目录,复制启动脚本 

cd /usr/src/zabbix-3.0.2/misc/

cp init.d/tru64/zabbix_server /etc/init.d/

cp init.d/tru64/zabbix_agentd /etc/init.d/

chmod +x /etc/init.d/zabbix_*

 

修改zabbix_agentdzabbix_server程序目录的位置

vim /etc/init.d/zabbix_agentd

内容如下:

DAEMON=/usr/local/zabbix/sbin/zabbix_agentd

 

vim /etc/init.d/zabbix_server

内容如下:

DAEMON=/usr/local/zabbix/sbin/zabbix_server

 

 

由于zabbix_server 服务不支持 chkconfig,使用下列方法自启动

 

vim /etc/init.d/zabbix_server

#!/bin/sh下面一行添加

 

#chkconfig: 345 95 95

#description: Zabbix_Server

 

vim /etc/init.d/zabbix_agentd

#!/bin/sh下面一行添加

 

#chkconfig: 345 95 95

#description: Zabbix_agentd

 

添加到系统服务

chkconfig zabbix_server on

chkconfig zabbix_agentd on

 

编辑系统库配置文件

vim /etc/ld.so.conf

加入一行

/usr/local/mysql/lib/

 

重新加载

ldconfig

启动服务

/etc/init.d/zabbix_server start

/etc/init.d/zabbix_agentd start

查看端口

netstat -ntpl|grep zabbix

tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      21188/zabbix_agentd

tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      21140/zabbix_server

 

 

复制php页面,并设置权限

cp -rf /usr/src/zabbix-3.0.2/frontends/php/ /usr/local/zabbix/php

chown www:www -R /usr/local/zabbix/php/

 

编辑nginx配置文件

vim /etc/nginx/conf.d/default.conf

 

内容如下:

把之前的内容注释掉并增加以下内容

server {

        listen   80;

        server_name localhost;

        root /usr/local/zabbix/php;

        index index.php index.html index.htm;

 

        location / {

            if (!-e $request_filename) {

                rewrite  ^(.*)$  /index.php/$1  last;

                break;

            }

        }

 

        location ~ \.php {

                fastcgi_pass   127.0.0.1:9000;

                fastcgi_index  index.php;

                include        fastcgi_params;

                set $real_script_name $fastcgi_script_name;

                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {

                   set $real_script_name $1;

                   set $path_info $2;

                }

 

                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

                fastcgi_param SCRIPT_NAME $real_script_name;

                fastcgi_param PATH_INFO $path_info;

        }

 

}

 

重新加载nginx

/etc/init.d/nginx restart

 

编辑php配置文件,开启中文

vim /usr/local/zabbix/php/include/locales.inc.php

打开'zh_CN' => ['name' => _('Chinese (zh_CN)'),     'display' => true],

/etc/init.d/php-fpm56 restart

 

 

 

访问 http://ip/setup.php  例如:http://192.168.137.36/setup.php

 

wKiom1nbNCajkAkYAADJf7-PEHQ337.png-wh_50

出现报错

解决方法:

 

PHP option always_populate_raw_post_data must be set to -1

打开/usr/local/php56/etc/php.ini文件把always_populate_raw_post_data = -1这一行注释打开,保存重启php-fpm56

wKioL1nbM-XwgQ0hAAAtY9ZnzFE174.png-wh_50

 

 

1. Freetype

wget "http://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.bz2"

tar jxvf freetype-2.4.0.tar.bz2

cd freetype-2.4.0

./configure --prefix=/usr/local/freetype && make && make install

 

 

2. jpegsrc

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

tar zxvf jpegsrc.v9.tar.gz

cd jpeg-9

CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/jpeg && make && make install

 

 

3. libpng

tar zxvf libpng-1.6.31.tar

cd libpng-1.6.31

CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/libpng && make && make install

 

 

 cd /usr/local/src/php-5.6.0/ext/gd/

运行/usr/local/php56/bin/phpize 命令

./configure --with-php-config=/usr/local/php56/bin/php-config  --with-jpeg-dir=/usr/local/jpeg  --with-png-dir=/usr/local/libpng   --with-freetype-dir=/usr/local/freetype

 

出现了异常error: png.h not found.

 

解决办法:

yum install libpng-devel,下面就是编译安装

./configure --with-php-config=/usr/local/php56/bin/php-config  --with-jpeg-dir=/usr/local/jpeg  --with-png-dir=/usr/local/libpng   --with-freetype-dir=/usr/local/freetype

 

make && make install

 

接着修改php.ini文件  ; default extension directory. 下面添加一行extension=gd.so

yum install php-gd

service nginx restart

/etc/init.d/php-fpm56 restart

 

 

 

输入密码123456

wKiom1nbNE2g_IbKAACfAoZYpnk801.png-wh_50

 

解决方法

ln -s /var/lib/mysql/mysql.sock /tmp/

 

vim /usr/local/php56/etc/php.ini

mysqli.default_socket = /var/lib/mysql/mysql.sock

 

wKioL1nbNBPTYJJ9AAAfKXhSA88962.png-wh_50

/etc/init.d/php-fpm56 restart

 

 

 

然后一直下一步 输入用户名Admin,密码zabbix

wKiom1nbNSSCOdYFAAA2UNpSAyc279.png-wh_50




















本文转自去轻狂书生51CTO博客,原文链接: http://blog.51cto.com/8999a/1970956,如需转载请自行联系原作者


登录 后评论
下一篇
corcosa
16498人浏览
2019-10-08
相关推荐
史上最全建站教程
16198人浏览
2017-07-25 17:09:51
lamp一键安装包
1454人浏览
2013-04-12 09:44:00
1.4 Cobbler基础配置
940人浏览
2017-05-24 14:20:45
LNMP安装
870人浏览
2017-11-15 16:22:00
Centos 6.8安装Python3.7
1165人浏览
2018-08-07 18:21:23
CentOS所有下载
2590人浏览
2016-08-02 13:39:00
AMH面板安装记录
759人浏览
2017-08-19 13:08:00
LNMP_6.8+1.11.0+5.6.12+5.6.22
581人浏览
2017-11-22 18:38:00
CentOS 6.8学习笔记
476人浏览
2018-05-26 17:17:00
0
0
0
686