Fix for use of PHP-FPM instead of mod_php

Change-Id: Id9112adee54d093a36ebdcbe04cefcb32cbe0034
This commit is contained in:
Olivier Bourdon
2016-03-22 13:03:24 +01:00
parent 3c2e7e3587
commit 72a190d1d7
3 changed files with 171 additions and 52 deletions

View File

@@ -17,6 +17,23 @@ class plugin_zabbix::frontend {
include plugin_zabbix::params
$cgi_activation_str = sprintf('%s\n%s\n%s\n%s\n%s%s\n%s\n',
'<IfModule mod_fastcgi.c>',
' AddHandler fastcgi-php5-fpm .php php phar',
' Action fastcgi-php5-fpm /fastcgi-php5-fpm virtual',
" Alias /fastcgi-php5-fpm ${plugin_zabbix::params::zabbix_document_root}/fastcgi-php5-fpm",
" FastCgiExternalServer ${plugin_zabbix::params::zabbix_document_root}/fastcgi-php5-fpm",
' -host 127.0.0.1:9000 -idle-timeout 900 -pass-header Authorization -pass-header Range',
'</IfModule>')
$cgi_exec_str = sprintf('%s\n%s\n%s\n%s\n%s\n%s\n',
' <IfModule authz_core_module>',
' # Only when redirected internally by FastCGI.',
' Require env REDIRECT_STATUS',
' Options +ExecCGI',
' </IfModule>',
' Require all granted')
service { $plugin_zabbix::params::frontend_service:
ensure => 'running',
enable => true,
@@ -24,14 +41,36 @@ class plugin_zabbix::frontend {
hasrestart => true,
}
service { $plugin_zabbix::params::php_fpm_service:
ensure => 'running',
enable => true,
hasstatus => true,
hasrestart => true,
}
package { $plugin_zabbix::params::frontend_pkg:
ensure => present,
require => [
File['/etc/dbconfig-common/zabbix-server-mysql.conf'],
Package[$plugin_zabbix::params::php_mysql_pkg]
Package[$plugin_zabbix::params::php_fpm_pkg],
Package[$plugin_zabbix::params::php_mysql_pkg],
Package[$plugin_zabbix::params::apache_fcgi_pkg]
],
}
package { $plugin_zabbix::params::php_common_pkg:
ensure => present
}
package { $plugin_zabbix::params::php_fpm_pkg:
ensure => present,
require => Package[$plugin_zabbix::params::php_common_pkg],
}
package { $plugin_zabbix::params::apache_fcgi_pkg:
ensure => present
}
package { $plugin_zabbix::params::php_mysql_pkg:
ensure => present
}
@@ -43,31 +82,9 @@ class plugin_zabbix::frontend {
require => Package[$plugin_zabbix::params::frontend_pkg],
}
file_line { 'php timezone':
path => $plugin_zabbix::params::frontend_service_config,
line => ' php_value date.timezone UTC',
match => 'php_value date.timezone',
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
file_line { 'php memory_limit':
path => $plugin_zabbix::params::frontend_service_config,
line => ' php_value memory_limit 256M',
match => 'php_value memory_limit',
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
file_line { 'set expose_php to off':
path => $plugin_zabbix::params::php_config,
match => 'expose_php =',
line => 'expose_php = Off',
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
# disable worker MPM, use prefork MPM which is required by mod_php:
# do not use prefork as it is incompatible with MOS 8.0 / Liberty
# So need to enable a few more Apache modules to work with PHP-FPM
# and mod worker
case $::osfamily {
'RedHat': {
# default line: "HTTPD=/usr/sbin/httpd.worker"
@@ -83,27 +100,63 @@ class plugin_zabbix::frontend {
}
}
'Debian': {
exec { 'disable-apache-worker':
command => 'a2dismod worker',
exec { 'enable-apache-actions':
command => 'a2enmod actions',
path => ['/usr/sbin', '/usr/bin', '/sbin', '/bin'],
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
exec { 'enable-apache-prefork':
command => 'a2enmod mpm_prefork',
exec { 'enable-apache-rewrite':
command => 'a2enmod rewrite',
path => ['/usr/sbin', '/usr/bin', '/sbin', '/bin'],
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
exec { 'enable-apache-php5':
command => 'a2enmod php5',
exec { 'enable-apache-expires':
command => 'a2enmod expires',
path => ['/usr/sbin', '/usr/bin', '/sbin', '/bin'],
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
exec { 'enable-apache-fastcgi':
command => 'a2enmod fastcgi',
path => ['/usr/sbin', '/usr/bin', '/sbin', '/bin'],
notify => Service[$plugin_zabbix::params::frontend_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
file_line { 'set php_fpm local listener':
path => $plugin_zabbix::params::php_fpm_config,
match => 'listen =',
line => 'listen = 127.0.0.1:9000',
require => Package[$plugin_zabbix::params::php_fpm_pkg],
}
file_line { 'php timezone':
ensure => present,
path => $plugin_zabbix::params::php_fpm_config,
line => 'php_value[date.timezone] = UTC',
require => File_line['set php_fpm local listener'],
}
file_line { 'php memory_limit':
ensure => present,
path => $plugin_zabbix::params::php_fpm_config,
line => 'php_value[memory_limit] = 256M',
notify => Service[$plugin_zabbix::params::php_fpm_service],
require => File_line['php timezone'],
}
file_line { 'set expose_php to off':
path => $plugin_zabbix::params::php_config,
match => 'expose_php =',
line => 'expose_php = Off',
notify => Service[$plugin_zabbix::params::php_fpm_service],
require => Package[$plugin_zabbix::params::frontend_pkg],
}
}
default: {}
}
@@ -118,12 +171,68 @@ class plugin_zabbix::frontend {
provider => 'shell',
before => Package[$plugin_zabbix::params::frontend_pkg],
}
file { '/etc/apache2/conf.d/zabbix.conf':
ensure => link,
target => $plugin_zabbix::params::frontend_service_config,
notify => Service[$plugin_zabbix::params::frontend_service],
# Do not modify the file contained by the package
# Make a copy to work on but do not put it right away in the
# Apache configuration directory else it will produce errors
file { $plugin_zabbix::params::frontend_service_tmp_cfg:
ensure => present,
source => $plugin_zabbix::params::frontend_service_template,
require => Package[$plugin_zabbix::params::frontend_pkg],
}
file_line { 'remove php_value lines':
ensure => absent,
path => $plugin_zabbix::params::frontend_service_tmp_cfg,
line => 'php_value',
match => 'php_value .*',
replace => false,
match_for_absence => true,
multiple => true,
require => File[$plugin_zabbix::params::frontend_service_tmp_cfg],
}
# Need to escape slashes in path
$p = regsubst($plugin_zabbix::params::zabbix_document_root, '/', '\\/', 'G')
# Adding FastCGI directive before Zabbix Directory directive
$cmd1 = "sed -i -e '/<Directory \"${p}\">/i\\${cgi_activation_str}'"
exec { 'configure zabbix-UI-1':
command => "${cmd1} ${plugin_zabbix::params::frontend_service_tmp_cfg}",
provider => 'shell',
require => File_line['remove php_value lines'],
}
# Adding PHP handling directive within Zabbix Directory directive
$cmd2 = "sed -i -e '/<Directory \"${p}\">/a\\${cgi_exec_str}'"
exec { 'configure zabbix-UI-2':
command => "${cmd2} ${plugin_zabbix::params::frontend_service_tmp_cfg}",
provider => 'shell',
require => Exec['configure zabbix-UI-1'],
}
# Now that the file contents is correct, we can put this
# configuration into Apache
# Make a copy to work on but do not put it right away in the
# Apache configuration directory else it will produce errors
file { $plugin_zabbix::params::frontend_service_config:
ensure => present,
source => $plugin_zabbix::params::frontend_service_tmp_cfg,
notify => Service[$plugin_zabbix::params::frontend_service],
require => Exec['configure zabbix-UI-2'],
}
$cmd3 = sprintf('%s | %s | %s | %s >> %s',
"grep php_value ${plugin_zabbix::params::frontend_service_template}",
'sed -e "s/^\s*//"',
'egrep -v "^#|memory_limit"',
'awk \'{printf "%s[%s] = %s\n",$1,$2,$3}\'',
$plugin_zabbix::params::php_fpm_config)
exec { 'configure zabbix-UI-3':
command => $cmd3,
provider => 'shell',
notify => Service[$plugin_zabbix::params::php_fpm_service],
}
}
default: {}
}

View File

@@ -34,25 +34,33 @@ class plugin_zabbix::params {
case $::operatingsystem {
'Ubuntu', 'Debian': {
$agent_pkg = 'zabbix-agent'
$server_pkg = 'zabbix-server-mysql'
$frontend_pkg = 'zabbix-frontend-php'
$sender_pkg = 'zabbix-sender'
$get_pkg = 'zabbix-get'
$php_fpm_pkg = 'php5-fpm'
$php_fpm_config = '/etc/php5/fpm/pool.d/www.conf'
$php_fpm_service = 'php5-fpm'
$php_common_pkg = 'php5-common'
$apache_fcgi_pkg = 'libapache2-mod-fastcgi'
$agent_pkg = 'zabbix-agent'
$server_pkg = 'zabbix-server-mysql'
$frontend_pkg = 'zabbix-frontend-php'
$sender_pkg = 'zabbix-sender'
$get_pkg = 'zabbix-get'
$agent_service = 'zabbix-agent'
$server_service = 'zabbix-server'
$agent_service = 'zabbix-agent'
$server_service = 'zabbix-server'
$agent_log_file = "${zabbix_base_log_dir}/zabbix_agentd.log"
$server_log_file = "${zabbix_base_log_dir}/zabbix_server.log"
$agent_log_file = "${zabbix_base_log_dir}/zabbix_agentd.log"
$server_log_file = "${zabbix_base_log_dir}/zabbix_server.log"
$prepare_schema_cmd = 'cat /usr/share/zabbix-server-mysql/schema.sql /usr/share/zabbix-server-mysql/images.sql > /tmp/zabbix/schema.sql'
$prepare_schema_cmd = 'cat /usr/share/zabbix-server-mysql/schema.sql /usr/share/zabbix-server-mysql/images.sql > /tmp/zabbix/schema.sql'
$frontend_service = 'apache2'
$frontend_service_config = "${zabbix_base_conf_dir}/apache.conf"
$frontend_config = "${zabbix_base_conf_dir}/web/zabbix.conf.php"
$php_config = '/etc/php5/apache2/php.ini'
$php_mysql_pkg = 'php5-mysql'
$frontend_service = 'apache2'
$frontend_service_template = "${zabbix_base_conf_dir}/apache.conf"
$frontend_service_config = '/etc/apache2/conf.d/zabbix.conf'
$frontend_service_tmp_cfg = '/tmp/zabbix.conf'
$frontend_config = "${zabbix_base_conf_dir}/web/zabbix.conf.php"
$php_config = '/etc/php5/fpm/php.ini'
$php_mysql_pkg = 'php5-mysql'
$zabbix_document_root = '/usr/share/zabbix'
}
'CentOS', 'RedHat': {

View File

@@ -28,6 +28,8 @@ download deb http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix/zabbix-
http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix/zabbix-sender_2.4.4-1+trusty_amd64.deb \
http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix/zabbix-get_2.4.4-1+trusty_amd64.deb \
http://archive.ubuntu.com/ubuntu/pool/main/p/php5/php5-mysql_5.5.9+dfsg-1ubuntu4.14_amd64.deb \
http://archive.ubuntu.com/ubuntu/pool/main/p/php5/php5-common_5.5.9+dfsg-1ubuntu4.14_amd64.deb \
http://archive.ubuntu.com/ubuntu/pool/universe/p/php5/php5-fpm_5.5.9+dfsg-1ubuntu4.14_amd64.deb \
http://archive.ubuntu.com/ubuntu/pool/universe/n/net-snmp/libsnmp-perl_5.7.2~dfsg-8.1ubuntu3.1_amd64.deb \
http://archive.ubuntu.com/ubuntu/pool/universe/s/snmptt/snmptt_1.4-1_all.deb \
http://archive.ubuntu.com/ubuntu/pool/universe/libs/libsmi/smistrip_0.4.8+dfsg2-8ubuntu2_all.deb \