CentOS 6.8编译PHP 7.0.10安装Zabbix3.0.4

前端之家收集整理的这篇文章主要介绍了CentOS 6.8编译PHP 7.0.10安装Zabbix3.0.4前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

环境:

操作系统:CentOS 6.8 x86_64(关闭SELinux、iptables)

Nginx:1.10.1

PHP: 7.0.10

MysqL:5.7.13

Zabbix:3.0.4


一.安装MysqL

1.安装依赖

yum-yinstallgccgcc-develgcc-c++gcc-c++-devellibaio-develboostboost-develautoconf*automake*zlib*libxml*ncurses-develncurseslibgcrypt*libtool*cmakeopensslopenssl-develbisonbison-develunzipnumactl-devel

2.卸载MysqL-libs,否则下面安装MysqL的时候会报错

rpm-e--nodepsMysqL-libs

3.下载解压及安装

wgettarxfMysqL-5.7.13-1.el6.x86_64.rpm-bundle.tar
rpm-ivh`ls|grepMysqL-community|grep-vtest`

4.由于MysqL 5.7跟之前的5.6安全性有很大提升,有很多地方是不一样的

先重置密码

#修改默认字符集
sed-i'/\[MysqLd\]/a\character-set-server=utf8'my.cnf
#启动MysqLd,并进行初始化
/etc/init.d/MysqLdstart
#停止MysqLd,以便进行无密码启动
/etc/init.d/MysqLdstop
#无密码启动MysqL
MysqLd_safe--skip-grant-tables&
MysqL
#注意新版的MysqL5.7在MysqL.user表下已经没有password字段了
MysqL>updateMysqL.usersetauthentication_string=password('123456.abcd')whereuser='root'andHost='localhost';
ERROR1819(HY000):Yourpassworddoesnotsatisfythecurrentpolicyrequirements
#会被告知你的密码不符合当前策略
#修改对应的密码策略,但是密码也至少为9位
MysqL>setglobalvalidate_password_policy=0;
MysqL>updateMysqL.usersetauthentication_string=password('123456.abcd')whereuser='root'andHost='localhost';
serviceMysqLdrestart

二.编译安装PHP 7.0.10

1.安装EPEL源及安装对应的依赖包

rpm-ivhhttp://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum-yinstalllibmcrypt-develmcryptmhashgd-develncurses-devellibxml2-develbzip2-devellibcurl-develcurl-devellibjpeg-devellibpng-develfreetype-develnet-snmp-developenssl-devel

2.安装libiconv

wgethttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tarzxflibiconv-1.14.tar.gz
cdlibiconv-1.14
./configure--prefix=/usr/local/libiconv1.14
make&&makeinstall
cd..

3.下载及编译PHP

wgethttp://cn2.PHP.net/get/PHP-7.0.10.tar.gz/from/this/mirror
tarzxfmirror
cdPHP-7.0.10/
./configure--prefix=/usr/local/PHP7.0.10--with-config-file-path=/usr/local/PHP7.0.10/etc--enable-MysqLnd--with-MysqLi=MysqLnd--with-pdo-MysqL=MysqLnd--with-iconv-dir=/usr/local/libiconv1.14--with-pcre-regex--with-zlib--with-bz2--enable-calendar--with-curl--enable-dba--with-libxml-dir--enable-ftp--with-gd--with-jpeg-dir--with-png-dir--with-zlib-dir--with-freetype-dir--enable-gd-native-ttf--with-mhash--enable-mbstring--with-mcrypt--enable-pcntl--enable-xml--disable-rpath--enable-shmop--enable-sockets--enable-zip--enable-bcmath--with-snmp--disable-ipv6--with-gettext--enable-fpm--with-fpm-user=www--with-fpm-group=www--with-openssl
#注意不能有--enable-gd-jis-conv参数,否则后面图形乱码
make&&makeinstall

4.修改相应参数

cpsapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm
chmod+x/etc/init.d/PHP-fpm
cpPHP.ini-production/usr/local/PHP7.0.10/etc/PHP.ini
#修改时区
sed-i's#;date.timezone=#date.timezone=PRC#g'/usr/local/PHP7.0.10/etc/PHP.ini
#隐藏PHP版本
sed-i's#expose_PHP=On#expose_PHP=Off#g'/usr/local/PHP7.0.10/etc/PHP.ini

