Configuring a Puppet Master Server with Passenger and Apache

本文介绍如何使用Passenger和Apache配置Puppet Master服务器,包括安装Apache和Passenger、配置Puppet应用、设置虚拟主机等内容。

Configuring a Puppet Master Server with Passenger and Apache

  1. What is Passenger?
    1. Relevant Pages in the Passenger Docs
  2. Install Apache and Passenger
    1. Install Apache 2
    2. Install Rack/Passenger
  3. Configure Puppet
  4. Configure Apache
    1. Global Configuration
    2. Install the Puppet Master Rack Application
    3. Create and Enable the Puppet Master Vhost
    4. Notes on PassengerHighPerformance
    5. Notes on DocumentRoot and PassengerAppRoot
    6. Notes on SSL Verification
  5. Start or Restart the Apache service

Puppet includes a basic Puppet master web server based on Ruby’s WEBrick library. (This is what Puppet uses if you run puppet master on the command line or use most puppetmasterinit scripts.)

You cannot use this default server for real-life loads, as it can’t handle concurrent connections; it is only suitable for small tests with ten nodes or fewer. You must configure a production quality web server before you start managing your nodes with Puppet.

Any Rack-based application server stack will work with a Puppet master, but if you don’t have any particular preference, you should use Passenger combined with Apache. This guide shows how to configure Puppet with this software.

What is Passenger?

Passenger (AKA mod_rails or mod_rack) is an Apache 2.x module which lets you run Rails or Rack applications inside a general purpose web server, like Apache httpd or nginx.

Relevant Pages in the Passenger Docs

Install Apache and Passenger

Make sure puppet master has been run at least once (or puppet agent, if this master is not the CA), so that all required SSL certificates are in place.

Install Apache 2

Debian/Ubuntu:

$ sudo apt-get install apache2 ruby1.8-dev rubygems
$ sudo a2enmod ssl
$ sudo a2enmod headers

RHEL/CentOS (needs the Puppet Labs repository enabled, or the EPEL repository):

$ sudo yum install httpd httpd-devel mod_ssl ruby-devel rubygems gcc

Install Rack/Passenger

$ sudo gem install rack passenger
$ sudo passenger-install-apache2-module

Configure Puppet

If you’re running Puppet 3.x, make sure the always_cache_features setting is set to true in the [master] (not [main]) section of puppet.conf. This improves performance.

In post-4.0 versions of Puppet, the example config.ru file hardcodes this setting to true.

Configure Apache

To configure Apache to run the Puppet master application, you must:

  • Install the Puppet master Rack application, by creating a directory for it and copying the config.ru file from the Puppet source.
  • Create a virtual host config file for the Puppet master application, and install/enable it.

Global Configuration

Keepalive Timeout

Make sure Apache’s KeepAliveTimeout setting is set to at least 5. (5 is the default value, but your global Apache config may have set a different value, in which case you’ll need to change it.)

Although this setting is valid at virtual host scope, the way Apache reads its value means it’s safer to set it globally.

Install the Puppet Master Rack Application

Your copy of Puppet includes a config.ru file, which tells Rack how to spawn Puppet master processes. To install this Rack application in a form Passenger can use, you’ll need to:

  • Create three directories for the application (a parent directory, a “public” directory, and a “tmp” directory)
  • Copy the ext/rack/config.ru file from the Puppet source code into the parent directory
  • Set the ownership of the config.ru file

Note: The chown step is important — the owner of this file is the user the Puppet master process will run under. This should usually be puppet, but may be different in your deployment.

Also, make sure the Apache user (which may vary by platform) can both read and traverse all three directories, can traverse all of its parent directories, and can write to the “tmp” directory.

These steps will look something like this:

$ sudo mkdir -p /usr/share/puppet/rack/puppetmasterd
$ sudo mkdir /usr/share/puppet/rack/puppetmasterd/public /usr/share/puppet/rack/puppetmasterd/tmp
$ sudo cp /usr/share/puppet/ext/rack/config.ru /usr/share/puppet/rack/puppetmasterd/
$ sudo chown puppet:puppet /usr/share/puppet/rack/puppetmasterd/config.ru

The location of the Puppet source will vary by OS, and the packages you installed with might have excluded the files from ext/. If so, you can download the config.ru file directly from GitHub.

Create and Enable the Puppet Master Vhost

