运维自动化Chef-server及 chefworkstation安装教程

三台服务器分别对应IP和主机名

运维自动化Chef-server及 chefworkstation安装教程

chefserver服务器命令(软件下载地址https://downloads.chef.io/)

      rpm -ivh  chef-server-core-12.17.33-1.el7.x86_64

      chef-server-ctl reconfigure

      rpm -ivh chef-manage-2.5.15-1.el7.x86_64

     chef-manage-ctl reconfigure 先按任意键继续再按q键然后输入yes(很多人在这儿都会出现问题)

运维自动化Chef-server及 chefworkstation安装教程

创建登录用户

chef-server-ctl user-create pcdog hao yu [email protected] [email protected] --filename /usr/chef/pcdog.pem

(chef-server-ctl user-create wuf fei wu [email protected] [email protected] -f /root/wuf.pem)

然后登录https://chefserver_IP创建组织

运维自动化Chef-server及 chefworkstation安装教程

workstation节点操作(https://docs.chef.io/workstation.html)


     rpm -ivh  chefdk-3.0.36-1.el7.x86_64.rpm

        安装之后验证下

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

    source ~/.bash_profile

    which ruby

输出 /opt/chefdk/embedded/bin/ruby证明workstation安装完成

运维自动化Chef-server及 chefworkstation安装教程

安装好了之后,从chefserverIP网页下一个start kit主要需要这两个文件

运维自动化Chef-server及 chefworkstation安装教程

安装git

yum -y install git

cd ~

chef generate repo chef-repo

ls -al ~/chef-repo/

运维自动化Chef-server及 chefworkstation安装教程

git config --global user.name "admin"

git config --global user.email "[email protected]"

cd ~/chef-repo/ && git init

运维自动化Chef-server及 chefworkstation安装教程

mkdir -p ~/chef-repo/.chef

echo '.chef' >> ~/chef-repo/.gitignore

cd ~/chef-repo/ && git add . && git commit -m "initial commit"

git status

运维自动化Chef-server及 chefworkstation安装教程

cd  /root/chef-repo/.chef 然后rz(yum install -y lrzsz)上传pcdog.pem和knife.rb到此目录

运维自动化Chef-server及 chefworkstation安装教程

把证书从server端复制到workstation

运维自动化Chef-server及 chefworkstation安装教程

scp [email protected]:/var/opt/opscode/nginx/ca/chefserver.crt  ./trusted_certs/

再运行  knife ssl check成功

运维自动化Chef-server及 chefworkstation安装教程

运行knife client list 成功

运维自动化Chef-server及 chefworkstation安装教程

配置 Chef Client


用 knife 命令来创建一个新的节点,即在目标主机安装 Chef Client 与 Chef Server 相关联:

knife bootstrap chefworkstation -x root -P password -N chefworkstation

knife cookbook upload learn_chef_httpd

knife ssh 'name:chefworkstation' 'sudo chef-client' --ssh-user root --ssh-password 'gemhone2016' --attribute ipaddress

knife bootstrap chefworkstation --ssh-user root --ssh-password 'gemhone2016' --sudo --use-sudo-password --node-name chefworkstation --run-list 'recipe[learn_chef_httpd]' (加入节点并运行食谱)