saltstack实现中小型架构的搭建

  1. 安装以下依赖包:
    yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel lrzsz memcache(可以先安装,操作时就只是检查)
  2. 下载以下软件包:
    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz##可用yum
    wget http://nginx.org/download/nginx-1.9.6.tar.gz
    wget http://keepalived.org/software/keepalived-1.2.19.tar.gz
    wget http://cn2.php.net/get/php-5.6.15.tar.gz/from/this/mirror

部署Haproxy

[[email protected]]# vim /etc/salt/master

file_roots:

  base:

    - /srv/salt/base

  prod:

    - /srv/salt/prod

  test:

    - /srv/salt/test

[[email protected]]# /etc/init.d/salt-master restart

###修改完配置文件要重启才能生效

[[email protected]~]# mkdir /srv/salt/prod/pkg –p   ##生产上一些包放在这

[[email protected]~]# mkdir /srv/salt/prod/haproxy

[[email protected]~]# mkdir /srv/salt/prod/haproxy/files

[[email protected]]# vim pkg-init.sls    ##安装包的初始化

pkg-init:              ##ID

pkg.installed:

- names:

- gcc

- gcc-c++

- glibc

- make

- autoconf

- openssl

- openssl-devel

- pcre-devel  ###nginx需要

[[email protected]]# cp /home/reid/tools/haproxy-1.6.2.tar.gz  haproxy/files/

操作方法:第一次先用手动安装一次,然后再用salt来写一次

[[email protected]]# cp /home/reid/tools/haproxy-1.6.2.tar.gz haproxy/files/

[[email protected]]# cd haproxy/files/

[[email protected]]# ls

haproxy-1.6.2.tar.gz

[[email protected]]# cp haproxy-1.6.2.tar.gz /usr/local/src/

[[email protected]]# tar zxf haproxy-1.6.2.tar.gz

[[email protected]]# cd haproxy-1.6.2

[[email protected]]# make TARGET=linux26 PREFIX=/usr/local/haproxy && makeinstall PREFIX=/usr/local/haproxy

[[email protected]]# cd examples/

[[email protected]]# vim haproxy.init

BIN=/usr/local/haproxy/sbin/$BASENAME   ##修改脚本路径

[[email protected]]# cp haproxy.init /srv/salt/prod/haproxy/files/

[[email protected]]# cd /srv/salt/prod/haproxy/

[[email protected]]# vim install.sls

include:           ##先把包include

- pkg.pkg-init

haproxy-install:

file.managed:

- name: /usr/local/src/haproxy-1.6.2.tar.gz

- source: salt://haproxy/files/haproxy-1.6.2.tar.gz  ##放包根据file_roots来设

- user: root

- group: root

- mode: 755

cmd.run:   ##安装

- name: cd/usr/local/src && tar zxf haproxy-1.6.2.tar.gz &&cdhaproxy-1.6.2 && make TARGET=linux26 PREFIX=/usr/local/haproxy&&make install PREFIX=/usr/local/haproxy

- unless: test -d /usr/local/haproxy    ###如果不存在返回false时就执行

- require:

- pkg: pkg-init      ##依赖于这些包

- file: haproxy-install

##haproxy-install下有一个文件模块,依赖于这个,一个ID下一个模块只能使用一次

haproxy-init:   ##加入开机启动服务

file.managed:

-name: /etc/init.d/haproxy

- source: salt://haproxy/files/haproxy.init

- user: root

- group: root

- mode: 755

- require:

- cmd: haproxy-install   ####haproxy-install下面一个cmd的模块,依赖于这个

cmd.run:

-name: chkconfig --add haproxy

- unless: chkconfig --list |grep haproxy

- require:

- file: /etc/init.d/haproxy

net.ipv4.ip_nonlocal_bind:   #监听非本地IP ,负载均衡的机器上只有一个IP,所以要修改一个内核参数

sysctl.present:

- value: 1

haproxy-config-dir:  ###创建一个目录,放文件到里面

file.directory:

- name: /etc/haproxy

- user: root

- group: root

- mode: 755

监听非本地IP ,负载均衡的机器上只有一个IP,所以要修改一个内核参数

[[email protected]~]# cat /proc/sys/net/ipv4/ip_nonlocal_bind

0

状态间关系:

unless:用于检查的命令仅当“unless”选项指向的命令返回false时才执行name指向的命令

