您现在的位置是:网站首页> 编程资料编程资料
CentOS 6.3下安装部署CHEF环境教程_RedHat/Centos_操作系统_
2024-03-03
283人已围观
简介 CentOS 6.3下安装部署CHEF环境教程_RedHat/Centos_操作系统_
一.前言:
初识Chef,我们可以先了解一下DevOps运动http://zh.wikipedia.org/wiki/DevOps,简单点说,就是传统的软件组织将开发、IT运营和质量保障设为各自分离的部门,而DevOps运动的出现是由于软件行业日益清晰地认识到:为了按时交付软件产品和服务,开发和运营工作必须紧密合作。
所以Chef简单点说,就是DevOps运动中的一项重要工具成员,是一个同时面向开发与运维的集中管理工具。
就服务器的集中管理工具而言,知名度与Chef平分天下的是叫“Puppet”的工具,它们是OSS知名度排名最前的2个。
想像一下我们现在需要搭建一台MySQL Database Slave服务器,安装过程我们手动操作了没过多久,又需要第二台,这时候我们会想,如果之后安装第一台的时候把操作过程执行的命令写成脚本,现在安装第二台,运行一下脚本就行了,节约时间而且不容易出错。
Chef就相当于这样的一个脚本管理工具,但功能要强大得多,可定制性强,Chef将脚本命令代码化,定制时只需要修改代码,安装的过程就是执行代码的过程。打个比方,Chef就像一个制作玩具的工厂,它可以把一些原材料做成漂亮的玩具,它有一些模板,你把原材料放进去,选择一个模板(比如怪物史莱克),它就会制造出这个玩具,服务器的配置也是这样,一台还没有配置的服务器,你给它指定一个模板(role或recipe),Chef就会把它配置成你想要的线上服务器。
Chef使用服务器—客户端模式管理所有需要配置的机器,使用Chef涉及至少三台机器:
一台开发机器(Workstation),在上面编写大餐的做法;
一台Chef服务器(server),管理所有要配置的Chef客户端,给它们下发配置信息;
多台Chef客户端(Node),就是我将要烹调出的大餐。
操作系统:CentOS-6.3-x86-64
CHEF: chef-server-11.0.12-1.el6.x86_64
Server : 10.107.91.251 (chef.example.com)
Workstation: 10.107.91.251 (chef.example.com)
node: 10.107.91.252 (node1.example.com)
二.安装前的准备:(chef.example.com,node1.example.com)
1.关闭iptables
# service iptables stop
2.关闭SELINUX
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------
3.同步时间(重要)
# ntpdate asia.pool.ntp.org
# hwclock -w
4.安装ruby环境:
详见: https://www.jb51.net/article/54981.htm
三.chef-server安装:(chef.example.com)
1.下载chef-server安装包
进入页面http://www.opscode.com/chef/install,点击Chef Server标签,选择要下载的版本
或在终端下用以下命令下载11.0.12版本:
# wget -c --no-check-certificate
https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm
2.安装chef-server
终端内进入chef-server软件包所在目录,执行以下命令:
# rpm -ivh chef-server-11.0.12-1.el6.x86_64.rpm
注:请使用下载的软件包名称替换上面命令中的软件包名称.
3.修改本地FQDN名:
1).首先修改主机的hostname
# vi /etc/sysconfig/network
———————-———————-———————-———————-
HOSTNAME=chef.example.com
———————-———————-———————-———————-
2).修改本地host,添加server与node的FNDN
# echo "10.107.91.251 chef.example.com" >> /etc/hosts
# echo "10.107.91.252 node1.example.com" >> /etc/hosts
重启系统. 登录后验证:
# hostname -f
———————-———————-———————-———————-
chef.example.com
———————-———————-———————-———————-
3.配置chef-server
执行以下命令配置chef-server
# chef-server-ctl reconfigure
注:chef-server 10.x版本默认监听4000端口,chef-server 11.x监听443端口
SO若线上开启防火墙,需执行以下命令防火墙开启443端口
# iptables -I INPUT -p tcp --dport 443 -j ACCEPT
# service iptables save
现在浏览器打开https://10.107.91.251
输入:
username: admin
password: p@ssw0rd1
即可访问chef-server web页面.
四.chef-workstation安装:(chef.example.com)
1.安装chef-Client
进入页面http://www.opscode.com/chef/install,点击Chef Client标签,选择要下载的版本.
本例使用11.12.4-1版本:
# wget -c --no-check-certificate https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm
# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm
2.安装配置git
1).yum安装git:
# yum -y install git
2).进入root主目录,git克隆chef repository
# cd ~
# git clone git://github.com/opscode/chef-repo.git
————————————————————————————————————————————————————————————
Initialized empty Git repository in /root/chef-repo/.git/
remote: Reusing existing pack: 223, done.
remote: Total 223 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
Resolving deltas: 100% (57/57), done.
————————————————————————————————————————————————————————————
2.配置chef-workstation
运行命令 knife configure -i ,配置过程如下所示(只需填写chef repository一项:/root/chef-repo,其他项使用默认值):
# knife configure --initial
————————————————————————————————————————————————————————————
WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [https://chef.example.com:443]
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
Please enter the path to a chef repository (or leave blank): /root/chef-repo
Creating initial API user...
Please enter a password for the new user: 123456
注:这里输入API user密码(后面要使用)
Created user[root]
Configuration file written to /root/.chef/knife.rb
————————————————————————————————————————————————————————————
注: 没有出现Please enter a name for the new user: [root] 检查chef-server的443端口是否可以访问.
五.chef-workstation与chef-server不在同一服务器上的配置方法
(本例server与workstation在同一服务器,如无特殊需可略过这部分)
1.将chef-server的域名解析添加至chef-workstation的hosts文件
# echo "10.107.91.251 chef.example.com" >>/etc/hosts
2.在chef-workstation先创建/root/.chef目录,并将chef服务器上的/etc/chef-server/admin.pem和/etc/chef-server/chef-validator.pem文件拷贝到此目录
# mkdir ~/.chef
# scp chef.example.com:/etc/chef-server/admin.pem ~/.chef
# scp chef.example.com:/etc/chef-server/chef-validator.pem ~/.chef
3.执行knife configure -i命令进行初始化, 然后删除~/.chef/admin.pem
# knife configure --initial
# rm ~/.chef/admin.pem
4.knife configure配置过程:
1).server URL修改为chef服务器的地址https://chef.example.com:443,
2).admin's private key路径改为/root/.chef/admin.pem
3).validation key路径改为/root/.chef/chef-validation.pem
4).chef repository地址输入/root/chef-repo,其余项保持默认值.
# knife configure --initial
————————————————————————————————————————————————————————————
Overwrite /root/.chef/knife.rb? (Y/N) Y
Please enter the chef server URL: [https://workstation:443] https://chef.example.com:443
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /root/.chef/admin.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-valid
相关内容
- 简单几步让CentOS时间同步的方法_RedHat/Centos_操作系统_
- 红帽企业版更新 Red Hat发布RHEL 7.1下载_RedHat/Centos_操作系统_
- centos时间不同步的解决方法(centos时间同步)_RedHat/Centos_操作系统_
- CentOS使用MPlayer有图像无声音的解决方法_RedHat/Centos_操作系统_
- CentOS系统下安装scikit-learn的方法_RedHat/Centos_操作系统_
- CentOS如何安装系统监控工具Monitorix_RedHat/Centos_操作系统_
- CentOS挂载lvm分区重名问题的解决方法_RedHat/Centos_操作系统_
- Centos 6.4 64位版命令行下设置无线网卡教程_RedHat/Centos_操作系统_
- CentOS 7 网络配置方法_RedHat/Centos_操作系统_
- 剑网3五毒门派跟宠孔雀任务怎么做_五毒门派孔雀获得攻略(推荐)_网络游戏_游戏攻略_
点击排行
本栏推荐
