安装就不写了
先把配置文件贴出来
vim /etc/salt/master
然后是目录树:
修改配置文件是为了把根目录设置成base
init目录是初始化服务器要做的所有操作都放在这个目录里面,init/files 目录放着了源码安装所需的所有文件,init-install.sls 是安装服务器所需的基础模块,python.sls是升级python相关的操作,init.sls是init目录的入口文件
init-install.sls内容:
# 修改yum源 yum-source-change: file.managed: - name: /opt/repo.tar.gz - source: salt://init/files/repo.tar.gz - mode: 755 - user: root - group: root cmd.run: - name: tar xf /opt/repo.tar.gz -C /etc/yum.repos.d/ - unless: -f /opt/repo.tar.gz - require: - file: yum-source-change # 安装基础模块 init-install: pkg.installed: - names: - gcc - gcc-c++ - zip - unzip - zlib - zlib-devel - openssl - openssl-devel - ntp - vim - yum-fastestmirror - openssh-clients - wget - rsync - cmake - lrzsz - xz - ntpdate - lsof - telnet - epel-release - tree - kernel-devel - kernel - ncurses-devel - libaio # 配置基础环境 localtime-change: cmd.run: - name: rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime - unless: -f /usr/share/zoneinfo/Asia/Shanghai # 添加开机启动 ntp-add-chkconfig: cmd.run: - name: chkconfig --add ntpd - unless: chkconfig --list | grep ntpd - require: - pkg: init-install
python.sls内容:
# 更新python2.6到python2.7.13版本 include: - init.init-install python-source-install: file.managed: - name: /usr/local/src/Python-2.7.13.tgz - source: salt://init/files/Python-2.7.13.tgz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src/ && tar xvf Python-2.7.13.tgz && cd Python-2.7.13 && ./configure && make && make install - unless: -d /usr/local/src/Python-2.7.13 - require: - pkg: init-install - file: python-source-install # 将系统默认的2.6改成2.7 python-change-version: cmd.run: - name: mv /usr/bin/python /usr/bin/python_old2 && cp /usr/local/src/Python-2.7.13/python /usr/bin/python - unless: -f /usr/bin/python - require: - cmd: python-source-install # 安装 distribute distribute-soruce-install: file.managed: - name: /usr/local/src/distribute-0.7.3.zip - source: salt://init/files/distribute-0.7.3.zip - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src/ && unzip -o distribute-0.7.3.zip && cd distribute-0.7.3 && python setup.py install - unless: -d /usr/local/src/distribute-0.7.3 - require: - file: distribute-soruce-install - cmd: python-change-version # 安装setuptools setuptools-soruce-install: file.managed: - name: /usr/local/src/setuptools-39.2.0.zip - source: salt://init/files/setuptools-39.2.0.zip - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src/ && unzip -o setuptools-39.2.0.zip && cd setuptools-39.2.0 && python setup.py install - unless: -d /usr/local/src/setuptools-39.2.0 - require: - file: setuptools-soruce-install - cmd: python-change-version # 安装pip pip-soruce-install: file.managed: - name: /usr/local/src/pip-18.0.tar.gz - source: salt://init/files/pip-18.0.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src/ && tar xf pip-18.0.tar.gz && cd pip-18.0 && python setup.py build && python setup.py install - unless: -d /usr/local/src/pip-18.0 - require: - file: pip-soruce-install - cmd: setuptools-soruce-install # 修复yum不能使用 yum-change-version: cmd.run: - name: sed -i 's#/usr/bin/python#/usr/bin/python2.6#g' /usr/bin/yum - unless: -f /usr/bin/yum - require: - cmd: python-source-install
init.sls内容:
include: - init.python - init.init-install
然后把源文件放到指定目录就可以安装了
在master上执行命令:
salt 'vps-test-001' state.highstate test=True 测试上面的内容是否正确
salt 'vps-test-001' state.highstate 单个服务器执行安装
salt '*' state.highstate 所有受控服务器执行安装
在minion上执行命令:
salt-call state.sls init
不同的系统版本有可能会出现基础模块没安装的情况,有报错请在init-install.sls中加入对应的模块名
第一章结束,下一章写iptables相关配置