ansible批量一鍵安裝lnmp環境
阿新 • • 發佈:2017-09-06
ansible批量 安裝 lnmp 部署
1、ansible一鍵安裝nginx服務
#nginx_server install - hosts: 172.16.1.5 根據自己的主機自行定義 tasks: -name: yumpcre-devel yum: name=pcre-devel -name: yum pcre yum: name=pcre -name: yumopenssl-devel yum: name=openssl-devel -name: yum openssl yum: name=openssl -name: create/home/tools/ file: dest=/home/tools/ state=directory -name: createuseradd ningx user: name=nginx createhome=no shell=/sbin/nologin -name: downloadnginx shell: cd /home/tools/ && wget http://nginx.org/download/nginx-1.6.3.tar.gz -name:decompression nginx shell: cd /home/tools/ && tar -xf nginx-1.6.3.tar.gz -name: Toconfigure nginx shell: cd /home/tools/nginx-1.6.3 && ./configure --user=nginx --group=nginx--prefix=/application/nginx-1.6.3/ --with-http_stub_status_module--with-http_ssl_module && make && make install -name: Softconnection file: src=/application/nginx-1.6.3/ dest=/application/nginxstate=link -name: start nginx shell:/application/nginx/sbin/nginx
2、ansible一鍵安裝mysql服務
#mysql_server install - hosts: 172.16.1.5 根據自己主機自行定義 tasks: -name: createuseradd mysql user: name=mysql createhome=no shell=/sbin/nologin -name: create/home/tools file: dest=/home/tools state=directory -name: downloadmysql file: cd /home/tools && wget https://downloads.mysql.com/archives/get/file/mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz -name:decompression nginx shell: cd /home/tools && tar -xf mysql-5.5.32-linux2.6-x86_64.tar -name: create file: dest=/application/ state=directory -name: move mysql shell: cd /home/tools && mvmysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32 -name: Softconnection file: src=/application/mysql-5.5.32/dest=/application/mysql state=link -name: copy conf shell: cd /application/mysql && cpsupport-files/my-small.cnf /etc/my.cnf -name: create/application/mysql/data file: dest=/application/mysql/data state=directoryowner=mysql group=mysql -name:Initialization mysql shell: /application/mysql/scripts/mysql_install_db--basedir=/application/mysql --datadir=/application/mysql/data --user=mysql -name: copy start_file shell: cd /application/mysql && cpsupport-files/mysql.server /etc/init.d/mysqld -name: Add executeauthority shell: chmod +x /etc/init.d/mysqld -name: replaceconfigure_file shell: sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe/etc/init.d/mysqld -name: start mysql shell: /etc/init.d/mysqld start -name: setenvironment variable shell: echo ‘exportPATH=/application/mysql/bin:$PATH‘>>/etc/profile -name: source/etc/profile shell: source /etc/profile
3、ansible一鍵安裝php服務
#php_server install - hosts: 172.16.1.5 根據自己主機自行定義 tasks: -name: yum rely on yum:name=zlib-devel,libxml2-devel,libjpeg-devel,libjpeg-turbo-devel,freetype-devel,libpng-devel,gd-devel,libcurl-devel,libxslt-devel -name: installlibiconv shell: cd /home/tools &&wget http://219.239.26.3/files/524500000A03C5BE/ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz -name: decompression libiconv shell: cd /home/tools &&tar -xf libiconv-1.14.tar.gz -name: Toconfigure libiconv shell: cd /home/tools/libiconv-1.14 && ./configure --prefix=/usr/local/libiconv && make && make install - name:epel shell: wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo -name: yumlibmcrypt-devel yum: name=libmcrypt-devel,mhash,mcrypt - name: downloadphp-5.3.27 shell: cd /home/tools/ && wget http://php.net/get/php-5.3.27.tar.gz/from/a/mirror -name: install php shell: cd /home/tools/ &&tar -xf php-5.3.27.tar.gz -name: softconnect shell: ln -s/application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ -name: createphar.phar shell: touch /home/tools/php-5.3.27/ext/phar/phar.phar -name: intophp-5.3.27 shell: cd /home/tools/php-5.3.27 && ./configure --prefix=/application/php5.3.27--with-mysql=/application/mysql --with-iconv-dir=/usr/local/libiconv--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization--with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring--with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags--enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx--with-fpm-group=nginx --enable-ftp && make && make install - name: Soft connection php5.3.27 shell: ln -s /application/php5.3 27 /application/php -name: copyphp.ini-production shell: cp /home/tools/php-5.3.27/php.ini-production/application/php/lib/php.ini -name: into/application/php/etc/ shell: cp /application/php/etc/php-fpm.conf.default/application/php/etc/php-fpm.conf -name: into/home/tools/php-5.3.27 shell: cp/home/tools/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm -name: Add executeauthority shell: chmod +x /etc/init.d/php-fpm -name: startphp-fpm shell: /etc/init.d/php-fpm start
本文出自 “每天一小步” 博客,請務必保留此出處http://fenyuer.blog.51cto.com/11265169/1963168
ansible批量一鍵安裝lnmp環境