Article From:https://www.cnblogs.com/51wansheng/p/9063646.html

One, Ansible introduction

 ansibleIt is a new automatic operation and maintenance tool. Based on Python development, it combines the advantages of many operation and maintenance tools (puppet, Cfengine, chef, func, fabric), and realizes the functions of batch system configuration, batch program deployment, batch operation command and so on.
 ansibleIt is based on module work, and has no capacity to deploy in batches. The real batch deployment is the module that ansible runs, and ansible just provides a framework. It mainly includes:
(1)、Connect plug-in connection plugins: responsible for communicating with the monitored terminal;
(2)、host inventory:The host that specifies the operation is a configuration file that defines the host for monitoring.
(3)、Various modules core modules, command modules, custom modules;
(4)、The function of recording log and mail is completed by means of plug-ins.
(5)、playbook:When a script executes multiple tasks, it is not necessary to allow nodes to run multiple tasks at once.
 

 

Two, ansible working mechanism

  1 #!/bin/bash
  2 #####################################################
  3 #Create date 2018.4.10
  4 #Author: wansheng
  5 #Function: shell script install apache2.4
  6 #Email: 1447646759@qq.com 
  7 #System: Linux CentOS-7
  8 #####################################################
  9 
 10 if [ $UID -ne 0 ];then
 11         please use root user running script!!
 12         exit 1
 13 fi
 14 #Download the installation package 15 apache_name="https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.33.tar.gz"
 16 zlib_name="https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz"
 17 apr_name="https://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz"
 18 apr_util_name="https://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz"
 19 pcre_name="https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz"
 20 openssl_name="https://www.openssl.org/source/openssl-1.1.1-pre3.tar.gz"
 21 libxml2_name="http://distfiles.macports.org/libxml2/libxml2-2.9.7.tar.gz"
 22 #Install the package directory definition 23 apache_dir=`echo $apache_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 24 zlib_dir=`echo $zlib_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 25 pcre_dir=`echo $pcre_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2}'`
 26 openssl_dir=`echo $openssl_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 27 libxml2_dir=`echo $libxml2_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 28 apr_dir=`echo $apr_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 29 apr_util_dir=`echo $apr_util_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 30 
 31 ##################################Installation directory and directory of services in the directory and directory of services. 32 
 33 apache_install_dir=/server/application/${nginx_dir}
 34 apache_server_dir=/usr/local/apche
 35 [ ! -d /root/soft ] && mkdir -p /root/soft
 36 [ ! -d /server/application ] && mkdir -p /server/application
 37 
 38 package=(
 39 wget
 40 curl
 41 gcc
 42 gcc-c++
 43 libxml2-devel
 44 gd-devel
 45 GeoIP
 46 GeoIP-devel
 47 perl
 48 perl-devel
 49 perl-ExtUtils-Embed
 50 libxslt
 51 libxslt-devel
 52 lsof
 53 make
 54 tree
 55 lrzsz
 56 expat
 57 expat-devel
 58 lua
 59 lua-devel
 60 openssl
 61 openssl-devel
 62 )
 63 #Installation package 64 software=(
 65 $zlib_name
 66 $apache_name
 67 $pcre_name
 68 $openssl_name
 69 $libxml2_name
 70 $apr_name
 71 $apr_util_name
 72 )
 73 ############################################################################
 74 
 75 function apache_check(){
 76 if [ $? -ne 0 ];then
 77         echo $_
 78     echo "please check error!!!!!"
 79         exit 2
 80 fi
 81 }
 82 
 83 #########################################################
 84 function package_install(){
 85 yum -y groupinstall "Development Tools"
 86 for package_i in ${package[*]}
 87 do    
 88     rpm -ql $package_i
 89     if [ $? -ne 0 ];then
 90         yum -y install $package_i
 91         echo $package_i
 92     else
 93         continue    
 94     fi
 95 done
 96 cd /root/soft
 97 for software_i in ${software[*]}
 98 do
 99     echo $software_i
100     software_ls=`echo $software_i |awk -F"[/]" '{print $NF}'`
101         if [ -f $software_ls ];then
102                 tar zxvf $software_ls
103         else
104                 wget $software_i
105                 tar zxvf $software_ls
106         fi
107 done
108 }
109 #########################################################
110 function apr_install(){
111 if [ ! -d /usr/local/apr ];then
112     cd /root/soft/$apr_dir
113     ./configure --prefix=/usr/local/apr
114     apache_check
115     make
116     apache_check
117     make install
118     apache_check
119     cd /root/soft/$apr_util_dir
120     ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-crypto
121     apache_check
122     make
123     apache_check
124     make install
125     apache_check
126     echo 2222
127 else
128     echo 111
129 fi
130 }
131 function pcre_install(){
132 if [ ! -d /usr/local/pcre ];then
133         cd /root/soft/$pcre_dir
134         ./configure --prefix=/usr/local/pcre --enable-utf8
135         apache_check
136         make
137         apache_check
138         make install
139         apache_check
140     echo 2222
141 else
142     echo 111
143 fi
144 }
145 function apache_install(){
146 cd /root/soft/$apache_dir
147 ./configure \
148 --prefix=/server/application/apache-2.4 \
149 --with-apr=/usr/local/apr \
150 --with-apr-util=/usr/local/apr-util \
151 --with-pcre=/usr/local/pcre \
152 --with-z=/root/soft/zlib-1.2.11 \
153 --with-libxml2=/root/soft/libxml2-2.9.7 \
154 --with-ssl \
155 --with-curl \
156 --with-mpm=prefork \
157 --enable-so \
158 --enable-authnz-fcgi \
159 --enable-file-cache \
160 --enable-cache \
161 --enable-cache-disk \
162 --enable-cache-socache \
163 --enable-cgi \
164 --enable-rewrite \
165 --enable-mpms-shared \
166 --enable-proxy \
167 --enable-proxy-connect \
168 --enable-proxy-ftp \
169 --enable-proxy-http \
170 --enable-proxy-fcgi \
171 --enable-proxy-scgi \
172 --enable-proxy-express \
173 --enable-proxy-hcheck \
174 --enable-slotmem-shm \
175 --enable-slotmem-plain \
176 --enable-ssl \
177 --enable-ssl-staticlib-deps \
178 --enable-static-support \
179 --enable-static-htpasswd \
180 --enable-static-htdigest \
181 --enable-static-htdbm \
182 --enable-static-ab \
183 --enable-static-logresolve \
184 --enable-unixd \
185 --enable-expires \
186 --enable-authn-dbm \
187 --enable-lua \
188 --enable-luajit \
189 --libdir=/usr/lib64
190 apache_check
191 make
192 apache_check
193 make install
194 apache_check
195 }
196 function apache_optimize(){
197 ln -s /server/application/apache-2.4 /usr/local/apache
198 sed -i 's/#Server.*80/ServerName localhost:80/g' /server/application/apache-2.4/conf/httpd.conf
199 /usr/local/apache/bin/apachectl -k start
200 apache_check
201 ss -tunl|grep 80
202 curl -I -s http://127.0.0.1|awk NR==1
203 apache_check
204 echo -e "\033[32;1m Congratulations on the successful installation of \033[0m in Apache-2.4"
205 }
206 main(){
207 package_install
208 apr_install
209 pcre_install
210 apache_install
211 apache_optimize
212 }
213 main

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *