Purpose: Use the Saltstack tool to deploy batch servers and automate the installation (uninstall) of services (such as MySQL).
[[email protected] ~]# ll total dosage 304228-rw-r--r--1 root root 311516309 March mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz- Rwxr-xr-x 1 root root 6628 March 12:52 mysql_ binary installation. sh-rwxr-xr-x 1 root root 590 March 12:53 mysql_ binary Uninstall. sh[[e Mail protected] ~]#
1. View the master and Minion status.
Master |
Node2 |
192.168.1.221 |
Minion |
Node4 |
192.168.1.223 |
1.1) View the master status information:
[[email protected] ~]# netstat -atupn|grep --color -e ' 4505|4506 ' tcp 0 0 0.0.0.0:4505 0.0.0.0:* listen 2897/python2.6 tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 2915/python2.6 tcp 0 0 192.168.1.221:4505 192.168.1.223:58448 established 2897/python2.6 tcp 0 0 192.168.1.221:4506 192.168.1.223:53904 established 2915/python2.6 [[email protected] ~]#
1.2) View the current Salt key information (minion) I only configured one:
[Email protected] ~]# salt-key-laccepted keys:node4denied keys:unaccepted keys:rejected keys:[[email protected] ~]#
1.3) View Minion status information:
[[email protected] ~]# Salt ' node4 ' cmd.run ' netstat-atupn|grep python ' node4:tcp 0 0 192.168.1.223:53904 192.168.1.221:4506 established 2846/python2.6 TCP 0 0 192.168.1.223:58448 19 2.168.1.221:4505 established 2846/python2.6[[email protected] ~]#
1.4) Distribute shell scripts and packages and authorize:
1.4.1) commonly used CP Module introduction: (Other modules can see my other related blog)
Cp.get_file downloading directories from the master server
Cp.get_dir downloading files from the master server
Cp.get_url download the specified URL file from the server
[email protected] ~]# Salt ' node4 ' cp.get_file salt://mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz/root/ MYSQL-5.6.21-LINUX-GLIBC2.5-X86_64.TAR.GZNODE4:/root/mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz[[email protected ] ~]#[[email protected] ~]# salt ' node4 ' cp.get_file salt://mysql_install.sh/root/mysql_install.shnode4:/root/mysql_i Nstall.sh[[email protected] ~]# salt ' node4 ' cp.get_file salt://mysql_remove.sh/root/mysql_remove.shnode4:/root/MySQ L_remove.sh[[email protected] ~]#
1.4.2) Minion view;
[[email protected] ~]# ll total dosage 304232-rw-r--r--1 root root 311516309 March 14:06 mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz -rw-r--r--1 root root 6628 March 14:09 mysql_install.sh-rw-r--r--1 root root 590 March 14:10 mysql_remove.s H[[email protected] ~]#
1.4.3) script weighting:
[[email protected] ~]# Salt ' node4 ' cmd.run ' chmod +x/root/*.sh ' node4:[[email protected] ~]#
1.5) Script Installation:
[[email protected] ~]# salt ' node4 ' cmd.run '/root/mysql_install.sh ' node4: ? [37;32m start the installation of MySQL! ? [0m ? [37;32m mysql installation directory has been created! [/usr/local/mysql under] ? [0m ########################################################! ? [37;32m mysql required for user and group creation completed! ? [0m ########################################################! Installing MySQL requires a basic dependency package! [37;32m mysql needs the basic dependency package has been installed to complete! ? [0m ########################################################! Initialize mysql! ? [37;32m mysql initialization succeeded! ? [0m ########################################################! Change MySQL permissions belong to group permissions ? [37;32m change MySQL directory permissions group permissions successful! ? [0m ########################################################! Create and configure the MySQL startup file! [37;32m mysql boot file has been created configuration completed! ? [0m ########################################################! Import optimized my.cnf to/etc/under ? [37;32m mysql configuration file is ready! ? [0m ########################################################! Start the MySQL service ? [37;32m mysql service started successfully! ? [0m ########################################################! Configure the root account password for MySQL! [37;32m mysql root default account password is renzhiyuan ? [0m ########################################################! [[email protected] ~]#
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/8D/EE/wKioL1iv2Lbz90Q4AAAdlt58JhE197.png "title=" 2.png "alt=" Wkiol1iv2lbz90q4aaadlt58jhe197.png "/>
1.5.2) Uninstall:
[email protected] ~]# Salt ' node4 ' cmd.run '/root/mysql_remove.sh ' node4:? [37;32m start MySQL uninstall!? [0m ########################################################! ? [37;32m MySQL uninstall succeeded!? [0m ########################################################! [Email protected] ~]#
In fact, automation can be placed in a script batch execution, Bo master just for more convenient to share knowledge, it is a bit more written, welcome to correct.
This article is from "Never give up!" Ningzhiyuan "blog, declined reprint!
Saltstack+shell Automated Distribution scripts