原创:生机勃勃键化铺排百台服务器品级后端服

作者:电脑系统

齐天大圣的分脚本

原创:一键化部署百台服务器级别后端服务器,百台后端

在管理端一键部署nfs  rsync 并且实时同步  实现非密码非交互式一键部署

还会继续增加新的东西 未完待续

ip:管理 61 nfs 131 rsync 141 web 108

管理端 :

齐天大圣的总的脚本

[[email protected] tools]# cat quanwang.sh
#!/bin/bash
sh /server/scripts/piliangceshimiyao.sh
ansible-playbook /server/tools/rsyncpiliang.yml
ansible-playbook /server/tools/nfspiliang.yml
ansible-playbook /server/tools/quanwang.yml

齐天大圣的分脚本

1./server/scripts/piliangceshimiyao.sh

 

[[email protected] tools]# cat /server/scripts/piliangceshimiyao.sh
#!/bin/bash
#生成密钥
rm -f /root/.ssh/id_dsa*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q

#发送密钥
for ip in 61 108 131 141
do
echo "==== 现在分发 172.16.1.$ip=========="
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no [email protected]$ip"
echo "==============end======="
echo
echo
done

 

2.ansible-playbook /server/tools/rsyncpiliang.yml

 

[[email protected] tools]# cat ansible-playbook /server/tools/rsyncpiliang.yml
cat: ansible-playbook: No such file or directory

  • hosts: 172.16.1.141 #服务端
    tasks:
  • name: yum
    shell: yum install -y rsync #安装rsync
  • name: yunm
    shell: yum -y install sshpass #安装密钥的软件
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi
    copy: src=/server/tools/peizhi.sh dest=/server/tools/peizhi.sh
  • name: yunxing
    script: /server/tools/peizhi.sh #运行脚本
  • name: guanliyunhu
    shell: useradd -s /sbin/nologin -M rsync #创建rsync虚拟用户
  • name: anquanwenjian
    shell: echo "rsync_backup:oldboy123" >/etc/rsync.password #设置密码文件
  • name: quanxian
    shell: chmod 600 /etc/rsync.password #给予权限
  • name: beifenmulu
    shell: mkdir -p /backup && chown -R rsync.rsync /backup
  • name: qidong
    shell: rsync --daemon #运行rsync
  • hosts: 172.16.1.108
    tasks:
  • name: yum
    shell: yum install -y rsync # 客户端
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/
  • name: mimawenjian
    shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password
  • hosts: 172.16.1.131
    tasks:
  • name: yum
    shell: yum install -y rsync #客户端
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/
  • name: mimawenjian
    shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password

 

 

3.ansible-playbook /server/tools/nfspiliang.yml

 

- hosts: 172.16.1.131 #服务端
tasks:

  • name: yum
    shell: yum install -y nfs-utils rpcbind #安装nfs
  • name: yunm
    shell: yum -y install sshpass #安装密钥的软件
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi
    copy: src=/server/tools/nfspeizhi.sh dest=/server/tools/nfspeizhi.sh
  • name: yunxingjiaoben
    script: /server/tools/nfspeizhi.sh #运行脚本
  • name: guanlimulu
    shell: mkdir -p /data && chown -R nfsnobody.nfsnobody /data
  • name: qidong
    shell: /etc/init.d/rpcbind start && /etc/init.d/nfs start #启动
  • name: kaijiqidong
    shell: chkconfig rpcbind on && chkconfig nfs on
    #设置密码文件
  • hosts: 172.16.1.108
    tasks:
  • name: yum
    shell: yum install -y nfs-utils rpcbind # 客户端
    # - name: gui
    # shell: umount -f /mnt
  • name: guazai
    shell: mount -t nfs 172.16.1.131:/data /mnt
  • hosts: 172.16.1.141
    tasks:
  • name: yumh
    shell: yum install -y nfs-utils rpcbind #客户端
    # - name: guih
    # shell: umount -f /mnt
  • name: guazaih
    shell: mount -t nfs 172.16.1.131:/data /mnt

 

4.ansible-playbook /server/tools/quanwang.yml

 

 

- hosts: 172.16.1.61
tasks:
# - name: anzhuangrsync
# shell: /server/scripts/piliangceshimiyao.sh
# - name: anzhuangrsync
# shell: /server/tools/rsyncpiliang.yml
# - name: anzhuangnfs
# shell: /server/tools/nfspiliang.yml

  • hosts: 172.16.1.141
    tasks:
  • name: chuangjianmulu141
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi141
    copy: src=/server/tools/quanwangrsync.sh dest=/server/tools/quanwangrsync.sh
  • name: rsyncdajian141
    script: /server/tools/quanwangrsync.sh
  • hosts: 172.16.1.108
    tasks:
  • name: chuangjianmulu108
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi108
    copy: src=/server/tools/quanwangweb.sh dest=/server/tools/quanwangweb.sh
  • name: quanwangweb108
    script: /server/tools/quanwangweb.sh
  • hosts: 172.16.1.131
    tasks:
  • name: chuangjianmulu131
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi131
    copy: src=/server/tools/quanwangnfs.sh dest=/server/tools/quanwangnfs.sh
  • name: quanwangnfs.sh131
    script: /server/tools/quanwangnfs.sh

 

经历的错误

美高梅手机登录网站 1

是因为在剧本里运行剧本的原因

 

美高梅手机登录网站 2

 

 是以为我创建了rsync这个用户  所以报错没办法创建

 

美高梅手机登录网站 3

 

 是因为我没有给61管理端也发密钥

 

