Introducing Saltstack

22
SaltStack NOV 2013 www.anubhaskar.name Creative Commons Attribution-ShareAlike 3.0 Unported License.

description

These are the slides I used in my local libre user group meetup to introduce Saltstack to my friends and users from varied backgrounds.

Transcript of Introducing Saltstack

Page 1: Introducing Saltstack

SaltStack

NOV 2013

www.anubhaskar.name

Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 2: Introducing Saltstack

2

1.Introduction2.Product Architecture3.Components4.Prototype Architecture5.Prerequisites6.Install & configure Salt server7.Install and configure Salt clients8.Configure LAMP Software repositories9.Create web site template10.Configure Apache web server11.Configure PHP12.Configure MySQL db server13.Create sample database14.Create script to import database15.Configure sample database import16.Apply states to target clients

AGENDA

Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 3: Introducing Saltstack

3

Introduction

Creative Commons Attribution-ShareAlike 3.0 Unported License.

Saltstack is a● Configuration Management System

Keep the hosts configured the way we want them. Maintain hosts in a defined state

Manage packages, config files, services, users, groups etc in an easy to read syntax at central locations

Provision cloud computing instances● Remote Execution System

Execute commands and query data on remote nodes

Receive results from remote nodes asynchronously

Page 4: Introducing Saltstack

4

Product Architecture

Creative Commons Attribution-ShareAlike 3.0 Unported License.

Minion1

Minion2

MinionN

Salt Master

Halite(Web UI)

Page 5: Introducing Saltstack

5

Components

Creative Commons Attribution-ShareAlike 3.0 Unported License.

● Master - The central server from which Salt commands are run and States are applied

● Minions - The hosts you are managing, they maintain a connection to the master and await instructions

● States - Express the state of a host using small, easy to read, easy to understand configuration files. Directives used for configuration management

● Modules - Collections of functions which can be run from the Salt CLI (and are also run under the hood by States)

● Grains – Static information collected by minions about the system. The grains interface is made available to other components to make right commands are automatically available to them.

Page 6: Introducing Saltstack

6

repo(Centos6/10.10.10.2Software Repository)

Prototype Architecture

Creative Commons Attribution-ShareAlike 3.0 Unported License.

minion(Centos6/10.10.10.4)

salt(Centos6/10.10.10.3)

Admin

Administration

Page 7: Introducing Saltstack

7

Prerequisites

Creative Commons Attribution-ShareAlike 3.0 Unported License.

For simplicity and ease of demonstration below changes are made in prototype. These options should be avoided or carefully considered in a production deployment

1. All the hosts are installed with Centos6.3 minimal install cd.

2. Disable SELinux on both server and client# vi /etc/selinux/configSELINUX=disabled

3. Disable firewall on both server and client# chkconfig iptables off

4. Add host entries on server, client and software repository10.10.10.2 repo10.10.10.3 salt10.10.10.4 minion

5. Reboot server and client hosts

Page 8: Introducing Saltstack

8

Install & configure Salt server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Install salt server and web-ui on 10.10.10.3# yum install salt-master# yum install python-halite

2. Configure salt server# vi /etc/salt/masterexternal_auth: pam: halite: - .* - '@runner' file_roots: base: - /srv/salthalite: level: 'debug' server: 'cherrypy' host: '0.0.0.0' port: '8080' cors: False tls: False

Page 9: Introducing Saltstack

9

Install & configure Salt server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

3. Create a user to login to web-ui# useradd halite# passwd halite

4. Create directory for configuration store# mkdir /srv/salt

5. Start salt server# service salt-master start# chkconfig salt-master on

Page 10: Introducing Saltstack

10

Install & configure Salt clients

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Install salt client (called minion) on 10.10.10.4# yum install salt-minion# service salt-minion start# chkconfig salt-minion on

2. Log into salt server and accept SSL key from minion for authorization# salt-key -L# salt-key -a minion

3. Try a test connect from salt server to salt client# salt minion test.ping

4. View details (called grains) of salt client from server# salt minion grains.items

Page 11: Introducing Saltstack

11

Now, let us deploy a simple LAMP using

Saltstack

LAMP – Linux/Apache/MySQL/PHP

Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 12: Introducing Saltstack

12

Configure LAMP Software Repositories

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create webserver yum repo file in salt server# mkdir /srv/salt/softdepo# vi /srv/salt/softdepo/httpd.repo[httpd]name=httpdbaseurl=http://10.10.10.2/httpdgpgcheck=0enabled=1

