参考https://chegva.com/794.html
包
[root@node1 prod]# cat cluster/fastdfs.sls include: - modules.fastdfs.install fastdfs-service: file.managed: - name: /etc/fdfs/storage.conf - source: salt://cluster/files/storage.conf - mode: 644 - user: root - group: root - template: jinja - IP: {{ grains['fqdn_ip4'] }} service.running: - name: fdfs_storaged - enable: True - reload: True - require: - cmd: fastdfs-source-install - watch: - file: fastdfs-service
[root@node1 modules]# for i in `find . -name "*.sls"`;do echo $i &&cat $i;done ./libfast/install.sls libfast-source-install: file.managed: - name: /usr/local/src/libfastcommon-1.0.7.tar.gz - source: salt://modules/libfast/files/libfastcommon-1.0.7.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar zxf libfastcommon-1.0.7.tar.gz && cd libfastcommon-1.0.7 && ./make.sh && ./make.sh install - unless: test -d /usr/local/src/libfastcommon-1.0.7 - require: - file: libfast-source-install ./fastdfs/install.sls include: - modules.pkg.make - modules.libfast.install fastdfs-source-install: file.managed: - name: /usr/local/src/FastDFS_v5.05.tar.gz - source: salt://modules/fastdfs/files/FastDFS_v5.05.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: mkdir -p /data/fastdfs && cd /usr/local/src && tar zxf FastDFS_v5.05.tar.gz && cd FastDFS && ./make.sh && ./make.sh install && sed -i 's%/usr/local/bin%/usr/bin%g' /etc/init.d/fdfs_storaged - unless: test -d /usr/local/src/FastDFS && test -d /data/fastdfs - require: - file: fastdfs-source-install - pkg: make-pkg fastdfs-init: cmd.run: - name: chkconfig --add fdfs_storaged - unless: chkconfig --list | grep fdfs_storaged - require: - cmd: fastdfs-source-install ./pkg/make.sls make-pkg: pkg.installed: - pkgs: - gcc - gcc-c++ - glibc - make - autoconf - openssl - openssl-devel - pcre - pcre-devel - gd - gd-devel - lua-devel
1.ln -s /data/fastdfs/data /data/fastdfs/data/M00
2.防火墙问题
单机两个storage,简单练练手
tracker 172.1.1.1 storage 172.1.1.2 test1 storage 172.1.1.3 test2 test1 部署1,2 test2 部署3,4 cd /srv/salt/pillar [root@node pillar]# cat test1.sls group_name1: group1 group_name2: group2 tracker_server: 172.1.1.1 base_path1: /data/group1 base_path2: /data/group2 store_path1: /data/grou1 store_path2: /data/group2 bind_addr: {{ grains['fqdn_ip4'][0] }} storage_server_port1: 23000 storage_server_port2: 23001 http_port1: 8080 http_port2: 8081 salt 'test1' saltutil.refresh_pillar cd /srv/salt/prod/modules/fastdfs [root@node fastdfs]# tree . ├── files │ ├── FastDFS_v5.05.tar.gz │ ├── fdfs_storaged │ ├── fdfs_storaged1 │ ├── fdfs_storaged2 │ ├── fdfs_storaged3 │ ├── fdfs_storaged4 │ ├── storage_1.conf │ ├── storage_2.conf │ ├── storage_3.conf │ └── storage_4.conf ├── installstorage.sls └── installtracker.sls [root@jk fastdfs]# cat installstorage.sls include: - modules.pkg.make - modules.libfast.install fastdfs-mkdir: cmd.run: - name: mkdir -p {{ pillar['base_path1'] }}/data && ln -s {{ pillar['base_path1'] }}/data {{ pillar['base_path1'] }}/data/M00 && mkdir -p {{ pillar['base_path2'] }}/data && ln -s {{ pillar['base_path2'] }}/data {{ pillar['base_path2'] }}/data/M00 fastdfs-source-install: file.managed: - name: /usr/local/src/FastDFS_v5.05.tar.gz - source: salt://modules/fastdfs/files/FastDFS_v5.05.tar.gz - user: root - group: root - mode: 644 cmd.run: - name: cd /usr/local/src && tar zxf FastDFS_v5.05.tar.gz && cd FastDFS && ./make.sh && ./make.sh install && sed -i 's%/usr/local/bin%/usr/bin%g' /etc/init.d/fdfs_storaged - unless: test -d /usr/local/src/FastDFS && test -d /data/fastdfs - require: - cmd: fastdfs-mkdir - file: fastdfs-source-install - pkg: make-pkg fastdfs-conf1: file.managed: {% if pillar['base_path1'] == '/data/group1' %} - name: /etc/fdfs/storage_1.conf - source: salt://modules/fastdfs/files/storage_1.conf - user: root - group: root - mode: 644 - template: jinja {% elif pillar['base_path1'] == '/data/group3' %} - name: /etc/fdfs/storage_3.conf - source: salt://modules/fastdfs/files/storage_23.conf - user: root - group: root - mode: 644 - template: jinja {% endif %} fastdfs-conf2: file.managed: {% if pillar['base_path2'] == '/data/group2' %} - name: /etc/fdfs/storage_2.conf - source: salt://modules/fastdfs/files/storage_2.conf - user: root - group: root - mode: 644 - template: jinja {% elif pillar['base_path2'] == '/data/group4' %} - name: /etc/fdfs/storage_4.conf - source: salt://modules/fastdfs/files/storage_4.conf - user: root - group: root - mode: 644 - template: jinja {% endif %} cd /srv/salt/prod/cluster [root@node cluster]# cat storage.sls include: - modules.fastdfs.installstorage fastdfs-service1: file.managed: {% if pillar['base_path1'] == '/data/group1' %} - name: /etc/init.d/fdfs_storaged1 - source: salt://modules/fastdfs/files/fdfs_storaged1 - user: root - group: root - mode: 755 {% elif pillar['base_path1'] == '/data/group3' %} - name: /etc/init.d/fdfs_storaged3 - source: salt://modules/fastdfs/files/fdfs_storaged3 - user: root - group: root - mode: 755 {% endif %} service.running: {% if pillar['base_path1'] == '/data/group1' %} - name: fdfs_storaged1 - enable: True - reload: True - require: - cmd: fastdfs-source-install - file: fastdfs-service1 - watch: - file: fastdfs-service1 {% elif pillar['base_path1'] == '/data/group3' %} - name: fdfs_storaged3 - enable: True - reload: True - require: - cmd: fastdfs-source-install - file: fastdfs-service1 - watch: - file: fastdfs-service1 {% endif %} fastdfs-init1: cmd.run: - name: chkconfig --add fdfs_storaged1 - unless: chkconfig --list | grep fdfs_storaged1 - require: - cmd: fastdfs-source-install - file: fastdfs-service1 fastdfs-init2: cmd.run: - name: chkconfig --add fdfs_storaged1 - unless: chkconfig --list | grep fdfs_storaged1 - require: - cmd: fastdfs-source-install - file: fastdfs-service1 fastdfs-service2: file.managed: {% if pillar['base_path2'] == '/data/group2' %} - name: /etc/init.d/fdfs_storaged2 - source: salt://modules/fastdfs/files/fdfs_storaged2 - group: root - mode: 755 {% elif pillar['base_path2'] == '/data/group4' %} - name: /etc/init.d/fdfs_storaged4 - source: salt://modules/fastdfs/files/fdfs_storaged4 - user: root - group: root - mode: 755 {% endif %} service.running: {% if pillar['base_path2'] == '/data/group2' %} - name: fdfs_storaged2 - enable: True - reload: True - require: - cmd: fastdfs-source-install - file: fastdfs-service2 - watch: - file: fastdfs-service2 {% elif pillar['base_path2'] == '/data/group4' %} - name: fdfs_storaged4 - enable: True - reload: True - require: - cmd: fastdfs-source-install - file: fastdfs-service2 - watch: - file: fastdfs-service2 {% endif %} fastdfs-init2: cmd.run: - name: chkconfig --add fdfs_storaged2 - unless: chkconfig --list | grep fdfs_storaged2 - require: - cmd: fastdfs-source-install - file: fastdfs-service2 fastdfs-init4: cmd.run: - name: chkconfig --add fdfs_storaged4 - unless: chkconfig --list | grep fdfs_storaged4 - require: - cmd: fastdfs-source-install - file: fastdfs-service2
就是简单的if elif endif。