1th ChapterThinking1.1How to use one clickAnsibleBuild1.1.1First Step goal
The first thing we want to make clear is that we need to implement a one-click Automation script that executes a script and then automates the installation of Nfs+rsync+sersync andthen lets web01 automatically mount the NFS shared directory.
1.1.2Second step relationship clear and sequential
Now that we have a goal, what we need to do is we need to understand the sequencing of automated installations.
-
since we need Ansible ansible
-
installed ansible Nfs share, and rsync backup. The peer
-
was installed Nfs and rsync Sersync
-
after we've installed it, the last thing we do is need WEB01 client mount
- 1.3Ansible
Ansible is based on the Ssh-key. So we need ssh key login without password. But if you want a non-interactive key authentication login then we need to Sshpass and this package is ansible to provide (also can be directly yum installed), and if you want to install ansible So it is clear that Ansible is based on the Erel source, so the steps are as follows
Epel
Yum Ansible
Secret key authentication
Installing ansible
Modifying a configuration file
Determine if management is successful
- 1.4Rsync
Rsync is a backup transfer, and his installation only needs to install rsync, create profiles, create password files, create users, modify permissions, start rsync
1.1.5Nfs
the need to be clear here is that NFS is based on Rpcbind , so we need to install the Rpcbind+nfs first , and then we need to clear the principle that NFS boot needs to find Rpcbind, to implement, so we need to start the Rpcbind first, at the start of NFS
1.1.6Sersync
to implement Sersync need to have this package, so we directly in the script RZ , but the system is not with the RZ command by default so we need to install Lrzsz first (I have my own RZ command for system optimization ). The configuration file is then modified to run in the background.
1.1.7web01
here web01 just as a client so we just hang on to him just fine and don't need anything else
2nd ChapterDeployment Installation2.1Catalog Specification
Script |
/server/scripts |
Install package |
/opt/src |
installation directory |
/usr/local |
Ansible 's yml file |
/etc/ansible/yml |
2.2Execution Process
just need to execute install.sh .
2.3the creation of each script2.3.1Installscript (only need to execute this script just fine)
#!/bin/bsh
SH automatic_deployment_ansible.sh
Mkdir-p/OPT/SRC
echo "Pleace rz rsync to/opt/src"
Cd/opt/src
Rz
if [-f/opt/src/ser*.tar.gz]
Then
Mkdir/etc/ansible/yml
Cd/etc/ansible/yml
Rz
echo "Pleace input you install.yml,"
Ansible-playbook index.yml
Else
echo "You can not true Sersync to/opt/src tryagent"
Fi
2.3.2installationAnsibleScript
#!/bin/bash
#just prevent you have SSH key
rm-rf/root/.ssh/id_dsa* >>/dev/null2>&1
Ssh-keygen-t dsa-f/root/.ssh/id_dsa-p "" >>/dev/null 2>&1
#加载repo源
Wget-o/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo && \
#all can ssh each other
Yum install ansible-y >>/dev/null2>&1 && \
echo "Install Ansible"
#judge you ansible install
If ["' Rpm-qa | Grep-o ansible ' "= =" Ansible "]
Then
For IP in web01 rsync nfs01
Do
sshpass-p123456 ssh-copy-id-i/root/.ssh/id_dsa.pub "-ostricthostkeychecking=no [email protected] $ip" >>/dev/ Null 2>&1
#justfor you determine whether distribution of success of SSH
Export a=$ (ssh $ip Hostname-i|awk ' {print $ | $ ')
Export b=$ (cat/etc/hosts | grep $ip | awk ' {print $} ')
Done
if [["$b" =~ $a]]
Then
#insert you group of ansible
# read-p "Pleaceinsert you ansible group name:" Grop
# read-p "Pleaceinsert The name of the group just like one ...:" Arg
Cat >> eof<</etc/ansible/hosts
[LS]
Web01
Nfs01
Rsync
Eof
#judge You can useansible
Ansible ls-m command-a "hostname" 2>>/var/log/ansible.log
If [$?-ne 0]
Then
echo "Error:you can not use Ansible,pleace see/var/log/ansible.log"
Else
echo "congratulations!! You ansible successful! And now you can do youwant "
Fi
Else
echo "You Fenfa Falit"
Fi
Else
echo "Error:you can not install Ansible"
Fi
2.3.3Ymlfiles for batch installation
---
-Hosts:ls #$ (tail/etc/ansible/hosts | sed-rn ' s#^\[(. *) \]$#\1#GP ')
Tasks
-Name:copy
Copy:src=/etc/hosts dest=/etc/hosts
-Hosts:rsync
Tasks
-Name:install rsync
script:/server/scripts/automatic_deployment_rsync.sh
-Hosts:nfs01
Tasks
-Name:install Nfs01
script:/server/scripts/automatic_deployment_nfs.sh
-Hosts:nfs01
Tasks
-Name:copy Sersync
COPY:SRC=/OPT/SRC dest=/opt/
-Name:install Sersync
script:/server/scripts/automatic_deployment_sersync.sh
-HOSTS:WEB01
Tasks
-Name:mount
Command:mount 172.16.1.31:/backup/mnt
2.3.4installationRsyncScript
#!/bin/bash
#if Install Rsync
Dir=/etc/rsyncd
#if install already and start we neet to stop Rsyncand RM pid file
Ps-ef | grep rsync | Awk-f "" ' {print$2} ' >>/dev/null 2<&1
Rm-rf/var/run/rsyncd.pid
#i need Create configuration directory
Mkdir-p $dir
# Determine whether the installation rsync
If ["' Rpm-qa | Grep-o rsync ' "! =" Rsync "]
Then
Yum install rsync-y >>/dev/null 2>&1
If ["' Rpm-qa | Grep-o rsync ' "! =" Rsync "]
Then
echo "Can not install rsync pleace See you Network"
Fi
Fi
#Enter the Directory
CD $dir
#Create a configuration file
Cat >eof << rsyncd.conf
UID = rsync
GID = rsync
Use Chroot =no
MaxConnections = 200
Timeout =300
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
Log file =/var/log/rsyncd.log
[Backup]
Path =/backup/
Ignoreerrors
Read Only =false
List = False
Hosts allow= 172.16.1.0/24
Hosts Deny =0.0.0.0/32
Auth Users =rsync_backup
Secrets file=/etc/rsyncd/password
Eof
#Determine whether a user
user= ' ID rsync '
If [$?-eq 0]
Then
Chown-rrsync.rsync/etc/rsyncd
Else
Useradd-s/sbin/nologin-m rsync
Fi
#Create a password file
echo "rsync_backup:123456" >/etc/rsyncd/password
#give Permissions Password file
chmod 600/etc/rsyncd/password
Chown Root.root $dir/password
Mkdir-p/backup >>/dev/null 2>&1
Chown Rsync.rsync/backup
#start rsync
rsync--daemon--config= $dir/rsyncd.conf
2.3.5installationSersyncScript
#!/bin/bash
Sedir=/usr/local/sersync
Cd/opt/src
Mkdir-p/usr/local/sersync
TAR-ZXVF sersync*.tar.gz-c $sedir--strip-components 1 >>/dev/null 2>&1
echo "123456" > $sedir/passwd
chmod $sedir/passwd
Sed-i ' s#<localpathwatch= "/opt/tongbu" >#<localpathwatch= "/backup" > #g ' $sedir/confxml.xml
Sed-i ' s#<remote ip= "127.0.0.1" name= "tongbu1"/>#<remote ip= "rsync" name= "Backup"/> #g ' $sedir/ Confxml.xml
Sed-i ' S#<auth start= "false" users= "root" passwordfile= "/etc/rsync.pas"/>#<authstart= "true" users= "rsync_ Backup "passwordfile="/usr/local/sersync/passwd "/> #g ' $sedir/confxml.xml
CD $sedir
./sersync2-d-o confxml.xml >>/dev/null2>&1
2.4explanation
Here I am using install,sh to call ansible 's installation script, to install Ansible first , after installing and determining that there is no error, I call the execution of the index.yml . the Index.yml is the first copy of the Hosts file, then the installation call rsync installation script installation, after the call sersync installation script, install Sersync. After that, Yml lets ansible directly mount the directory that uses NFS to automatically share through web01 .
Deploying NFS+RSYNC+SERSYNC+WEB01 Automation mounts with Ansible automation