See “Example Vhost Configuration” below for the contents of this vhost file. Note that the vhost’s DocumentRoot directive refers to the Rack application directory you created above.

Debian/Ubuntu:

See “Example Vhost Configuration” below for the contents of the puppetmaster file

$ sudo cp puppetmaster /etc/apache2/sites-available/
$ sudo a2ensite puppetmaster

RHEL/CentOS:

See “Example Vhost Configuration” below for the contents of the puppetmaster.conf file.

$ sudo cp puppetmaster.conf /etc/httpd/conf.d/
Example Vhost Configuration

This Apache Virtual Host configures the Puppet master on the default puppetmaster port (8140). You can also see a similar file at ext/rack/example-passenger-vhost.conf in the Puppet source.

Make sure you point the SSL-related settings to your actual SSL files; the example below uses Puppet 4’s ssldir, but Puppet 3 uses a different path, which can vary by OS.

# You'll need to adjust the paths in the Passenger config depending on which OS
# you're using, as well as the installed version of Passenger.

# Debian/Ubuntu:
#LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-4.0.x/ext/apache2/mod_passenger.so
#PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.x
#PassengerRuby /usr/bin/ruby1.8

# RHEL/CentOS:
#LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.x/ext/apache2/mod_passenger.so
#PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.x
#PassengerRuby /usr/bin/ruby

# And the passenger performance tuning settings:
# Set this to about 1.5 times the number of CPU cores in your master:
PassengerMaxPoolSize 12
# Recycle master processes after they service 1000 requests
PassengerMaxRequests 1000
# Stop processes if they sit idle for 10 minutes
PassengerPoolIdleTime 600

Listen 8140
<VirtualHost *:8140>
    # Make Apache hand off HTTP requests to Puppet earlier, at the cost of
    # interfering with mod_proxy, mod_rewrite, etc. See note below.
    PassengerHighPerformance On

    SSLEngine On

    # Only allow high security cryptography. Alter if needed for compatibility.
    SSLProtocol ALL -SSLv2 -SSLv3
    SSLCipherSuite EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA
    SSLHonorCipherOrder     on

    SSLCertificateFile      /etc/puppetlabs/puppet/ssl/certs/puppet-server.example.com.pem
    SSLCertificateKeyFile   /etc/puppetlabs/puppet/ssl/private_keys/puppet-server.example.pem
    SSLCertificateChainFile /etc/puppetlabs/puppet/ssl/ca/ca_crt.pem
    SSLCACertificateFile    /etc/puppetlabs/puppet/ssl/ca/ca_crt.pem
    SSLCARevocationFile     /etc/puppetlabs/puppet/ssl/ca/ca_crl.pem
    SSLCARevocationCheck 	chain
    SSLVerifyClient         optional
    SSLVerifyDepth          1
    SSLOptions              +StdEnvVars +ExportCertData

    # Apache 2.4 introduces the SSLCARevocationCheck directive and sets it to none
	# which effectively disables CRL checking. If you are using Apache 2.4+ you must
    # specify 'SSLCARevocationCheck chain' to actually use the CRL.

    # These request headers are used to pass the client certificate
    # authentication information on to the Puppet master process
    RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
    RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
    RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e

    DocumentRoot /usr/share/puppet/rack/puppetmasterd/public

    <Directory /usr/share/puppet/rack/puppetmasterd/>
      Options None
      AllowOverride None
      # Apply the right behavior depending on Apache version.
      <IfVersion < 2.4>
        Order allow,deny
        Allow from all
      </IfVersion>
      <IfVersion >= 2.4>
        Require all granted
      </IfVersion>
    </Directory>

    ErrorLog /var/log/httpd/puppet-server.example.com_ssl_error.log
    CustomLog /var/log/httpd/puppet-server.example.com_ssl_access.log combined
</VirtualHost>

If this Puppet master is not the certificate authority, you will need to use different paths to the CA certificate and CRL:

SSLCertificateChainFile /etc/puppetlabs/puppet/ssl/certs/ca.pem
SSLCACertificateFile    /etc/puppetlabs/puppet/ssl/certs/ca.pem
SSLCARevocationFile     /etc/puppetlabs/puppet/ssl/crl.pem

For additional details about enabling and configuring Passenger, see the Passenger install guide and the Apache version of the Passenger user’s guide.

Notes on PassengerHighPerformance