在管理端一键部署nfs rsync 并且实时同步 实现非密码非交互式一键部署 还会继续增...

  • hosts: 172.16.1.141
    tasks:
  • name: chuangjianmulu141
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi141
    copy: src=/server/tools/quanwangrsync.sh dest=/server/tools/quanwangrsync.sh
  • name: rsyncdajian141
    script: /server/tools/quanwangrsync.sh
  • hosts: 172.16.1.108
    tasks:
  • name: chuangjianmulu108
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi108
    copy: src=/server/tools/quanwangweb.sh dest=/server/tools/quanwangweb.sh
  • name: quanwangweb108
    script: /server/tools/quanwangweb.sh
  • hosts: 172.16.1.131
    tasks:
  • name: chuangjianmulu131
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi131
    copy: src=/server/tools/quanwangnfs.sh dest=/server/tools/quanwangnfs.sh
  • name: quanwangnfs.sh131
    script: /server/tools/quanwangnfs.sh

美高梅手机登录网站 4

是因为在剧本里运行剧本的原因

 

 是因为我没有给61管理端也发密钥

- hosts: 172.16.1.131 #服务端
tasks:

 

3.ansible-playbook /server/tools/nfspiliang.yml

 

- hosts: 172.16.1.61
tasks:
# - name: anzhuangrsync
# shell: /server/scripts/piliangceshimiyao.sh
# - name: anzhuangrsync
# shell: /server/tools/rsyncpiliang.yml
# - name: anzhuangnfs
# shell: /server/tools/nfspiliang.yml

4.ansible-playbook /server/tools/quanwang.yml

ip:管理 61 nfs 131 rsync 141 web 108

 是以为我创建了rsync这个用户  所以报错没办法创建

美高梅手机登录网站 5

 

 

 

 

1./server/scripts/piliangceshimiyao.sh

 

#发送密钥
for ip in 61 108 131 141
do
echo "==== 现在分发 172.16.1.$ip=========="
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@172.16.1.$ip"
echo "==============end======="
echo
echo
done

美高梅手机登录网站 6

 

还会继续增加新的东西 未完待续

齐天大圣的总的脚本

2.ansible-playbook /server/tools/rsyncpiliang.yml

  • name: yum
    shell: yum install -y nfs-utils rpcbind #安装nfs
  • name: yunm
    shell: yum -y install sshpass #安装密钥的软件
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi
    copy: src=/server/tools/nfspeizhi.sh dest=/server/tools/nfspeizhi.sh
  • name: yunxingjiaoben
    script: /server/tools/nfspeizhi.sh #运行脚本
  • name: guanlimulu
    shell: mkdir -p /data && chown -R nfsnobody.nfsnobody /data
  • name: qidong
    shell: /etc/init.d/rpcbind start && /etc/init.d/nfs start #启动
  • name: kaijiqidong
    shell: chkconfig rpcbind on && chkconfig nfs on
    #设置密码文件
  • hosts: 172.16.1.108
    tasks:
  • name: yum
    shell: yum install -y nfs-utils rpcbind # 客户端
    # - name: gui
    # shell: umount -f /mnt
  • name: guazai
    shell: mount -t nfs 172.16.1.131:/data /mnt
  • hosts: 172.16.1.141
    tasks:
  • name: yumh
    shell: yum install -y nfs-utils rpcbind #客户端
    # - name: guih
    # shell: umount -f /mnt
  • name: guazaih
    shell: mount -t nfs 172.16.1.131:/data /mnt

 

[root@m01 tools]# cat /server/scripts/piliangceshimiyao.sh
#!/bin/bash
#生成密钥
rm -f /root/.ssh/id_dsa*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q

 

管理端 :

 

 

 

经历的错误

[root@m01 tools]# cat ansible-playbook /server/tools/rsyncpiliang.yml
cat: ansible-playbook: No such file or directory

[root@m01 tools]# cat quanwang.sh
#!/bin/bash
sh /server/scripts/piliangceshimiyao.sh
ansible-playbook /server/tools/rsyncpiliang.yml
ansible-playbook /server/tools/nfspiliang.yml
ansible-playbook /server/tools/quanwang.yml

在管理端一键部署nfs  rsync 并且实时同步  实现非密码非交互式一键部署

 

  • hosts: 172.16.1.141 #服务端
    tasks:
  • name: yum
    shell: yum install -y rsync #安装rsync
  • name: yunm
    shell: yum -y install sshpass #安装密钥的软件
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/ #创建所在配置的文件
  • name: peizhi
    copy: src=/server/tools/peizhi.sh dest=/server/tools/peizhi.sh
  • name: yunxing
    script: /server/tools/peizhi.sh #运行脚本
  • name: guanliyunhu
    shell: useradd -s /sbin/nologin -M rsync #创建rsync虚拟用户
  • name: anquanwenjian
    shell: echo "rsync_backup:oldboy123" >/etc/rsync.password #设置密码文件
  • name: quanxian
    shell: chmod 600 /etc/rsync.password #给予权限
  • name: beifenmulu
    shell: mkdir -p /backup && chown -R rsync.rsync /backup
  • name: qidong
    shell: rsync --daemon #运行rsync
  • hosts: 172.16.1.108
    tasks:
  • name: yum
    shell: yum install -y rsync # 客户端
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/
  • name: mimawenjian
    shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password
  • hosts: 172.16.1.131
    tasks:
  • name: yum
    shell: yum install -y rsync #客户端
  • name: chuangjianmulu
    shell: mkdir -p /server/tools/
  • name: mimawenjian
    shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password

本文由美高梅4858官方网站发布,转载请注明来源

关键词: