salty ops – saltstack introduction

39
Salty OPS – Saltstack Introduction By Walter Liu 2013/12/24

Upload: walter-liu

Post on 15-Jan-2015

1.984 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Salty OPS – Saltstack Introduction

Salty OPS – Saltstack IntroductionBy Walter Liu 2013/12/24

Page 2: Salty OPS – Saltstack Introduction

Before Saltstack(This section is borrowed slides from slideshare)

Page 3: Salty OPS – Saltstack Introduction
Page 4: Salty OPS – Saltstack Introduction
Page 5: Salty OPS – Saltstack Introduction
Page 6: Salty OPS – Saltstack Introduction
Page 7: Salty OPS – Saltstack Introduction
Page 8: Salty OPS – Saltstack Introduction
Page 9: Salty OPS – Saltstack Introduction
Page 10: Salty OPS – Saltstack Introduction
Page 11: Salty OPS – Saltstack Introduction
Page 12: Salty OPS – Saltstack Introduction
Page 13: Salty OPS – Saltstack Introduction
Page 14: Salty OPS – Saltstack Introduction

BasicsCommands and misc

Page 15: Salty OPS – Saltstack Introduction

Basic components

Salt-master

Salt-minion

Salt-syndic: for large deployment or cross data-center.

Page 16: Salty OPS – Saltstack Introduction

Basic files of Salt

Configuration files /etc/salt/master /etc/salt/minion /etc/salt/minion_id (generated when first time start

daemon) /etc/salt/pki/ (generated when first time start daemon)

Log: /var/log/salt/

GITFS cache: /var/cache/salt/master/gitfs/refs/master/

Page 17: Salty OPS – Saltstack Introduction

Basic command

salt salt –v "*" test.ping salt –v –L “web1,web2” test.ping salt –v –E “web[12]” test.ping Salt –v –N group1 test.ping

salt-key –a, salt-key -d

salt-call

Page 18: Salty OPS – Saltstack Introduction

Update to newest state

salt –v '*' state.highstate

Page 19: Salty OPS – Saltstack Introduction

Copy file to minions

salt ‘*’ cp.get_file salt://path/to/file /minion/path/to/file

salt ‘*’ cp.get_dir salt://path/to/dir/ /minion/path/to/dir/

Page 20: Salty OPS – Saltstack Introduction

Information commands

salt '*' sys.doc [module]

salt '*' grains.items

salt '*' pillar.items

Page 21: Salty OPS – Saltstack Introduction

Package something andRun command

salt '*' pkg.install nginx

salt '*' pkg.remove nginx

salt '*' cmd.run ifconfig

Page 22: Salty OPS – Saltstack Introduction

Batch Size

Use batch size to rolling web server restart.

Example: salt “websvr*” –batch-size 25% apache.signal restart salt “websvr*” –batch-size 10 apache.signal restart

Page 23: Salty OPS – Saltstack Introduction

Troubleshooting and Test your command

Use salt-call to run locally

Add test=True to just view what will be done.

example: salt-call -l info state.highstate test=True salt '*' state.highstate test=True salt ‘testsvr01’ state.sls nginx test=True

Demo: Test failed. only salt-call could see the error.

Page 24: Salty OPS – Saltstack Introduction

Let’s run some examples.

Page 25: Salty OPS – Saltstack Introduction

Installation (CentOS)

yum install salt-master

yum install salt-minion

yum install salt-api

yum install python-halite

Other OS wget -O - http://bootstrap.saltstack.org | sudo sh

Page 26: Salty OPS – Saltstack Introduction

Re-initialize demo environment

salt "*" pkg.remove nginx

salt “*” cmd.run “rm /etc/nginx/conf.d/*”

salt-key -D

Page 27: Salty OPS – Saltstack Introduction

Add a new machine to Salt

Minion: edit /etc/salt/minion

Minion: hostname change to “www-01.dc1”

Minion: service salt-minion start

Master: salt-key -A

Page 28: Salty OPS – Saltstack Introduction

Configure installation in Salty way

Master: edit /etc/salt/master

Master: Add file top.sls

Master: Add file nginx.sls

Minion: salt-call -l debug state.highstate test=True

Master: salt "*" state.highstate test=True

Execute on master: salt "*" state.highstate

Page 29: Salty OPS – Saltstack Introduction

Add another new machine to salt

Minion: Add another machine. (hostname)

Master: salt "*" state.highstate

Page 30: Salty OPS – Saltstack Introduction

Add a managed config file

Master: edit top.sls, add dc1 directives.

Master: Add dc1/web.sls

Master: Add conf/dc1/www.conf

Master: salt "*" state.highstate

Page 31: Salty OPS – Saltstack Introduction

Add dc2 managed config file

Master: edit top.sls, add dc1 directives.

Master: Add dc2/web.sls

Master: Add conf/dc2/www.conf

Master: salt "*" state.highstate

Page 32: Salty OPS – Saltstack Introduction

Grains in short

Key values items of minion hardware/env.

Only acquire at salt-minion startup.

May be used in sls/template.

Let’s see how to config by domain/hostname. Master: salt ‘*’ grains.items Master: Add web_general/web.sls Master: Modify top.sls Master: Add conf/dc3/www.conf Master: salt-call ‘*.dc3’ highstate test=True

Page 33: Salty OPS – Saltstack Introduction

Pillar in short

Usage Highly Sensitive Data Minion Configuration Variables Arbitrary Data

Example, DB username, password Configure config file by hostname

Page 34: Salty OPS – Saltstack Introduction

GITFS

/etc/salt/master, change below configuration fileserver_backend:

- git Gitfs_remotes:

- git@gitlab……..

salt-run fileserver.update

Another method: Or only use gitfs to host config files.

Page 35: Salty OPS – Saltstack Introduction

Check config before restart

Application support check config in service reload (“init.d”). Return error code if failed.

Use cmd.wait:     - name: ”nginx -s reload” # do reload     - onlyif: “nginx -t” # test if config is ok.     - watch:       - file: /etc/nginx/conf.d/my_web.conf

Page 36: Salty OPS – Saltstack Introduction

Collaboration

RD Installation sls: “nginx.sls” User Config sls: “web_general/web.sls” User Config template: “www_redis.conf.template”

OPS top.sls pillar/top.sls

Page 37: Salty OPS – Saltstack Introduction

Reference for writing SLS

Salt Formulars on github https://github.com/saltstack-formulas

Salt-states on github https://github.com/saltstack/salt-states

Page 38: Salty OPS – Saltstack Introduction

Halite

Demo Web UI

Page 39: Salty OPS – Saltstack Introduction

Q & A