require:我依赖某个状态,它执行了我才执行

[[email protected]]# salt ‘linux-node1.*‘ state.sls haproxy.install env=prod  ##加env=prod,因为不加默认是找base,生产上不建议用*来执行,这里为了方便用了* ,而且要加test=True做好测试

[[email protected]~]# mkdir /srv/salt/prod/cluster

[[email protected]~]# mkdir /srv/salt/prod/cluster/files ##把配置放里面

[[email protected]~]# cd /srv/salt/prod/cluster/files/

[[email protected]]# vim haproxy-outside.cfg  ##外网负载均衡

global

maxconn 100000

chroot /usr/local/haproxy

uid 99

gid 99

daemon

nbproc 1

pidfile /usr/local/haproxy/logs/haproxy.pid

log 127.0.0.1 local3 info

defaults

option http-keep-alive

maxconn 100000

mode http

timeout connect 5000ms

timeout client  50000ms

timeout server 50000ms

listen stats

mode http

bind 0.0.0.0:8888

stats enable

stats uri     /haproxy-status

stats auth    haproxy:saltstack

frontend frontend_www_example_com

bind10.0.0.11:80

mode http

option httplog

log global

default_backend backend_www_example_com

backend backend_www_example_com

option forwardfor header X-REAL-IP

option httpchk HEAD / HTTP/1.0

balanceroundrobin

server web-node1  10.0.0.7:8080 check inter 2000 rise 30 fall 15

server web-node2  10.0.0.8:8080 check inter 2000 rise 30 fall 15

###生产建议除了负载均衡都监听80,可以用普通用户来起

cluster目录下写haproxy相关的配置,配置文件的管理和服务的管理—》思路先安装---配置---再起

[[email protected]]# vim haproxy-outside.sls

include:

- haproxy.install

haproxy-service:

file.managed:

- name: /etc/haproxy/haproxy.cfg

- source:salt://cluster/files/haproxy-outside.cfg

- user: root

- group: root

- mode: 644

service.running:     ##启动服务

- name: haproxy

- enable: True            ###开机自启动

- reload: True     ###不加,配置文件变化了会restart

- require:

- cmd: haproxy-init

- watch:           ##监控配置文件的变化

- file: haproxy-service

[[email protected]]# vim /srv/salt/base/top.sls

base:

‘*‘:

- init.env_init

prod:

  ‘linux-node1.example.com‘:

    - cluster.haproxy-outside

  ‘linux-node2.example.com‘:

    - cluster.haproxy-outside

[[email protected]~]# salt ‘*‘ state.highstate

Apache的监听端口要修改

Listen:8080

/etc/init.d/httpdrestart    ###linux-node2上没有安装

[[email protected]~]# echo "linux-node1" >>/var/www/html/index.html

[[email protected]~]# echo "linux-node2" >>/var/www/html/index.html

http://10.0.0.7:8888/haproxy-status

部署keepalived

[[email protected]]# mkdir /srv/salt/prod/keepalived/files -p

[[email protected]]# cp /usr/local/src/keepalived-1.2.19/keepalived/etc/init.d/keepalived.init/srv/salt/prod/keepalived/files/

[[email protected]]# cp /usr/local/src/keepalived-1.2.19/keepalived/etc/keepalived/keepalived.conf  /srv/salt/prod/keepalived/files/

[[email protected]]# cd /srv/salt/prod/keepalived/files/

[[email protected]]# ls

keepalived.conf  keepalived.init

[[email protected]]# vimkeepalived.init   ###启动脚本

