salt-docs Documentation

Transcrição

salt-docs Documentation
salt-docs Documentation
Release 1.0
DTI-SJC
July 01, 2016
Contents
1
Docker - Instalação e Configuração
1.1 Instalação . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Configuração . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Dockerfiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
SaltStack
2.1 Documentação: https://docs.saltstack.com/en/latest/
2.2 Instalação com Bootstrap . . . . . . . . . . . . . .
2.3 Instalação . . . . . . . . . . . . . . . . . . . . . . .
2.4 Configuração . . . . . . . . . . . . . . . . . . . . .
2.5 Comandos salt . . . . . . . . . . . . . . . . . . . .
3
3
3
3
.
.
.
.
.
9
9
9
9
9
10
3
Sphinx vs Readthedocs
3.1 DICAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 LINKS ÚTEIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
15
15
4
Indices and tables
17
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
i
ii
salt-docs Documentation, Release 1.0
Conteúdo:
Contents
1
salt-docs Documentation, Release 1.0
2
Contents
CHAPTER 1
Docker - Instalação e Configuração
1.1 Instalação
$ curl -sSL https://get.docker.com/ | sh
$ docker -v
Docker version 1.11.1, build 5604cbe
para outras opções: get.docker.com ou https://docs.docker.com/installation/
1.2 Configuração
Distriuição
Ubuntu/Debian/Gentoo
Opensuse/CentOS/Red Hat
Configuração
/etc/default/docker
/etc/sysconfig/docker
1. Mudando a localização diretório raiz do Docker (Default -> /var/lib/docker)
1. Técnica 1 ( no Debian /etc/default/docker )
DOCKER_OPTS="-g /mnt/bigdisk/docker"
$ systemctl stop docker
$ systemctl start docker
2. Técnica 2
$ docker daemon -g /mnt/bigdisk/docker
1.3 Dockerfiles
1.3.1 Nginx ( http://salt:8000 )
1. DOCKERFILE
FROM nginx
MAINTAINER DTI-SJC <[email protected]>
3
salt-docs Documentation, Release 1.0
COPY default.conf /etc/nginx/conf.d/default.conf
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2. DOCKER BUILD
$ docker build -t tiusjc/nginx .
3. DOCKER RUN ( LINK COM MYSQL)
$ docker run -h nginx --link php:php -p 8000:80 --name nginx -v /data/nginx/html:/usr/share/nginx/htm
Note: VOlUMES: HOST=/data/nginx/html CONTAINER=/usr/share/nginx/html
$ ls /data/nginx/html/
index.html
4. DOCKER EXEC
$ docker exec -ti nginx /bin/bash
Testando:
root@nginx:/# curl http://127.0.0.1/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
17
18
19
20
21
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
22
23
24
25
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
4
Chapter 1. Docker - Instalação e Configuração
salt-docs Documentation, Release 1.0
1.3.2 PHP ( http://salt:8000/phpinfo.php )
1. DOCKERFILE
FROM php:7.0.7-fpm
MAINTAINER DTI-SJC <[email protected]>
RUN docker-php-ext-install mysqli
EXPOSE 9000
CMD ["php-fpm"]
2. DOCKER BUILD
$ docker build -t tiusjc/php .
3. DOCKER RUN (link com MYSQL)
$ docker run -h php --name php --link mysql:mysql --volumes_from:nginx -d tiusjc/php
4. DOCKER EXEC
$ docker exec -ti php /bin/bash
1.3.3 MYSQL ( http://salt:8000/mysql.php )
1.DOCKERFILE
FROM mysql
MAINTAINER DTI-SJC <[email protected]>
EXPOSE 3306
2. DOCKER BUILD
$ docker build -t tiusjc/mysql .
3. DOCKER RUN
$ docker run --name mysql -h mysql -e MYSQL_ROOT_PASSWORD=******* -d tiusjc/mysql
4. DOCKER EXEC
$ docker exec -ti mysql /bin/bash
Testando:
root@mysql:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
1.3. Dockerfiles
5
salt-docs Documentation, Release 1.0
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
1.3.4 PHPMYADMIN ( http://salt:8080 )
1. DOCKERFILE
FROM phpmyadmin/phpmyadmin
MAINTAINER DTI-SJC <[email protected]>
EXPOSE 80
2. DOCKER BUILD
$ docker build -t tiusjc/phpmyadmin .
3. DOCKER RUN
$ docker run --name phpmyadmin -h phpmyadmin -e PMA_USER=root -e PMA_PASSWORD=******* -e PMA_HOST=mys
4. DOCKER EXEC
$ docker exec -ti phpmyadmin /bin/bash
1.3.5 Juntando tudo
1. DOCKER COMPOSE
nginx:
image: tiusjc/nginx
ports:
- 8000:80
links:
- php
volumes_from:
- app
php:
image: tiusjc/php7.0.7-fpm
ports:
- 9000:9000
links:
- mysql
volumes_from:
- app
app:
image: tiusjc/php7.0.7-fpm
volumes:
- /data/html/:/var/www/html
command: echo "Backup aplicação"
6
Chapter 1. Docker - Instalação e Configuração
salt-docs Documentation, Release 1.0
mysql:
image: tiusjc/mysql
volumes_from:
- data
environment:
MYSQL_ROOT_PASSWORD: ****
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql
environment:
PMA_USER: root
PMA_PASSWORD: ****
PMA_HOST: mysql
data:
image: tiusjc/mysql
volumes:
- /data/mysql/:/var/lib/mysql
command: echo "Backup Mysql"
2. EXECUTANDO
$ docker-compose -f nginx-php-mysql.yml -d
1.3.6 SALT MASTER
1. DOCKERFILE
FROM ubuntu:xenial
MAINTAINER DTI-SJC <[email protected]>
RUN apt-get update -q && apt-get install -q -y nano net-tools wget python-software-properties softwar
RUN wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-ke
RUN echo deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main > /etc/apt/sources.l
RUN apt-get update && apt-get install -q -y salt-master
RUN export TERM=xterm
ENTRYPOINT ["/usr/bin/salt-master"]
EXPOSE 4505 4506
2. DOCKER BUILD
$ docker build -t tiusjc/salt-master:16.04 .
3. DOCKER RUN
1.3. Dockerfiles
7
salt-docs Documentation, Release 1.0
$ docker run -d -h salt --name salt-master tiusjc/salt-master:16.04
4. DOCKER EXEC
$ docker exec -ti salt-master /bin/bash
1.3.7 SALT MINION
1. DOCKERFILE
FROM ubuntu:xenial
MAINTAINER DTI-SJC <[email protected]>
RUN apt-get update -q && apt-get install -q -y nano wget python-software-properties software-properti
RUN wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-ke
RUN echo deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main > /etc/apt/sources.l
RUN apt-get update && apt-get install -q -y salt-minion
RUN export TERM=xterm
CMD ["/usr/bin/salt-minion"]
2. DOCKER BUILD
$ docker build -t tiusjc/salt-minion:16.04 .
3. DOCKER RUN:
$ docker run -d --link salt-master:salt-master -h salt-minion --name salt-minion tiusjc/salt-minion:1
8
Chapter 1. Docker - Instalação e Configuração
CHAPTER 2
SaltStack
2.1 Documentação: https://docs.saltstack.com/en/latest/
2.2 Instalação com Bootstrap
Salt Bootstrap é um shell script que detecta a plataforma de destino e seleciona o melhor método de instalação (
Plataformas suportadas )
2.3 Instalação
2.3.1 1. No salt master
$ sudo sh bootstrap_salt.sh -M
Docker: http://dtisjc-docs.readthedocs.io/en/latest/docker.html#salt-master
Github: https://github.com/tiusjc/dtisjc-docs/tree/master/docs/dockerfiles/salt-master
2.3.2 2. No salt-minion
$ sudo sh bootstrap_salt.sh -A <servidor-salt>
onde:
<servidor-salt> - IP ou DNS name do servidor do salt.
Docker: http://dtisjc-docs.readthedocs.io/en/latest/docker.html#salt-minion
Github: https://github.com/tiusjc/dtisjc-docs/tree/master/docs/dockerfiles/salt-minion
2.4 Configuração
2.4.1 1. No master
/etc/salt/master
9
salt-docs Documentation, Release 1.0
file_roots:
base:
- /home/vol1/salt/base
pillar_roots:
base:
- /home/vol1/salt/pillar
Reiniciando serviço:
$ /etc/init.d/salt-minion restart
2.4.2 2. No minion
/etc/salt/minion
master: <ip_salt_servidor>
Reiniciando serviço:
$ /etc/init.d/salt-minion restart
2.5 Comandos salt
2.5.1 Aceitando minions
Comando: SALT-KEY -h ( https://docs.saltstack.com/en/latest/ref/cli/salt-key.html )
-a - aceita minion key
-A - aceitar todas as minions keys
-r - rejeita minion key
-R - Rejeitar todas as minions keys
-d - Deletar minion key
-D - Deleta todas as minions keys
$ salt-key
Accepted Keys:
D159718
Denied Keys:
Unaccepted Keys:
D159718
Rejected Keys:
2.5.2 Verificando a versão
Exibe a versão do salt resumo
$ salt-master --version
$ salt-minion --version
Exibe informações completas
$ salt-master --versions-report
$ salt-minion --versions-report
10
Chapter 2. SaltStack
salt-docs Documentation, Release 1.0
2.5.3 Testando os minions
$ salt \* test.ping
2.5. Comandos salt
11
salt-docs Documentation, Release 1.0
12
Chapter 2. SaltStack
CHAPTER 3
Sphinx vs Readthedocs
Documentando projetos com Sphinx e ReadTheDocs.org
• Crie um repositório no github para o seu projeto:
Repositório DTISJC - https://github.com/tiusjc/dtisjc-docs.git
Generating an SSH key - https://help.github.com/articles/generating-an-ssh-key
• Crie uma pasta documentation para o seu projeto:
$
$
$
$
mkdir documentation
cd documentation
git init
git remote add origin [email protected]:tiusjc/dtisjc-docs.git
• Crie uma pasta docs:
$ mkdir docs
• Instale o sphinx e configure o sphinx-quickstart:
$
$
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
pip install phinx
sphinx-quickstart
root path for documentation [.]: docs
Separate source and build directories (y/n) [n]: y
Name prefix for templates and static dir [_]:
Project name: dtisjc-docs
Author name(s): DTI-SJC
Project version: 1.0
Project release [1.0]:
Project language [en]: pt_BR
Source file suffix [.rst]:
Name of your master document (without suffix) [index]:
Do you want to use the epub builder (y/n) [n]:
autodoc: automatically insert docstrings from modules (y/n) [n]: y
doctest: automatically test code snippets in doctest blocks (y/n) [n]: y
intersphinx: link between Sphinx documentation of different projects (y/n) [n]:
todo: write "todo" entries that can be shown or hidden on build (y/n) [n]:
coverage: checks for documentation coverage (y/n) [n]:
imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
ifconfig: conditional inclusion of content based on config values (y/n) [n]:
viewcode: include links to the source code of documented Python objects (y/n)[n]: y
Create Makefile? (y/n) [y]:
Create Windows command file? (y/n) [y]:
13
salt-docs Documentation, Release 1.0
• A pasta docs agora possui:
$ ls docs -l
-rw-r--r-- 1
drwxr-xr-x 4
-rw-r--r-- 1
drwxr-xr-x 4
root
root
root
root
root
root
root
root
8085
4096
7747
4096
May
May
May
May
12
12
12
12
14:40
14:51
14:40
14:47
Makefile
build
make.bat
source #arquivo principal index.rst
• Va criar um arquivo all-about-me.rst (para aprender sobre formatação consulte:
doc.org/en/stable/rest.html#rst-primer).
http://www.sphinx-
Note: A pasta source conterá os arquivos após a renderização(.rst). Arquivos rst são os arquivos fontes para
sua documentação.
############
All about me
############
I'm Daniele Procida, a Django user and developer.
I've contributed to:
*
*
*
django CMS
Arkestra
Django
• Adicione a referência a ele no arquivo index.rst como abaixo:
.. toctree::
:maxdepth: 2
all-about-me
• Para renderizar o seu documento na pasta docs execute ( source(.rst) -> build/html(.html) ):
$ make html
sphinx-build -b html -d build/doctrees
source build/html
Running Sphinx v1.4.1
loading translations [pt_BR]... done
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
build succeeded.
Build finished. The HTML pages are in build/html.
• Veja na pasta build/html que foram criados os seguintes arquivos:
$ ls build/html/
_sources _static
all-about-me.html
genindex.html
index.html
objects.inv
search.html
• Vamos testar:
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
14
Chapter 3. Sphinx vs Readthedocs
searc
salt-docs Documentation, Release 1.0
• No seu navegador digite http://servidor:8000/build/html/
• Instalar o tema para sphinx_rtd_theme no ReadTheDocs - https://github.com/snide/sphinx_rtd_theme
$ pip install sphinx_rtd_theme
• No seu conf.py arquivo
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
• Atualize o github:
$ git add .
$ git commit -m "Atualizando o tema para sphinx_rtd_theme"
$ git push origin master
3.1 DICAS
• Lista todas as linguagens suportadas (.. code-block:: <language>)
$ pygmentize -L lexers
3.2 LINKS ÚTEIS
http://hyperpolyglot.org/lightweight-markup
3.1. DICAS
15
salt-docs Documentation, Release 1.0
16
Chapter 3. Sphinx vs Readthedocs
CHAPTER 4
Indices and tables
• genindex
• modindex
• search
17

Documentos relacionados

Docker para desenvolvedores

Docker para desenvolvedores This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iter...

Leia mais