knife sub command를 사용하는 방법에 대해 알아본다.
help 명령으로 보면 다음과 같은 sub command가 존재한다.
# knife -h
Available subcommands: (for details, knife SUB-COMMAND --help)
** BOOTSTRAP COMMANDS **
knife bootstrap FQDN (options)
** CLIENT COMMANDS **
knife client show CLIENT (options)
knife client delete CLIENT (options)
knife client reregister CLIENT (options)
크게 보면 다음과 같은 command를 사용할 수 있다.
- bootstrap
- client
- configure
- cookbook
- cookbook site
- data bag
- environment
- exec
- help
- index
- node
- recipe
- role
- search
- ssh
- status
- tag
'OSS(Open Source Software) > chef' 카테고리의 다른 글
chef 설치 (0) | 2014.04.14 |
---|---|
knife subcommand - configure (0) | 2014.04.10 |
knife sub commands - client (0) | 2014.04.10 |
cookbook 생성 (0) | 2014.04.10 |
chef client 설치 (0) | 2014.04.10 |
chef API를 사용하기 위해서는 chef client로 등록을 해야 한다.
노드를 생성하고 chef-client를 실행하기 위해서는 API client 권한이 필요하다. client와 server간에 인증은 key를 통해 하게 되는데, chef-server에서 client를 등록하면서 만들어진 client key를 배포하고, 이 key를 이용해서 등록하면 된다. client를 등록하는 방법으로 chef-validator로 등록하는 방법이 있다.
처음 chef-client가 실행되면 client는 먼저 client key 파일을 찾고, 없을 경우 validation.pem 파일을 이용해서 등록을 시도한다. validation.pem 파일은 chef-server에 /etc/chef/ 디렉토리에 있으며, validation.pem 파일을 이용해서 등록된 client는 일반 client로 등록된다.
client command
** CLIENT COMMANDS **
knife client show CLIENT (options)
knife client delete CLIENT (options)
knife client reregister CLIENT (options)
1. client 타입
client는 두 가지 타입이 있다.
- admin API client : 관리자 권한을 가지며, 읽기와 쓰기 권한 모두 가지고 있다.
- 일반 client : cookbook에 대한 읽기 권한만 갖고 있다. validation.pem을 통해서 등록된 client가 여기에 해당한다.
- chef-client(일반 client) : /etc/chef/client.pem으로 복사한다.
- knife(admin API client) : ~/.chef/client_name.pem 파일로 복사
- syntax
- 예제
- syntax
- 예제
4. list
클라이언트 목록 보기
5. reregister
새로운 RSA key pair를 생성한다.
# knife client reregister CLIENT (options)
# knife client reregister manage - f
6. show
API client의 상세정보를 보기
# knife client show CLIENT (options)
7. edit
client 정보를 수정
# knife client edit CLIENT (options)
# knife client edit manage
'OSS(Open Source Software) > chef' 카테고리의 다른 글
knife subcommand - configure (0) | 2014.04.10 |
---|---|
knife sub commands (0) | 2014.04.10 |
cookbook 생성 (0) | 2014.04.10 |
chef client 설치 (0) | 2014.04.10 |
chef workstation 설정 (0) | 2014.04.10 |
helloworld 라는 이름의 cookbook을 만들고 cookbook을 이용해서 /tmp 디렉토리에 helloworld.txt 파일을 만들어 본다.
cookbook을 만드는 방법은 chef server or chef workstation에서 knife를 이용해 만들 수 있다.
1. cookbook 생성
다음과 같은 명령을 이용해 cookbook을 생성 할 수 있다.
# knife cookbook create HelloWorld
** Creating cookbook HelloWorld
** Creating README for cookbook: HelloWorld
** Creating metadata for cookbook: HelloWorld
/var/chef/cookbooks 디렉터리 아래 HelloWorld 디렉토리가 만들어진다.
만약, cookbook이 저장 될 디렉토리를 변경하려면 server.rb 파일에 cookbook_path 값을 변경해 주면 된다.
2. 속성(attributes) 정의
HelloWorld/attributes/ 디렉토리로 이동해 HelloWorld.rb 문서를 만들고 그 안에 cookbook에서 사용할 속성들을 정의한다.
여기서 속성은 변수를 정의하는 것과 같이 사용한다.
default['message']="HelloWorld"
key - value 형식을 갖는다.
3. recipes 수정
HelloWorld/recipes/default.rb를 수정한다.
template "/tmp/HelloWorld.txt" do
source "HelloWorld.txt.erb"
variables :message => node['message']
action :create
end
/tmp/HelloWorld.txt 라는 파일을 HelloWorld.txt.erb 라는 템플릿을 이용해서 만들겠다는 의미이며, 위에서 정의한 속성을 사용했다.
4. 템플릿 파일 생성
HelloWorld/template/default/HelloWorld.txt.erb 파일을 만들고 다음과 같이 입력한다.
Message is : <%= @message %>
5. cookbook 업로드
cookbook 디렉토리로 이동해서 다음과 같이 업로드 한다.
# knife cookbook upload -a -o .
Uploading HelloWorld [0.0.1]
upload complete
-a : 모든 cookbook
-o : cookbook 경로
6. chef-client의 cookbook 사용 설정
# knife node run_list add chef-client.com2us.com 'recipe[HelloWorld]'
run_list: recipe[HelloWorld]
# knife node show chef-client.com2us.com -r
run_list: recipe[HelloWorld]
chef-client.com2us.com node에게 HelloWorld라는 recipe를 사용할 수 있도록 설정
-r : recipe 출력
7. chef-client에서 chef-client 실행
# chef-client
[Thu, 10 Apr 2014 13:31:43 +0900] INFO: *** Chef 0.10.6 ***
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Run List is [recipe[HelloWorld]]
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Run List expands to [HelloWorld]
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Starting Chef Run for chef-client.com2us.com
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Running start handlers
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Start handlers complete.
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Loading cookbooks [HelloWorld]
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Storing updated cookbooks/HelloWorld/recipes/default.rb in the cache.
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Storing updated cookbooks/HelloWorld/attributes/HelloWorld.rb in the cache.
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Storing updated cookbooks/HelloWorld/README.md in the cache.
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Storing updated cookbooks/HelloWorld/metadata.rb in the cache.
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Processing template[/tmp/HelloWorld.txt] action create (HelloWorld::default line 9)
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: template[/tmp/HelloWorld.txt] updated content
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Chef Run complete in 0.457015 seconds
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Running report handlers
[Thu, 10 Apr 2014 13:31:44 +0900] INFO: Report handlers complete
8. 설정 업데이트 확인
# cat /tmp/HelloWorld.txt
Message is : HelloWorld
HelloWorld.txt 파일이 만들어진 것을 확인할 수 있다.
'OSS(Open Source Software) > chef' 카테고리의 다른 글
knife sub commands (0) | 2014.04.10 |
---|---|
knife sub commands - client (0) | 2014.04.10 |
chef client 설치 (0) | 2014.04.10 |
chef workstation 설정 (0) | 2014.04.10 |
knife 사용 (0) | 2014.04.07 |