cp/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf.default/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i's#;rlimit_files=1024#rlimit_files=65535#g'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i's#;listen.owner=www#listen.owner=www#g'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i's#;listen.group=www#listen.group=www#g'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i's#;listen.mode=0660#listen.mode=0660#g'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i's#listen=127.0.0.1:9000#;listen=127.0.0.1:9000#g'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf
sed-i'/;listen=127.0.0.1:9000/a\listen=/tmp/PHP-fpm.sock'/usr/local/PHP7.0.10/etc/PHP-fpm.d/www.conf

#安全配置,禁用相关函数,注意不能包含scandir和fsockopen,zabbix需要使用到这2个函数
sed-i's#^;cgi.fix_pathinfo=1#cgi.fix_pathinfo=0#g'/usr/local/PHP7.0.10/etc/PHP.ini
sed-i's#disable_functions=#disable_functions=exec,system,eval,passthru,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,fsocket,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g'/usr/local/PHP7.0.10/etc/PHP.ini
#限制执行目录,我的WEB目录都在/var/www/html下
sed-i's#;open_basedir=#open_basedir="/var/www/html/:/tmp/"#g'/usr/local/PHP7.0.10/etc/PHP.ini

#修改PHP相关参数以保证zabbix最低要求
sed-i's#max_execution_time=30#max_execution_time=300#g'/usr/local/PHP7.0.10/etc/PHP.ini
sed-i's#max_input_time=60#max_input_time=300#g'/usr/local/PHP7.0.10/etc/PHP.ini
sed-i's#post_max_size=8M#post_max_size=24M#g'/usr/local/PHP7.0.10/etc/PHP.ini
sed-i's#upload_max_filesize=2M#upload_max_filesize=4M#g'/usr/local/PHP7.0.10/etc/PHP.ini

#修改PHP连接MysqL
sed-i's#pdo_MysqL.default_socket=#pdo_MysqL.default_socket=/var/lib/MysqL/MysqL.sock#g'/usr/local/PHP7.0.10/etc/PHP.ini
sed-i's#MysqLi.default_socket=#MysqLi.default_socket=/var/lib/MysqL/MysqL.sock#g'/usr/local/PHP7.0.10/etc/PHP.ini

增加PHP执行用户
groupadd-g10080www
useradd-gwww-u10080-s/sbin/nologin-d/dev/nullwww


三.安装Nginx

1.下载及安装Nginx

wget
tarzxfNginx-1.10.1.tar.gz
cdNginx-1.10.1
#隐藏Nginx版本
sed-i's#1.10.1#2.2.14.0#g'src/core/Nginx.h
sed-i's#"Nginx/"#"Apache/"#g'src/core/Nginx.h
sed-i's#"Server:Nginx"#"Server:Apache"#g'src/http/ngx_http_header_filter_module.c
sed-i's#<center>Nginx</center>#<center>Apache</center>#g'src/http/ngx_http_special_response.c

./configure--prefix=/usr/local/Nginx1.10.1--user=www--group=www--with-http_stub_status_module--with-http_gzip_static_module--with-http_ssl_module
make&&makeinstall
sed-i's#Nginx/$Nginx_version;#Apache/$Nginx_version;#g'/usr/local/Nginx1.10.1/conf/fastcgi.conf

2.配置Nginx

vim/usr/local/Nginx1.10.1/conf/Nginx.conf

userwwwwww;
worker_processes4;

error_loglogs/error.log;

pidlogs/Nginx.pid;

worker_rlimit_nofile65535;
events{
useepoll;
worker_connections65535;
}