2. Crete dbserver yum repo file in salt server# vi /srv/salt/softdepo/mysql.repo[mysql]name=mysqlbaseurl=http://10.10.10.2/mysqlgpgcheck=0enabled=1

3. Create php yum repo file in salt server# vi /srv/salt/softdepo/php.repo[php]name=phpbaseurl=http://10.10.10.2/phpgpgcheck=0enabled=1

Page 13: Introducing Saltstack

13

Configure LAMP Software Repositories

Creative Commons Attribution-ShareAlike 3.0 Unported License.

4. Create software repository state files in salt server# vi /srv/salt/softdepo.sls/etc/yum.repos.d/httpd.repo: file: - managed - source: salt://softdepo/httpd.repo

/etc/yum.repos.d/php.repo: file: - managed - source: salt://softdepo/php.repo

/etc/yum.repos.d/mysql.repo: file: - managed - source: salt://softdepo/mysql.repo

Page 14: Introducing Saltstack

14

Create web site template

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create a php web page template in salt server to display some mysql database values. This web page will be ultimately hosted in our LAMP server# mkdir /srv/salt/webserver# vi /srv/salt/webserver/index.php<?php

$con = mysql_connect( 'localhost', 'root' );$db = mysql_select_db( 'solarsystem' );

$sql = "select * from planets";$query = mysql_query( $sql );

echo "<table>";

while( $row = mysql_fetch_assoc($query) ){echo "<tr><td>$row[id]</td>";echo "<td>$row[name]</td></tr>";}

echo "</table>";

?>

Page 15: Introducing Saltstack

15

Configure Apache web server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

2. Create state files in salt server for installing Apache web server# vi /srv/salt/webserver.slshttpd: pkg: - installed service: - running - require: - pkg: httpd

/var/www/html/index.php: file: - managed - source: salt://webserver/index.php

Page 16: Introducing Saltstack

16

Configure PHP

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create state files in salt server for installing PHP# vi /srv/salt/php.slsphp: pkg: - installed

php-mysql: pkg: - installed

Page 17: Introducing Saltstack

17

Configure MySQL db server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create state files in salt server for installing MySQL# vi /srv/salt/dbserver.slsmysql-server: pkg: - installed

mysqld: service: - running - require: - pkg: mysql-server

Page 18: Introducing Saltstack

18

Create a sample database to import into db server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create a database dump file in salt server to import data to mysql server# mkdir /srv/salt/dbcreate# vi /srv/salt/dbcreate/dbdump.sqlCREATE DATABASE IF NOT EXISTS `solarsystem`;USE `solarsystem`;DROP TABLE IF EXISTS `planets`;CREATE TABLE `planets` ( `id` int(8) NOT NULL DEFAULT '0', `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;LOCK TABLES `planets` WRITE;INSERT INTO `planets` VALUES (1,'mercury'),(2,'venus'),(3,'earth'),(4,'mars'),(5,'jupiter'),(6,'saturn'),(7,'uranus'),(8,'neptune'),(9,'pluto');UNLOCK TABLES;

Page 19: Introducing Saltstack

19

Create a script to import sample database

Creative Commons Attribution-ShareAlike 3.0 Unported License.

2. Create a shell script in salt server to import sample database# vi /srv/salt/dbcreate/dbcreate.sh#! /bin/bashmysql -u root < /tmp/dbdump.sql

Page 20: Introducing Saltstack

20

Configure sample data base import to db server

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create saltstack state files in salt server for importing data to db server# vi /srv/salt/dbcreate.sls/tmp/dbdump.sql: file: - managed - source: salt://dbcreate/dbdump.sql/tmp/dbcreate.sh: file: - managed - source: salt://dbcreate/dbcreate.sh

dbcreate.sh: cmd: - run - name: | chmod +x /tmp/dbcreate.sh /tmp/dbcreate.sh

Page 21: Introducing Saltstack

21

Apply states to target client

Creative Commons Attribution-ShareAlike 3.0 Unported License.

1. Create a top.sls file in salt server to map state files to target hosts and specify execution order# vi /srv/salt/top.slsbase: minion: - softdepo - php - dbserver - dbcreate - webserver

2. Apply states to target client from salt server# salt minion state.highstate

3. View hosted website at http://10.10.10.4/index.php

Page 22: Introducing Saltstack

22

THANK YOU

Creative Commons Attribution-ShareAlike 3.0 Unported License.