markdown 工程师厨师食谱
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 工程师厨师食谱相关的知识,希望对你有一定的参考价值。
### Set Up the Chef Environment
* install the engineyard gem in your local environment
* `sudo gem install engineyard`
* enter the password for your **engineyard account**
* Fork and clone the `ey-cloud-recipes` repository to your local machine
* [link to fork the repo](https://github.com/engineyard/ey-cloud-recipes)
* click fork
* copy the url of the forked repo to your clipboard
* `git clone` link : **Do not clone in the same directory as your app repo!**
---
## File Structure
* root of the directory: `cookbooks/`
* `/main`
* `attributes/`
* `definitions/`
* `libraries/`
* `recipes/`
* In the cookbooks directory, there are sub-directories that contain recipes for various
components (ex.redis)
* And so within that `redis` directory, there will be more sub-directories under it
* in `recipes/default.rb`: the main definition file that defines how Chef performs each
of its actions to achieve the customization
---
### Turn on a Cookbook
* To turn on a cookbook and have that set of recipes run whenever you deploy your app, you need to uncomment
the recipe in the `cookbooks/main/recipes/default.rb`
* To turn on an existing cookbook:
* select the cookbook
* in your local environment: open `cookbooks/main/recipes/default.rb` for editing
* uncomment the `include_recipe` line for the recipe you want to **turn on**
* save the file and commit and push your changes locally
* use the ey recipe commands to **upload and apply the recipes**:
* `ey recipes upload -e environment_name`
* `ey recipes apply -e environment_name`
---
### Create your own cookbook
* In local environment: `rake new_cookbook COOKBOOK=nginx_logrotate`
* which creates `cookbooks/nginx_logrotates/recipes/default.rb`
* add to the file:
```
remote_file "/etc/logrotate.d/nginx" do
owner "root"
group "root"
mode 0755
source "nginx.logrotate"
backup false
action :create
end
```
* create `files/default/nginx_logrotate` with the following content:
```
/var/log/engineyard/nginx/*.log {
daily
missingok
compress
rotate 60
dateext
notifempty
sharedscripts
extension gz
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}
```
* Edit `cookbook/main/recipes/default.rb` to **enable the recipe**: `include_recipe "nginx_logrotate"`
* `rake test`
* commit changes locally and puhs
* use the commands above to upload and apply the recipes
---
## Displaying Messages to the Dashboard
* dashboard is located on the environment page under the "Instances" heading and allows you to see when the custom portions of
your recipe are running.
* Example code (in `recipes/default.rb`):
```
ey_cloud_report "recipe_name" do
message "message text"
end
```
---
### Report to a log from custom chef recipes
* custom chef recipes are logged to `var/log/custom.log`
* Default engineyard cloud recipes are logged to `/var/log/chef.main.log`
* Use `Chef::Log.info "message text"`
---
### Specify which instance roles run a recipe
* `if node[:instance_role] == 'instance_role`
* `instance_role` could be `app_master, app, solo, db_master, db_slave, util`
* same applies to utility servers
### Servers
* On Engine Yard, you have many **applications**:
* `ExampleSumm201`
* `ExamCold2016`
* Each of these **applications** have their own **environments**:
* `staging`
* `production`
* Within these environments, contain **instances**
* `Application Instances: Application Master`
* `Database Instances: Master Database`
* `Utility Instances: memcached, redis, resque`
* Each has their own unique address (**some will change upon restarting the environment**)
* To connect to the app or the database you'll need to create in your `.ssh/config` file
```
Host name-of-connection
HostName address obtained above (from the EY dashboard)
User deploy
IdentityFile ~/.ssh/engineyard
```
* If you don't use this way of connecting to the server:
```
ssh -i ~/.ssh/engineyard deploy@...
```
* terminal : `ssh name-of-connection`
* Now you are inside the virtual server that contains either the app or database
---
### Chef Recipes
* the chef repo lives in a directory outside of your app!
* In here, you can make recipes or modify existing recipes
* Upload and apply your changes within this directory to your **environment**!
---
### Logs
* Logs are located on the **actual server**
* SSH into the server and go into `/var/log` or `etc/chef.log.info`
* Use the `cat` command or `less` to view logs
以上是关于markdown 工程师厨师食谱的主要内容,如果未能解决你的问题,请参考以下文章