http{
includemime.types;
default_typeapplication/octet-stream;

log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';

access_loglogs/access.logmain;

server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8m;

fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
fastcgi_paramHTTP_PROXY"";
#隐藏后端服务器的相关参数
proxy_hide_headerX-Powered-By;
proxy_hide_headerX-Forwarded-For;
proxy_hide_headerX-AspNet-Version;
proxy_hide_headerX-AspNetMvc-Version;
proxy_hide_headerVia;
proxy_hide_headerX-Varnish;
proxy_hide_headerServer;

gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.1;
gzip_comp_level5;
gzip_disable"MSIE[1-6]\.";
gzip_typestext/plaintext/csstext/xmlapplication/javascriptapplication/x-javascript;
gzip_varyon;

includehost/*.conf;
}

3.配置站点

mkdir/usr/local/Nginx1.10.1/conf/host
vim/usr/local/Nginx1.10.1/conf/host/zabbix.conf
server{
listen80;
server_namelocalhostzabbix;
location/{
root/var/www/html;
indexindex.htmlindex.htmindex.PHP;

error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}

location~\.PHP${
fastcgi_passunix:/tmp/PHP-fpm.sock;
fastcgi_indexindex.PHP;
fastcgi_paramHTTP_PROXY"";
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
}
}


四.安装Zabbix

1.下载及安装zabbix

yum-yinstallOpenIPMI-devel
wgethttp://120.52.73.47/nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz
tar-zxvfzabbix-3.0.4.tar.gz
cdzabbix-3.0.4
./configure--prefix=/usr/local/zabbix3.0.4--enable-server--with-MysqL--with-net-snmp--with-libxml2--with-libcurl--with-openipmi--enable-agent
make&&makeinstalll

2.配置zabbix

cpmisc/init.d/fedora/core5/zabbix_server/etc/init.d/
cpmisc/init.d/fedora/core5/zabbix_agentd/etc/init.d/
sed-i's#/usr/local/sbin/zabbix_server#/usr/local/zabbix3.0.4/sbin/zabbix_server#g'/etc/init.d/zabbix_server
sed-i's#/usr/local/sbin/zabbix_agentd#/usr/local/zabbix3.0.4/sbin/zabbix_agentd#g'/etc/init.d/zabbix_agentd

3.复制WEB站点

mkdir/var/www/html/zabbix
cp-rffrontends/PHP/*/var/www/html/zabbix

4.zabbix乱码图形处理

将Windows操作系统的C:\Windows\Fonts\simkai.ttf字体文件上传至/var/www/html/zabbix/font。防止出现乱码情况

sed-i's#DejaVuSans#simkai#g'/var/www/html/zabbix/include/defines.inc.PHP

5.使用MysqL创建zabbix数据库并授权

MysqL-uroot-p
MysqL>createdatabasezabbixcharactersetutf8;
MysqL>grantallonzabbix.*to'zabbix'@'localhost'identifiedby'zabbix.localhost';

6.导入数据库

进入zabbix-3.0.4源码文件目录
MysqL-uroot-pzabbix<database/MysqL/schema.sql
MysqL-uroot-pzabbix<database/MysqL/data.sql
MysqL-uroot-pzabbix<database/MysqL/images.sql

7.修改zabbix_server配置文件,以下是我的配置文件

egrep-v'^:|^#'/usr/local/zabbix3.0.4/etc/zabbix_server.conf|awk'NF>0'
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix.localhost
StartPollers=10
StartPingers=4
StartDiscoverers=4
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=5
StartVMwareCollectors=5
VMwareFrequency=60
VMwareCacheSize=8M

8.再修改zabbix web目录下的配置文件

vim/var/www/html/zabbix3.0.4/conf/zabbix.conf.PHP
<?PHP
//ZabbixGUIconfigurationfile.
global$DB;

$DB['TYPE']='MysqL';
$DB['SERVER']='localhost';
$DB['PORT']='0';
$DB['DATABASE']='zabbix';
$DB['USER']='zabbix';
$DB['PASSWORD']='zabbix.localhost';

//Schemaname.UsedforIBMDB2andPostgresql.
$DB['SCHEMA']='';

$ZBX_SERVER='localhost';
$ZBX_SERVER_PORT='10051';
$ZBX_SERVER_NAME='';

$IMAGE_FORMAT_DEFAULT=IMAGE_FORMAT_PNG;



QA:

1.zabbix乱码问题

a.数据库字符集问题,创建数据库时指定字符集

create database zabbix character set utf8;


b.未上传中文字体,或者未修改include/define.inc.PHP文件


c.编译PHP时携带有--enable-gd-jis-conv参数,如果带有这个参数,画图的时候出现

wKiom1fM4SmBRJkcAAJOxtHJDII525.png


2.PHP7安装memcache问题

gitclone
cdpecl-memcache
/usr/local/PHP7.0.10/bin/PHPize
./configure--with-PHP-config=/usr/local/PHP7.0.10/bin/PHP-config
make&&makeinstall
echo'extension="memcache.so"'>>/usr/local/PHP7.0.10/etc/PHP.ini
#检查PHP是否加载memcache模块
/usr/local/PHP7.0.10/bin/PHP-m|grepmemcache
#重启PHP-fpm服务以加载memcache模块
/etc/init.d/PHP-fpmrestart

猜你在找的CentOS相关文章