start(){

echo -n $"Starting $prog: "

daemon /usr/local/keepalived/sbin/keepalived${KEEPALIVED_OPTIONS}

[[email protected]]# cd ..

[[email protected]]# vim install.sls   ##安装

include:            ##先include要安装的基础包

  - pkg.pkg-init

 

keepalived-install:      ##安装

  file.managed:

    - name:/usr/local/src/keepalived-1.2.19.tar.gz

    - source:salt://keepalived/files/keepalived-1.2.19.tar.gz   ###存放安装包

    - user: root

    - group: root

    - mode: 755

  cmd.run:            ###编译

    - name: cd/usr/local/src && tar zxf keepalived-1.2.19.tar.gz && cdkeepalived-1.2.19  && ./config

ure --prefix=/usr/local/keepalived --disable-fwmark&& make && make install

- unless: test -d /usr/local/keepalived

    - require:

      - pkg: pkg-init

      - file:keepalived-install

keepalived-init:          ###以下是管理配置文件

  file.managed:

    - name:/etc/init.d/keepalived

    - source:salt://keepalived/files/keepalived.init

    - user: root

    - group: root

    - mode: 755

  cmd.run:                 ###设置开机启动

    - name: chkconfig--add keepalived

    - unless:chkconfig --list | grep keepalived

    - require:

      - file:keepalived-init

 

/etc/sysconfig/keepalived:

  file.managed:

    - source:salt://keepalived/files/keepalived.sysconfig

    - user: root

    - group: root

    - mode: 644

 

/etc/keepalived:

  file.directory:

    - user: root

    - group: root

    - mode: 755

[[email protected]]# cp /usr/local/keepalived/etc/sysconfig/keepalived/srv/salt/prod/keepalived/files/keepalived.sysconfig

[[email protected]]# vim keepalived  ====》KEEPALIVED_OPTIONS="-D"

[[email protected]]# ll files/

总用量 12

-rw-r--r--1 root root 3562 11月 21 13:33 keepalived.conf

-rwxr-xr-x1 root root 1335 11月 21 13:39 keepalived.init

-rw-r--r--1 root root  667 11月 21 13:59 keepalived.sysconfig

-rw-r--r--1 root root 330164 11月 21 14:26 keepalived-1.2.19.tar.gz

[[email protected]]# salt ‘*‘ state.sls keepalived.install env=prod

[[email protected]]# lsof -i:4505   ###一直保持连

COMMAND    PID USER  FD   TYPE DEVICE SIZE/OFF NODENAME

salt-mast3643 root   12u  IPv4 163688      0t0 TCP *:4505 (LISTEN)

salt-mast3643 root   14u  IPv4 165569      0t0 TCP linux-node1.example.com:4505->linux-node1.example.com:34412 (ESTABLISHED)

salt-mast3643 root   15u  IPv4 164033      0t0 TCP linux-node1.example.com:4505->linux-node2.example.com:54631(ESTABLISHED)

salt-mini3747 root   24u  IPv4 165568      0t0 TCP linux-node1.example.com:34412->linux-node1.example.com:4505 (ESTABLISHED)

saltstack可以用写到mysql上看那能机器没有返回来测试,那能不成功

keepalived的引用

[[email protected]~]# cd /srv/salt/prod/cluster/files/

[[email protected]]# cat haproxy-outside-keepalived.conf   ###keepalived的配置文件

!Configuration File for keepalived

global_defs{

notification_email {

[email protected]

}

[email protected]

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id {{ROUTEID}}

}

vrrp_instancehaproxy_ha {

state {{STATEID}}

interfaceeth0

virtual_router_id 36

priority {{PRIORITYID}}

advert_int 1

authentication{

auth_typePASS

auth_pass 1111

}

virtual_ipaddress {

10.0.0.11

}

}

[[email protected]]# ls

files  haproxy-outside.sls

[[email protected]]# vim haproxy-outside-keepalived.sls

include:

  - keepalived.install

 

keepalived-service:

  file.managed:

    - name: /etc/keepalived/keepalived.conf

    - source:salt://cluster/files/haproxy-outside-keepalived.conf

    - user: root

    - group: root

    - mode: 644

    - template: jinja

   {% if grains[‘fqdn‘] == ‘linux-node1.example.com‘ %}

    - ROUTEID:haproxy_ha

    - STATEID: MASTER

    - PRIORITYID: 150

    {% elifgrains[‘fqdn‘] == ‘linux-node2.example.com‘ %}

    - ROUTEID:haproxy_ha

    - STATEID: BACKUP

    - PRIORITYID: 100

    {% endif %}

  service.running:

    - name: keepalived

    - enable: True

    - watch:

      - file: keepalived-service

[[email protected]]# salt ‘*‘ state.sls cluster.haproxy-outside-keepalived env=prodtest=True

[[email protected]]# salt ‘*‘ state.sls cluster.haproxy-outside-keepalived env=prod

[[email protected]]# vim base/top.sls

base:

‘*‘:

- init.env_init

prod:

‘linux-node1.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

‘linux-node2.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

[[email protected]]# salt ‘*‘ state.highstate

[[email protected]]# ip add| grep 11

inet 10.0.0.11/32 scope global eth0

[[email protected]]# /etc/init.d/keepalived stop

[[email protected]~]# ip add |grep 11

inet 10.0.0.11/32 scope global eth0

统一用记管理

[[email protected]~]# mkdir /srv/salt/prod/user

[[email protected]]# vim www.sls  ##web的管理用户

www-user-group:

  group.present:

    - name: www

    - gid: 1000

     

  user.present:

    - name: www

    - fullname: www

    - shell: /sbin/nologin

    - uid: 1000

- gid: 1000

[[email protected]]# salt ‘*‘ state.sls user.www env=prod test=True

[[email protected]]# salt ‘*‘ state.sls user.www env=prod

[[email protected]]# vim mysql.sls  ###mysql管理用户

mysql-user-group:

  group.present:

    - name: mysql

    - gid: 501

 

  user.present:

    - name: mysql

    - fullname: mysql

    - shell: /sbin/nologin

    - uid: 501

- gid: 501

[[email protected]]# salt ‘*‘ state.sls user.mysql env=prod test=True

[[email protected]]# salt ‘*‘ state.sls user.mysql env=prod

部署Nginx

[[email protected]~]# tree /srv/salt/prod/nginx/

/srv/salt/prod/nginx/

├── files

│   ├── nginx-1.9.6.tar.gz

│   └── nginx.init    ###启动脚本

└── install.sls

[[email protected]~]# tree /srv/salt/prod/cluster/

/srv/salt/prod/cluster/

├── files

│   ├── haproxy-outside.cfg

│   ├──haproxy-outside-keepalived.conf

│   └── nginx-web.conf       ##配置文件

├── haproxy-outside-keepalived.sls

├── haproxy-outside.sls

└── nginx-web.sls    ###管理配置文件

[[email protected]~]# cat /srv/salt/prod/nginx/install.sls

include:

  - pkg.pkg-init

 

nginx-install:

  file.managed:

    - name: /usr/local/src/nginx-1.9.6.tar.gz

    - source:salt://nginx/files/nginx-1.9.6.tar.gz

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: cd/usr/local/src && tar zxf nginx-1.9.6.tar.gz && cd nginx-1.9.6&&./configure --prefix=/usr/local/nginx --user=www --group=www--with-http_ssl_module --with-http_stub_status_module && make&& make install

    - unless: test -d/usr/local/nginx

    - pkg: pkg-init

    - file:nginx-install

 

nginx-init:

  file.managed:

    - name:/etc/init.d/nginx

    - source:salt://nginx/files/nginx.init

    - user: root

    - group: root

    - mode: 755

    - require:

      - cmd:nginx-install

  cmd.run:

    - name: chkconfig--add nginx

    - unless:chkconfig --list | grep nginx

    - require:

      - file:/etc/init.d/nginx

[[email protected]~]# cat /srv/salt/prod/cluster/nginx-web.sls

include:

  - nginx.install

 

nginx-service:

  file.managed:

    - name:/usr/local/nginx/conf/nginx.conf

    - source:salt://cluster/files/nginx-web.conf

 

  service.running:

    - name: nginx

    - enable: True

    - reload: True

    - require:

      - cmd:nginx-init

    - watch:

      - file:nginx-service

[[email protected]~]# cat /srv/salt/base/top.sls

base:

‘*‘:

- init.env_init

prod:

‘linux-node1.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

    -cluster.nginx-web

‘linux-node2.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

    -cluster.nginx-web

部署PHP

[[email protected]~]# tree /srv/salt/prod/php/

/srv/salt/prod/php/

├── files

│   ├── php-5.6.15.tar.gz

│   ├── php-fpm.conf   ###修改下启动用户为www

│   └── php.init

└── install.sls

[[email protected]~]# tree /srv/salt/prod/cluster/

/srv/salt/prod/cluster/

├── files

│   ├── haproxy-outside.cfg

│   ├──haproxy-outside-keepalived.conf

│   ├── nginx-web.conf

│   └── php.ini

├── haproxy-outside-keepalived.sls

├── haproxy-outside.sls

├── nginx-web.sls

└── php-web.sls

[[email protected]~]# cat /srv/salt/prod/php/install.sls

include:

  - pkg.pkg-init

 

php-install:

  file.managed:

    - name:/usr/local/src/php-5.6.15.tar.gz

    - source:salt://php/files/php-5.6.15.tar.gz

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: cd/usr/local/src/ && tar xf php-5.6.15.tar.gz && cd php-5.6.15&& ./configure --prefix=/usr/local/php --with-mysql --with-jpeg-dir--with-png-dir --with-zlib --enable-xml --with-libxml-dir --with-curl--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex--with-openssl --enable-mbstring --with-gd --enable-gd-native-ttf--enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug--enable-opcache --enable-zip --with-config-file-path=/usr/local/php/etc--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx && make&& make install

    - unless: test -d/usr/local/php

    - pkg: pkg-init

    - file:php-install

 

php-conf:

  file.managed:

    - name:/usr/local/php/etc/php-fpm.conf 

    - source:salt://php/files/php-fpm.conf   ###启动需要的文件

    - user: root

    - group: root

    - mode: 644

    - require:

      - cmd:php-install

 

php-init:

  file.managed:

    - name:/etc/init.d/php

    - source:salt://php/files/php.init    ###启动脚本

    - user: root

    - group: root

    - mode: 755

    - require:

      - cmd:php-install

 

  cmd.run:

    - name: chkconfig--add php

    - unless:chkconfig --list | grep php

    - require:

      - file:/etc/init.d/php

[[email protected]~]# cat /srv/salt/prod/cluster/php-web.sls

include:

  - php.install

 

php-service:

  file.managed:

    - name:/usr/local/php/etc/php.ini            ###配置文件

    - source:salt://cluster/files/php.ini

 

  service.running:

    - name: php

    - enable: True

    - reload: True

    - require:

      - cmd: php-init

    - watch:

      - file:php-service

[[email protected]~]# cat /srv/salt/prod/cluster/files/nginx-web.conf  ###需要修改,前期部署可以一下实现,可以根据不同的站点对业务配置管理

worker_processes  1;

events{

worker_connections  1024;

}

http{

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       8081;

server_name  www.reid.org;

        root   html/blog;

index index.php index.html index.htm;

    location ~ .*\.(php|php5)?$     ###支持PHP

    {

     fastcgi_pass  127.0.0.1:9000;

     fastcgi_index index.php;

     include fastcgi.conf;

    }

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

salt‘*‘ state.sls php.install env=prod test=True

salt‘*‘ state.sls php.install env=prod

salt‘*‘ state.higtstate

测试:

部署Memcached

[[email protected]~]#tree /srv/salt/prod/memcached/

/srv/salt/prod/memcached/

├── files

│   └── memcached-1.4.13.tar.gz

├── install.sls

├── memcached.sls

└── service.sls

[[email protected]~]# mkdir /srv/salt/prod/libevent/files -p

[[email protected]~]# mkdir /srv/salt/prod/memcached/files –p

安装libevent

[[email protected]~]# vim /srv/salt/prod/libevent/install.sls

libevent-source-install:

file.managed:

- name:/usr/local/src/libevent-1.4.13-stable.tar.gz

- source:salt://libevent/files/libevent-1.4.13-stable.tar.gz

- user: root

- group: root

- mode: 644

cmd.run:

- name: cd /usr/local/src && tarzxf libevent-1.4.13-stable.tar.gz && cd libevent-1.4.13-stable&& ./config

ure--prefix=/usr/local/libevent && make && make install

- unless: test -d /usr/local/libevent

- require:

- file: libevent-source-install

安装memcached

[[email protected]~]# vim /srv/salt/prod/memcached/install.sls

include:

- libevent.install

memcached-source-install:

file.managed:

- name: /usr/local/src/memcached-1.4.13.tar.gz

- source:salt://memcached/files/memcached-1.4.13.tar.gz

- user: root

- group: root

- mode: 644

cmd.run:

- name: cd /usr/local/src && tarzxf memcached-1.4.13.tar.gz && cd memcached-1.4.13 &&./configure --prefix

=/usr/local/memcached--enable-64bit --with-libevent=/usr/local/libevent && make &&make install

- unless: test -d /usr/local/memcached

- require:

- cmd: libevent-source-install

- file: memcached-source-install

启动memcached

[[email protected]~]# vim /srv/salt/prod/memcached/service.sls

include:

- memcached.install

- user.www

memcached.service:

cmd.run:

- name: /usr/local/memcached/bin/memcached-d -m 128 -p 11211 -c 8096 -u www

- unless: netstat -tnlp|grep 11211

- require:

- cmd: memcached-source-install

- user: www-user-group

在top file上定义

[[email protected]~]# vim /srv/salt/base/top.sls

base:

‘*‘:

- init.env_init

prod:

‘linux-node1.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

- cluster.nginx-web

- cluster.php-web

- cluster.mysql

    - memcached.service

‘linux-node2.example.com‘:

- cluster.haproxy-outside

- cluster.haproxy-outside-keepalived

- cluster.nginx-web

- cluster.php-web

- cluster.mysql

    - memcached.service

[[email protected]~]# netstat -ntlp|grep 11211

tcp        0     0 0.0.0.0:11211              0.0.0.0:*                   LISTEN      9485/memcached

tcp        0     0 :::11211                    :::*                       LISTEN      9485/memcached

[[email protected]~]#  netstat -ntlp|grep 11211

tcp        0     0 0.0.0.0:11211              0.0.0.0:*                   LISTEN      5137/memcached

tcp        0     0 :::11211                    :::*                        LISTEN      5137/memcached

PHP Memcache

[[email protected]~]# vim /srv/salt/prod/php/php-memcache.sls

memcache-plugin:

file.managed:

- name: /usr/local/src/memcache-2.2.5.tgz

- source: salt://php/files/memcache-2.2.5.tgz

- user: root

- group: root

- mode: 755

cmd.run:

- name: cd /usr/local/src && tarzxf memcache-2.2.5.tgz && cd memcache-2.2.5 &&/usr/local/php/bin/phpize &

&./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config&& make && make install

- unless: test -f/usr/local/php/lib/php/extensions/*/memcache.so

- require:

- file: memcache-plugin

/usr/local/php/etc/php.ini:

file.append:

- text:

- extension=memcache.so

部署MySQL(生产上不建议主从用salt部署)

[[email protected]~]# tree /srv/salt/prod/mysql/

/srv/salt/prod/mysql/

├── files

│   ├── my-medium.cnf      ##配置文件

│   ├── mysql-5.1.72.tar.gz   ##安装包

│   └── mysql.server  ###启动脚本

└── install.sls   ###安装文件

[[email protected]~]# cat /srv/salt/prod/mysql/install.sls

include:

- pkg.pkg-init

- user.mysql

mysql-install:

file.managed:

- name: /usr/local/src/mysql-5.1.72.tar.gz

- source:salt://mysql/files/mysql-5.1.72.tar.gz

- user: root

- group: root

- mode: 755

cmd.run:

- name: cd /usr/local/src && tar xfmysql-5.1.72.tar.gz && cd mysql-5.1.72 && ./configure--prefix=/usr/local/mysql--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/local/mysql/data--enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql--with-big-tables --without-debug --with-pthread --enable-assembler--with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server--enable-local-infile --with-plugins=partition,innobase--with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static &&make && make install

- unless: test -d /usr/local/mysql

- require:

- file: mysql-install

- pkg: pkg-init

mysql-data-dir:

file.directory:

- name: /usr/local/mysql/data

- user: mysql

- group: mysql

- require:

- user: mysql

cmd.run:

- name: cd /usr/local/mysql/bin/ &&./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/--user=mysql

- require:

- cmd: mysql-install

mysql-config-file:

file.managed:

- name: /etc/my.cnf

- source: salt://mysql/files/my-medium.cnf

- user: root

- group: root

- mode: 644

mysql-init:

file.managed:

- name: /etc/init.d/mysqld

- source: salt://mysql/files/mysql.server

- user: root

- group: root

- mode: 755

- require:

- cmd: mysql-install

- file: mysql-config-file

cmd.run:

- name: chkconfig --add mysqld

- unless: chkconfig --list | grep mysqld

- require:

- file: /etc/init.d/mysqld

service.running:

- name: mysqld

- enable: True

- require:

- file: /etc/init.d/mysqld

[[email protected]~]# salt ‘*‘ state.sls mysql.install env=prod

时间: 2024-10-25 07:14:35

saltstack实现中小型架构的搭建的相关文章

LAMP架构网站搭建

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台. 随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注. 目前LAMP架构是大多数中小企业最青睐的PHP架构选择,也是众多Linux SA喜欢选择

Linux:LNMP架构的搭建

LNMP架构的搭建 centos6.8-i686 MySQL PHP Nginx 搭建前先安装一些必要的rpm和php组件(全新系统) yum install -y wget gcc vim* libxml2 libxml2-devel openssl openssl-devel curl libcurl-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel mysql和lamp的M

Cisco PT模拟实验(21) 两层架构网络搭建的综合配置

Cisco PT模拟实验(21) 两层架构网络搭建的综合配置 实验目的: 熟悉网络的二层结构模型及原理 掌握路由交换的基本配置方法 掌握搭建两层架构网络的常用技术 实验背景: 情景:A公司企业网计划接入互联网,向 ISP申请了一条专线并拥有足够的公有IP地址,现要求搭建一个简易两层架构的企业内部网,具体构建需求如下: ①企业内网划分多个vlan ,减少广播域大小,提高网络稳定性 ②将用户网关配置在核心交换机上 ③搭建DHCP服务器,实现终端用户自动获取IP地址 ④在出口路由器上配置NAPT映射

LNMP架构的搭建

第9章 LNMP架构的搭建 9.1 什么是LNMP 9.1.1 LNMP的组成 L????????????????linux N????????????????nginx:实现静态的服务处理 M????????????????mysql/mariadb:实现数据的共享的存储 P????????????????php:实现动态的服务处理 9.2 LNMP的架构原理 9.2.1 LNMP图示讲解 9.2.2 文字进行讲解 用户将动态请求发送给web服务器,web服务器中的服务nginx没有办法进行处

Linux服务器集群架构部署搭建(四)WEB服务器LNMP/LAMP搭建部署及站点产品安装(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 集群WEB服务器LNMP生产应用 1.1 Nginx的应用场合:根据功能来进行应用 ①静态服务器(图片,视频服务)国内使用的只有两款,另一个是lighttpd.百度贴吧.豆瓣.html.js.css.flv等. ②动态服务:nginx+fastcgi的方式运行php.jsp.动态的并发很少(根据优化达到500-1500),

Angular05 angular架构、搭建angular开发环境、组件必备三要素、angular启动过程

1 angular架构 1.1 组件:是angular应用的基本构建模块,可以理解为一段带有业务逻辑和数据的HTML 1.2 服务:用来封装可重用的业务逻辑 1.3 指令:允许你想HTML元素添加自定义功能 1.4 模块:将应用中的不同部分组织成一个angular框架可以理解的单元 1.5 组件+服务+指令 = 模块 组件+服务+指令 是用来完成业务功能的:模块 是用来打包和分发的 2 开发环境搭建 2.1 安装node.js 很简单,百度即可 安装完后在我们的命令窗口中就可以使用 npm 命令

Linux服务器集群架构部署搭建(三)NFS文件系统、SSH通道建立、批量分发管理(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想.  作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 NFS共享服务器的企业应用 1.1 NFS服务--静态数据存储 NFS是(Network File System)主要功能是通过网络让不同的设备端之间可以彼此共享文件或目录.NFS客户端(一般为应用服务器,如WEB)可以通过挂载(mount)方式,将NFS客户端本地系统中(就是一个挂载点)从NFS服务器端共享的数据文件目

SpringMVC,Spring,Hibernate,Mybatis架构开发搭建之SpringMVC部分

辞职待业青年就是有很多时间来写博客,以前在传统行业技术强度相对不大,不处理大数据,也不弄高并发的,所以学不到什么高端编程技术和架构方法,那么我自己就琢磨搞一个SSH架构的东西出来,希望可以帮助到一些朋友,也希望大拿给出相应的指导意见. 先从用了什么东西说起吧 SSHM=SpringMVC+Spring+Hibernate+Mybatis,至于为什么要这么搞,我先简要的说下. SpringMVC 我最初的想法就是,它比struts2小,属于轻量级的MVC框架,而且和spring可以完美结合在一起.

Linux服务器企业集群架构部署搭建(一)----环境配置要求与系统基础优化

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 本文作者:燁未央_Estelle版权声明:测试学习,不足之处,欢迎指正.允许转载,转载时请务必以超链接形式标明文章原始出处.作者信息和本声明 第一章 集群架构搭建部署目标1.1 本次架构部署配置概况提示,本次集群架构所使用的服务器均为VM虚拟机进行模拟搭建测试及学习. ①两台linux服务器作为负载均衡服务器(LVS-01/LVS-02),基本模式:LVS-DR+keepalived.负责分发所