如何为 Chef 添加 Windows 节点

如何为 Chef 添加 Windows 节点

我有 3 台服务器

遵循 chefmaster 和 chefworkstation 的指南

https://www.itzgeek.com/how-tos/linux/centos-how-tos/setup-chef-12-centos-7-rhel-7.html

chefmaster 192.168.1.200 Centos7

chefworkstation 192.168.1.200 Centos7

chefnode 192.168.1.210 窗口服务器 2016

我已经在服务器上设置了具有管理员访问权限的 Windows 用户。

用户:chefUSER

我已经设置了 chefmaster 并配置了运行 chef 13.1.13

我已经设置并配置了 chefworkstation 运行 chefdk-0.19.6-1.el7.x86_64

谷歌搜索似乎只能找到如何在 Windows 上安装 Chef 服务器的方法。我正在尝试安装客户端以使其成为一个节点。

我努力了:

knife bootstrap -o winrm 192.168.1.210 -u chefUSER -P 密码

[root@chefworkstation .chef]# chef -v
ChefDK version: 4.6.35
Chef Infra Client version: 15.5.17
Chef InSpec version: 4.18.39
Test Kitchen version: 2.3.4
Foodcritic version: 16.2.0
Cookstyle version: 5.13.7


[root@chefworkstation .chef]# knife bootstrap -o winrm  192.168.1.210 -u chefUSER -P PASSWORD -N winnode1 -VV
INFO: Using configuration from /root/chef-repo/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at /etc/chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at /etc/chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
Connecting to 192.168.1.210
DEBUG: winrm-fs requested, loading WinRM::FS gem (~> 1.0)
DEBUG: WinRM::FS previously loaded
DEBUG: [WinRM] @192.168.1.210<{:transport=>:negotiate, :disable_sspi=>false, :basic_auth_only=>false, :endpoint=>"http://192.168.1.210:5985/wsman", :user=>"administrator", :password=>"<hidden>", :no_ssl_peer_verification=>false, :realm=>nil, :service=>nil, :ca_trust_file=>nil, :ssl_peer_fingerprint=>nil}> (Write-Host '[WinRM] Established
')
DEBUG: [WinRM] opening remote shell on http://192.168.1.210:5985/wsman
DEBUG: [WinRM] Endpoint doesn't support config request for MaxEnvelopsizekb
DEBUG: [WinRM] opening remote shell on http://192.168.1.210:5985/wsman
DEBUG: [WinRM] Endpoint doesn't support config request for MaxEnvelopsizekb

从源头来看

./lib/ruby/gems/2.6.0/gems/winrm-2.3.3/lib/winrm/shells/power_shell.rb

  # calculate the maimum fragment size so that they will be as large as possible yet
  # no greater than the max_envelope_size_kb on the end point. To calculate this
  # threshold, we:
  # - determine the maximum number of bytes accepted on the endpoint
  # - subtract the non-fragment characters in the SOAP envelope
  # - determine the number of bytes that could be base64 encded to the above length
  # - subtract the fragment header bytes (ids, length, etc)

  def max_envelope_size_kb
    @max_envelope_size_kb ||= begin
      config_msg = WinRM::WSMV::Configuration.new(connection_opts)
      msg = config_msg.build
      resp_doc = transport.send_request(msg)
      REXML::XPath.first(resp_doc, "//*[local-name() = 'MaxEnvelopeSizekb']").text.to_i
    ensure
      logger.debug("[WinRM] Endpoint doesn't support config request for MaxEnvelopsizekb")
    end
    # rubocop:enable Layout/RescueEnsureAlignment
  end

从这里我改变了我的 winrm 中的几个设置,但似乎没有什么区别。

PS C:\Windows\system32> winrm get winrm/config
Config
    MaxEnvelopeSizekb = 500
    MaxTimeoutms = 60000
    MaxBatchItems = 32000
    MaxProviderRequests = 4294967295
    Client
        NetworkDelayms = 5000
        URLPrefix = wsman
        AllowUnencrypted = true
        Auth
            Basic = true
            Digest = true
            Kerberos = true
            Negotiate = true
            Certificate = true
            CredSSP = false
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        TrustedHosts
    Service
        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;
        MaxConcurrentOperations = 4294967295
        MaxConcurrentOperationsPerUser = 1500
        EnumerationTimeoutms = 240000
        MaxConnections = 300
        MaxPacketRetrievalTimeSeconds = 120
        AllowUnencrypted = true
        Auth
            Basic = true
            Kerberos = true
            Negotiate = true
            Certificate = false
            CredSSP = false
            CbtHardeningLevel = Relaxed
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        IPv4Filter = *
        IPv6Filter = *
        EnableCompatibilityHttpListener = true
        EnableCompatibilityHttpsListener = false
        CertificateThumbprint
        AllowRemoteAccess = true
    Winrs
        AllowRemoteShellAccess = true
        IdleTimeout = 7200000
        MaxConcurrentUsers = 2147483647
        MaxShellRunTime = 2147483647
        MaxProcessesPerShell = 2147483647
        MaxMemoryPerShellMB = 2147483647
        MaxShellsPerUser = 2147483647

答案1

大部分内容取自https://www.itzgeek.com/how-tos/linux/centos-how-tos/setup-chef-12-centos-7-rhel-7.html大约 90% 是正确的,不起作用的部分可能是因为该页面引用了旧版本的 chef

3台服务器

Centos 7 - 192.168.1.200 chefmaster.local chefmaster

Centos 7 - 192.168.1.201 chefworkstation.local工作站

Windows Server 2016 数据中心(桌面体验) - 192.168.1.210 winsrv2016n1.local winsrv2016n1

配置 chefmaster 服务器:

cat /etc/hosts

192.168.1.200  chefmaster.local  chefmaster
192.168.1.201  chefworkstation.local  chefworkstation
192.168.1.210  winsrv2016n1.local winsrv2016n1

关闭 selinux-不确定是否需要。

sed -i 's/=enforcing/=disabled/g' /etc/selinux/config

更新主机名

sed -i "1s/.*/chefmaster.local/" /etc/hostname
hostnamectl set-hostname chefmaster.local

如果需要,更新服务器

yum update -y

重启服务器

reboot now

安装所需内容

yum -y install wget vim

安装 chef infa 服务器

wget https://packages.chef.io/files/stable/chef-server/13.1.13/el/7/chef-server-core-13.1.13-1.el7.x86_64.rpm
rpm -ivh chef-server-core-*.rpm
chef-server-ctl reconfigure
chef-server-ctl status

创建管理员用户:

例子:

chef-server-ctl user-create USER_NAME FIRST_NAME LAST_NAME EMAIL 'PASSWORD' -f PATH_FILE_NAME

我使用的方法:

chef-server-ctl user-create chefadmin chef admin [email protected] 'PASSWORD' -f /etc/chef/chefadmin.pem

创建组织:

例子:

chef-server-ctl org-create short_name 'full_organization_name' --association_user user_name --filename ORGANIZATION-validator.pem

我使用的方法:

chef-server-ctl org-create Myorgname "Myorg Name" --association_user chefadmin -f /etc/chef/Myorgname-validator.pem

打开防火墙:

firewall-cmd --permanent --zone public --add-service http
firewall-cmd --permanent --zone public --add-service https
firewall-cmd --reload

安装管理控制台:

chef-server-ctl install chef-manage
chef-server-ctl reconfigure
chef-manage-ctl reconfigure

==============================================================

配置 chefworkstation 服务器:

cat /etc/hosts

192.168.1.200  chefmaster.local  chefmaster
192.168.1.201  chefworkstation.local  chefworkstation
192.168.1.210  winsrv2016n1.local winsrv2016n1

关闭 selinux-不确定是否需要。

sed -i 's/=enforcing/=disabled/g' /etc/selinux/config

更新主机名

sed -i "1s/.*/chefworkstation.local/" /etc/hostname
hostnamectl set-hostname chefworkstation.local

如果需要,更新服务器

yum update -y

重启服务器

reboot now

安装 chefdk

wget https://packages.chef.io/files/stable/chefdk/4.6.35/el/7/chefdk-4.6.35-1.el7.x86_64.rpm
rpm -ivh chefdk-*.rpm
chef verify

验证 Ruby:

which ruby
echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
. ~/.bash_profile
which ruby

验证 Ruby 输出应如下所示:

/opt/chefdk/embedded/bin/ruby

安装并配置 git

yum -y install git
cd ~
chef generate repo chef-repo
ls -al ~/chef-repo/
git config --global user.name "chefadmin"
git config --global user.email "[email protected]"
cd ~/chef-repo/
git init
mkdir -p ~/chef-repo/.chef
echo '.chef' >> ~/chef-repo/.gitignore
cd ~/chef-repo/
git add .
git commit -m "initial commit"
git status

复制在配置 chefmaster 服务器部分中创建的 pem 文件

scp -pr root@chefmaster:/etc/chef/chefadmin.pem ~/chef-repo/.chef/
scp -pr root@chefmaster:/etc/chef/anthonyfornito-validator.pem ~/chef-repo/.chef/

创建刀文件:

vi ~/chef-repo/.chef/knife.rb

knife.rb 内容

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "chefadmin"
client_key               "#{current_dir}/chefadmin.pem"
validation_client_name   "Myorgname-validator"
validation_key           "#{current_dir}/Myorgname-validator.pem"
chef_server_url          "https://chefmaster.local/organizations/Myorgname"
syntax_check_cache_path  "#{ENV['HOME']}/.chef/syntaxcache"
cookbook_path            ["#{current_dir}/../cookbooks"]

检查 SSL 连接:

knife client list

可能会看到 SSL 错误

运行 ssl check 看看缺少什么

knife ssl check
.....
* ssl_ca_path: nil
* ssl_ca_file: nil
----

获取 SSL

knife ssl fetch

现在重新检查客户列表:

knife client list

您应该看到:

Myorgname-validator

===================================================

配置Window Server 2016服务器:

启用对端口 5985 的访问

从高级安全 Windows 防火墙:

单击“入站规则”

按本地端口对列表进行排序

找到“Windows 远程管理(HTTP-In)”规则(共有 2 条)

由于我没有使用域名,所以我所要做的就是配置公共

右键单击规则

选择属性

单击范围选项卡

将远程 IP 地址从以下位置更改:

这些 IP 地址:

到:

任何 IP 地址

在此处输入图片描述

使用 powershell 管理员运行以下命令

winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

===================================================

在 chefworkstation 服务器上运行以下命令来添加 windows server 2016 客户端。

例子:

knife bootstrap -o winrm CLIENTHOSTNAME -u ADMINWINUSER -P ADMINPASSWORD -VV

我使用的方法:

knife bootstrap -o winrm winsrv2016n1 -u Administrator -P PASSWORD -VV

这需要一些时间,但大约 20 分钟后它就会被添加为管理控制台下的客户端。

请记住,有一些主要的安全漏洞需要修复,但这应该可以帮助任何人开始

在此处输入图片描述

答案2

这是一个非常好的有关 Chef 和 Windows 的故障排除指南

TL;DR 基本上是 3 个步骤的列表:

  1. 在 Windows 节点中启用 WinRM,可以使用Enable-PSRemotingwinrm quickconfig

  2. 使用以下方法验证防火墙netsh advfirewall firewall add rule name=WinRM-HTTP" dir=in localport=5985 protocol=TCP action=allow

  3. 运行这些命令(仅用于测试,不用于生产):

    winrm set winrm/config/client/auth '@{Basic="true"}'
    winrm set winrm/config/service/auth '@{Basic="true"}'
    winrm set winrm/config/service '@{AllowUnencrypted="true"}'

常见原因:

  1. Winrm 服务未在远程计算机上运行
  2. 远程计算机上的防火墙拒绝连接
  3. 代理服务器阻碍了
  4. HTTPS 连接的 SSL 配置不正确

阅读上面链接的指南,以获得更深入的理解和额外的步骤。

相关内容