原創:一鍵化部署百台伺服器層級後端伺服器,百台後端

來源:互聯網
上載者:User

原創:一鍵化部署百台伺服器層級後端伺服器,百台後端

在管理端一鍵部署nfs  rsync 並且即時同步  實現非密碼非互動式一鍵部署

還會繼續增加新的東西 未完待續

ip:管理 61 nfs 131 rsync 141 web 108

管理端 :

齊天大聖的總的指令碼

[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

齊天大聖的分指令碼

1./server/scripts/piliangceshimiyao.sh

 

[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


#發送密鑰
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

 

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

 

[root@m01 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

 

經曆的錯誤

是因為在劇本裡運行劇本的原因

 

 

 是以為我建立了rsync這個使用者  所以報錯沒辦法建立

 

 

 是因為我沒有給61管理端也發密鑰

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.