安装准备
环境说明
关闭防火墙、SELinux # 关闭iptables chkconfig iptables off # 关闭ipv6防火墙 chkconfig ip6tables off #关闭firewall systemctl stop firewalld.service systemctl disable firewalld.service # 关闭SELinux sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
同步所有机器时间
# 不同步会导致,登录认证无法通过
# root/sudo执行
ntpdate ntp.ubuntu.com
#参考https://www.cnblogs.com/koudaiyoutang/p/10723417.html
设置主机名,域名配置
# Server、Workstation、Nodes均要设置hostname、配置hosts
# 设置Chef Server
hostnamectl set-hostname node2
# 设置Workstation
hostnamectl set-hostname node3
# 设置Node
hostnamectl set-hostname node4
# 配置hosts
vim /etc/hosts
192.168.56.12 node2
192.168.56.13 node3
192.168.56.14 node4
下载源文件
# 创建目录 mkdir -p /chef/software cd /chef/software # Chef Server [最新稳定版12.17.33] wget https://packages.chef.io/files/stable/chef-server/12.17.33/el/7/chef-server-core-12.17.33-1.el7.x86_64.rpm # Chef Manage [最新稳定版2.5.16] wget https://packages.chef.io/files/stable/chef-manage/2.5.16/el/7/chef-manage-2.5.16-1.el7.x86_64.rpm # Chef Workstation [最新稳定版0.1.137] wget https://packages.chef.io/files/stable/chef-workstation/0.1.137/el/7/chef-workstation-0.1.137-1.el6.x86_64.rpm # Chef Client [最新稳定版14.2.0] wget https://packages.chef.io/files/stable/chef/14.2.0/el/7/chef-14.2.0-1.el7.x86_64.rpm
Chef Server安装
系统参数调整 #内核参数调整 vi /etc/sysctl.conf # 物理内存使用90%再使用swap vm.swappiness = 10 # 1 表示开启重用,允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭 net.ipv4.tcp_tw_reuse = 1 # 1 表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭 net.ipv4.tcp_tw_recycle = 1 # 定义了系统中每一个端口最大的监听队列的长度, 对于一个经常处理新连接的高负载web服务环境,默认128太低 net.core.somaxconn = 2048 # 表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间 net.ipv4.tcp_fin_timeout = 30 # 该参数决定了, 每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目,不要设置过大 net.core.netdev_max_backlog = 8096 # 控制分配内存行为,不允许overcommit vm.overcommit_memory= 2 # 由于系统物理内存和swap内存都为4G vm.overcommit_radio=0 # (semmsl semmns semopm semmni) # semmsl:每个信号量set中信号量最大个数; # semmns:linux系统中信号量最大个数; # semopm:semop系统调用允许的信号量最大个数设置, # 设置成和semmsl一样即可; # semmni:linux系统信号量set最大个数; kernel.sem = 500 512000 500 1024 # 生效 sysctl -p # 关闭允许hugepage可以动态分配 echo never> /sys/kernel/mm/transparent_hugepage/enabled # 资源参数调整 # 查看资源参数命令:ulimit -a #1、open files 调整为65535 ulimit -n 65535 #2、max user processes 调整为 65535 ulimit -u 65535
安装
# 1.安装Chef Server rpm -ivh chef-server-core-12.17.33-1.el7.x86_64.rpm # 2.配置server chef-server-ctl reconfigure # 配置成功信息如下 # Starting Chef Client, version 12.21.31 #resolving cookbooks for run list: ["private-chef::default"] #Synchronizing Cookbooks: # - private-chef (0.1.1) # - openssl (8.1.2) # - runit (4.0.4) # - packagecloud (0.3.0) # - yum-epel (2.1.2) # - compat_resource (12.19.1) # - enterprise (0.11.0) # <...省略若干信息...> # Chef Client finished, 78/580 resources updated in 57 seconds # Chef Server Reconfigured! # 3.安装管理控制台 chef-server-ctl install chef-manage --path /chef/software/chef-manage-2.5.16-1.el7.x86_64.rpm 报错 & rpm -ivh chef-manage-2.5.16-1.el7.x86_64.rpm # 4.重新配置server chef-server-ctl reconfigure # 5.配置manage # 先按任意键继续再按q键然后输入yes chef-manage-ctl reconfigure # 6.创建用户 # 语法:chef-server-ctl user-create USER_NAME FIRST_NAME LAST_NAME EMAIL 'PASSWORD' --filename FILE_NAME chef-server-ctl user-create hogan Yu hogan 1660111465@163.com 'hogan@123' --filename /etc/chef/hogan.pem # 7.进入Manage创建组织 # 浏览器输入 https://192.168.56.12 # 创建组织:Admin 简称 :Admin
Chef Workstation安装
# 1.安装 cd /chef/software rpm -ivh chef-workstation-0.1.137-1.el6.x86_64.rpm # 2.验证安装 chef verify # 3.配置系统默认ruby echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile source ~/.bash_profile which ruby # 输入一下信息说明安装成功 # /opt/chef-workstation/embedded/bin/ruby # 4.下载Starter Kit # 浏览器输入https://192.168.56.12/organizations/Admin # 依次点击: "选择top一栏的设置按钮" -> "Starter Kit" -> "Download Starter Kit" # 5.上传chef-starter.zip # 上传 chef-starter.zip 至 /opt/chef-data 目录 cd /opt/chef-data unzip chef-starter.zip cd chef-repo/ # 6.验证安装 knife ssl fetch knife ssl check knife node list
Chef Client安装
# 1.安装 rpm -ivh chef-14.2.0-1.el7.x86_64.rpm # 2.校验 chef-client -v # 输出 Chef: 14.2.0 表示安装成功 # 3.登录Workstation机器,创建新节点(即在目标主机安装 Chef Client 与 Chef Server 相关联) knife bootstrap 192.168.56.14 --ssh-user root --ssh-password root@123 --node-name node4 # 4.登录Server查看节点详情 # https://192.168.56.12 (用户/密码:hogan/hogan@123)