The example vhost config above sets PassengerHighPerformance On. This setting basically allows Passenger to shortcut some of Apache’s normal layers of request handling, so the Puppet application can respond earlier. Unfortunately, it can also interfere with other Apache modules, including important ones like mod_proxy,mod_rewrite, and mod_authz_core.

In the example, we’ve limited its effect by setting PassengerHighPerformance at the vhost scope, so it won’t interfere with any non-Puppet requests the Apache process is handling. You can also enable or disable it in a <Location> directive, which may be necessary if you’re proxying traffic to the Puppet CA in a multi-master setup.

Notes on DocumentRoot and PassengerAppRoot

Passenger usually uses Apache’s DocumentRoot directive to guess where to find its config.ru file — it assumes config.ru will be right beside the public directory.

This generally works fine, but some users have seen Passenger fail to guess. If Passenger fails to load the Puppet master app and is displaying a generic error message, our first suggestion is to double-check the directory permissions (remember the Apache user must be able to read and traverse all Puppet master application directories), but you can also try explicitly telling Passenger where to find the config.ru file with the PassengerAppRoot directive:

PassengerAppRoot /usr/share/puppet/rack/puppetmasterd

Notes on SSL Verification

When an agent node makes a request to the Puppet master, Apache’s mod_ssl performs the verification of its certificate, and the Puppet master application will trustmod_ssl’s judgment. The two systems communicate via environment variables — Apache must set two variables containing the client’s subject DN and its verification status, and the Puppet master must know which variables to check when it receives a request.

Puppet uses the ssl_client_header and ssl_client_verify_header settings to find these variables; the default values are HTTP_X_CLIENT_DN and HTTP_X_CLIENT_VERIFY, respectively.

In our example vhost config above, Apache uses the SSLOptions +StdEnvVars directive to make several SSL-related environment variables available; a full list of these variables is available here. It then uses these variables to construct severalRequestHeader set directives, which put the information into the X-Client-DN andX-Client-Verify HTTP headers. The common gateway interface (CGI) standard converts all HTTP headers to environment variables and munges their names (an HTTP_ prefix is added, dashes are converted to underscores, and all letters are uppercased), and Puppet uses these environment variables, which have become the default names we mentioned above (HTTP_X_CLIENT_DN and HTTP_X_CLIENT_VERIFY).

Alternately, you could leave off the RequestHeader directives and use theSSL_CLIENT_S_DN and SSL_CLIENT_VERIFY variables directly, but this is a less standard way to do it, is tied specifically to Apache and mod_ssl, and requires changing your puppet.conf.

Start or Restart the Apache service

Ensure that any WEBrick Puppet master process is stopped before starting the Apache service; only one can be bound to TCP port 8140.

Debian/Ubuntu:

$ sudo /etc/init.d/apache2 restart

RHEL/CentOS:

$ sudo /etc/init.d/httpd restart

If all works well, you’ll want to make sure the WEBrick service no longer starts on boot:

Debian/Ubuntu:

$ sudo update-rc.d -f puppetmaster remove

RHEL/CentOS:

$ sudo chkconfig puppetmaster off
$ sudo chkconfig httpd on
内容概要:本文通过一个典型的嵌入式开发困境——因供应链问题需紧急更换传感器芯片,引出使用C语言实现工厂模式来解决代码强耦合问题。文章首先介绍如何利用C语言的结构体和函数指针模拟面向对象中的“接口”概念,定义统一的传感器操作接口(Sensor_Ops),实现业务层与具体驱动的解耦。接着展示“青铜段位”的简单工厂模式,通过switch-case根据宏定义选择具体传感器实现,使更换芯片只需修改一行代码。进一步,文章引入“王者段位”的自动注册工厂模式,利用编译器的section特性,将各传感器驱动的操作集自动注册到指定内存段,工厂通过遍历该段自动发现所有可用传感器,真正实现了“对扩展开放,对修改关闭”的开闭原则。最后阐述了该模式在硬件模拟(Mock)、多版本兼容和团队协作方面的实战价值。; 适合人群:从事嵌入式系统开发,具备一定C语言基础和项目经验的工程师,特别是常面临硬件变更、多型号产品维护或团队协作开发的从业者。; 使用场景及目标:①当项目中存在同类外设(如传感器、显示屏、存储芯片)多种选型,需要灵活切换时;②希望实现硬件抽象,便于在无实物硬件时进行软件仿真和单元测试;③构建多硬件版本产品(如Pro/Lite版),用一套代码库支持不同配置;④促进团队分工协作,降低驱动开发与业务逻辑之间的依赖和冲突。; 阅读建议:此资源不仅提供了代码范例,更重要的是传达了一种解耦和模块化的设计思想。建议读者在理解基本原理后,动手实践,尝试在自己的项目中应用简单工厂模式,并逐步过渡到自动注册模式,同时思考如何将此思想推广到其他模块(如通信、存储等)的设计中。
内容概要:本文针对有源中点箝位(ANPC)三电平并网逆变器在复杂电网环境下的性能瓶颈,提出了一种融合双极性倍频脉宽调制(DPWMA)、正负序分离锁相技术与电网电压前馈控制的一体化高性能并网控制策略。通过深入分析ANPC三电平拓扑在开关损耗均衡性、中点电位稳定性及输出电能质量方面的固有优势,构建了高可靠性的硬件基础;在此之上,DPWMA调制策略有效提升了开关频率利用率,显著降低了输出电流谐波含量;正负序分离锁相环(SRF-PLL)精准提取电网正序分量,解决了电网不平衡工况下传统锁相技术存在的相位检测偏差与并网电流不对称问题;电网电压前馈控制则通过前馈补偿机制,提前抑制电网电压扰动对并网电流的直接影响,大幅增强了系统在电压骤升、骤降等动态工况下的响应速度与鲁棒性。研究通过Simulink搭建了完整的仿真模型,对稳态运行、电网不平衡及动态切换等多种工况进行了全面验证,结果表明该复合控制策略能显著提升并网电能质量、锁相精度与系统动态稳定性,适用于新能源发电、大功率工业变流等对并网性能要求严苛的应用场景。; 适合人群:具备电力电子与电力系统基础知识,从事新能源发电、微电网、大功率变流器、电能质量治理等相关领域研究的研发人员及高校研究生。; 使用场景及目标:①解决传统三电平逆变器在电网不平衡条件下锁相不准、电流畸变严重的问题;②提升并网逆变器在电压骤升/骤降等动态扰动工况下的响应速度、抗扰能力与并网稳定性;③为高性能、高可靠性的并网控制系统设计提供一套可复现、可验证的技术方案与完整的仿真模型参考。; 阅读建议:建议读者结合文中提供的Simulink仿真模型,按照“拓扑分析-控制策略设计-仿真验证”的逻辑主线,循序渐进地理解各模块的设计原理,重点钻研正负序分离锁相与电网电压前馈控制的实现细节,并通过设置不同的电网扰动工况进行仿真实验,对比分析控制效果,从而深入掌握多技术协同优化的内在机理与工程应用价值。
代码转载自:https://pan.quark.cn/s/679a7257f458 在Windows操作系统环境中,开发多线程程序是一项普遍存在的编程需求,其主要目的是为了达成不同任务的并行处理,从而优化程序的执行效能。在C++开发情境下,我们一般会借助WinAPI提供的`_beginthreadex`函数来进行线程的构建,此方法具备跨操作系统的兼容性,并且是C运行时库(CRT)所包含的一部分。本文将深入剖析如何运用`_beginthreadex`函数来构建多线程以及相关的技术要点。 首先,让我们明确`_beginthreadex`函数的基本操作方法。该函数需要接收若干个参数,包括一个指向安全属性的指针、初始堆栈的尺寸、一个线程执行函数的指针、传递给线程执行函数的参数、线程的创建标识以及一个存放线程标识符的指针。线程执行函数是新线程将要运行的代码的起始位置。下面给出一个基础的实例代码: ```cpp uintptr_t thread_id; HANDLE hThread = (HANDLE)_beginthreadex( NULL, // 指向安全属性的指针,通常设置为NULL 0, // 堆栈尺寸,若传入0则表示采用系统默认值 ThreadFunction, // 指向线程执行函数的指针 NULL, // 传递给线程执行函数的参数,可以根据需求自定义 CREATE_SUSPENDED, // 线程的创建标识,可以选择使用CREATE_SUSPENDED来使线程处于挂起状态 &thread_id // 用于接收线程标识符的指针 ); ``` 在此代码中,`ThreadFunction`代表用户自定义的函数,它将作为新线程执行的起始点。例如: ```cpp D...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值