Saltstack推送httpd服务 与 nginx服务
作者:互联网
环境
server1(salt-master) | 172.25.60.1 |
---|---|
server2 (salt-minion) | 172.25.60.2 |
server3 (salt-minion) | 172.25.60.3 |
实验准备:
安装python-setproctitle.x86_64
重启服务:systemctl restart salt-master.service
推送apache
1.修改配置文件
[root@server1 salt]# vim /etc/salt/master ##注释647-650行
[root@server1 salt]# systemctl restart salt-master.service
2.server1创建需要的目录与文件
[root@server1 salt]# mkdir /srv/salt
[root@server1 salt]# cd /srv/salt
[root@server1 salt]# mkdir apache
[root@server1 salt]# cd apache/
[root@server1 apache]# vim install.sls
install-apache: ##安装服务
pkg.installed:
- pkgs:
- httpd
service-apache: ##开启服务
service.running:
- name: httpd
简单版install.sls v1.0 运行图省略 同v2.0
简单版install.sls v2.0
3.推送服务
[root@server1 apache]# salt server2 state.sls apache.install
4.检查salt-minion端服务开启情况
推送Nginx服务
1.创建nginx及所需目录
[root@server1 salt]# mkdir nginx
[root@server1 salt]# cd nginx/
[root@server1 nginx]# mkdir files
[root@server1 nginx]# cd ..
[root@server1 salt]# mkdir pkgs
2.在pkgs目录下编写install.sls
[root@server1 salt]# mkdir pkgs
[root@server1 salt]# cd pkgs/
[root@server1 pkgs]# vim install.sls
[root@server1 pkgs]# pwd
/srv/salt/pkgs
[root@server1 pkgs]# cat install.sls
nginx-make:
pkg.installed:
- pkgs:
- gcc
- make
- zlib-devel
- pcre-devel
3.拷贝软件包与文件模板到files目录下,并编写启动脚本 nginx.service
真机:
[root@foundation60 saltstack1_8.13_item8]# scp nginx-1.15.8.tar.gz server1:/srv/salt/nginx/files
root@172.25.60.1's password:
nginx-1.15.8.tar.gz 100% 1004KB 1.0MB/s 00:00
##172.25.60.21为安装过nginx的虚拟机:
root@server1 files]# scp root@172.25.60.21:/usr/local/nginx-1.15.8/conf/nginx.conf .
##server1:
[root@server1 files]# ls
nginx-1.15.8.tar.gz nginx.conf
[root@server1 files]# vim nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4.编写nginx目录写的intsall.sls文件
[root@server1 nginx]# vim install.sls
[root@server1 nginx]# cat install.sls
{% set nginx_version = '1.15.8'%} ##设置版本的变量
include:
- pkgs.install
install-nginx:
file.managed:
- name: /mnt/nginx-{{ nginx_version }}.tar.gz
- source: salt://nginx/files/nginx-{{ nginx_version }}.tar.gz
cmd.run:
- name: cd /mnt && tar zxf nginx-{{ nginx_version }}.tar.gz && cd nginx-{{ nginx_version }} && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx && make && make install
- creates: /usr/local/nginx
5.编写nginx目录下的服务启动文件service.sls
[root@server1 nginx]# vim service.sls
[root@server1 nginx]# pwd
/srv/salt/nginx
[root@server1 nginx]# cat service.sls
include:
- nginx.install
/usr/local/nginx/conf/nginx.conf:
file.managed:
- source: salt://nginx/files/nginx.conf
service-nginx:
file.managed:
- name: /usr/lib/systemd/system/nginx.service
- source: salt://nginx/files/nginx.service
service.running:
- name: nginx
- reload: True
- watch:
- file: /usr/local/nginx/conf/nginx.conf
服务开启方式1:
启动server3的nginx服务
salt server3 state.sls nginx.service
服务开启方式2:
使top.sls文件进行多任务的推送
[root@server1 salt]# ls
apache nginx pkgs top.sls zabbix
[root@server1 salt]# cat top.sls
base:
'server2':
- apache.install
'server3':
- nginx.service
启动方式:
salt ‘*’ state.highstate
标签:httpd,service,root,server1,sls,nginx,Saltstack,salt 来源: https://blog.csdn.net/vanvan_/article/details/99623170