In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Today, I try to use ansible to automate the compilation and installation of the lnmp environment, so as to share my opinions with you, and I hope you will correct your shortcomings.
The composition of lnmp
Lnmp = linux + nginx + mysql + php/python/perl
Now I will introduce to you my installation steps.
System: linux7
First download the modules required for the lnmp environment and create the ansible role
# mkdir-pv / tmp/roles/ {mysql,php,nginx} / {files,vars,templates,tasks,handlers,meta}
# cd / tmp/roles/mysql/
Step 1: install mysql, the version I installed is 5.6.x
Write a script
Vim / tmp/roles/mysql/files/mysql.sh
#! / bin/bashmount-o loop / dev/sr0 / yumyum clean allyum list# Import the dependency package yum install cmake* gcc gcc-c++ ncurses-devel perl libxml* libcurl* libjpeg* libpng* freetype*sleep 1 needed for the lnmp environment. Extract the mysql package tar xzf / root/Downloads/bag/11-mysql-5.6.26.tar.gz-C / usr/srccd / usr/src/mysql-5.6.26cmake. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=gbk,gb2312-DENABLED_LOCAL_INFILE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 & & make & & make install# after installation, write mysql configuration file # 1 Manually write the my.cnf configuration file mkdir / usr/local/mysql/etccat > / usr/local/mysql/etc/my.cnf load balance, LNMP) / Nginx- package / bag dest=/root/Downloads/ tags:-tar- name: copy mysql.sh to dbserver copy: src=mysql.sh dest=/tmp/- name: bash mysql.sh shell: / bin/bash / tmp/mysql.sh tags:-sh- name: install configure template: src=mysql dest=/etc/init.d/mysql56 tags:-tem notify:-restarted mysql
Save exit
Create site.yml
# vim / tmp/site.yml
-hosts: dbserver remote_user: root roles:-mysql
At this point, the installation of the database is complete
Step 2: install PHP. I'm installing version 5.6.x.
# cd / tmp/roles/php/
Create yml
# touch tasks/main.yml handlers/main.yml vars/main.yml
Write a script
Vim files/php.sh
#! / bin/bash# install a large module # 1, install libiconv-1.13.tar.gz-language transcoding install_libiconv () {tar xzf / root/Downloads/bag/4-libiconv-1.13.tar.gz-C / usr/srccd / usr/src/libiconv-1.13/./configure & & make & & make installecho / usr/local/lib > / etc/ld.so.conf.d/lnmp.conf/sbin/ldconfig} # 2. Install mhash-0.9.9.9.tar.bz2install_mhash-0.9.9.9 () {tar xf / root/Downloads/bag/7-mhash-0.9.9.9.tar.bz2-C / usr/src cd / usr/src/mhash-0.9.9.9/. / configure & & make & & make install / sbin/ldconfig} # 3. Install libmcrypt-2.5.8.tar.bz2install_libmcrypt-2.5.8 () {tar xf / root/Downloads/bag/5-libmcrypt-2.5.8.tar.bz2-C / usr/src cd / usr/src/libmcrypt-2.5.8/. / configure & & make & & make install / sbin/ldconfig} # 4. Install mcrypt-2.6.6.tar.gzinstall_mcrypt-2.6.6 () {tar xzf / root/Downloads/bag/6-mcrypt-2.6.6.tar.gz-C / usr/src cd / usr/src/mcrypt-2.6.6. / configure & & make & & make install / sbin/ldconfig} # 5. Install pcre-7.9.tar.gz--perl compatible regular expressions-- or use (yum install pcre pcre-devel-y) install_pcre-7.9 () {tar xzf / root/Downloads/bag/8-pcre-7.9.tar.gz-C / usr/src/ cd / usr/src/pcre-7.9/. / configure & & make & & make install / sbin/ldconfig} # 6. Compile and install phpinstall_php () {tar xf / root/Downloads/bag/12-php-5.6.12.tar.bz2-C / usr/src/ cd / usr/src/php-5.6.12/ ln-s / usr/local/mysql/lib/libmysqlclient.so / usr/lib/ ln-s / usr/local/mysql/lib/libmysqlclient.so.18 / usr/lib/libmysqlclient.so.18 echo'/ usr/local/lib' > > / Etc/ld.so.conf / sbin/ldconfig. / configure-prefix=/usr/local/php/-with-config-file-path=/usr/local/php/etc-with-mysql=/usr/local/mysql-with-mysqli=/usr/local/mysql/bin/mysql_config-with-iconv-dir=/usr/local-with-freetype-dir-with-jpeg-dir-with-png-dir-with-zlib-with-libxml-dir=/usr -- enable-xml-- disable-rpath-- enable-bcmath-- enable-shmop-- enable-sysvsem-- enable-inline-optimization-- with-curl-- enable-mbregex-- enable-fpm-- enable-mbstring-- enable-ftp-- with-gd-- enable-gd-native-ttf-- with-openssl-- with-mhash-- enable-pcntl-- enable-sockets-with-xmlrpc-- enable-zip-- enable-soap-- with-gettext-- enable-mysqlnd -with-pcre-dir=/usr/local/-with-mcrypt=/usr/local/-with-pdo-mysql=/usr/local/mysql-enable-opcache=no & & make ZEND_EXTRA_LIBS='-liconv' & & make install} # 7. Install the cache module memcacheinstall_memcache () {tar xf / root/Downloads/bag/10-memcache-2.2.7.tgz-C / usr/src/ cd / usr/src/memcache-2.2.7/ / usr/local/php/bin/phpize. / configure-- with-php-config=/usr/local/php/bin/php-config & & make & & make install echo / usr/src/memcache-2.2.7/modules/ > > / etc / ld.so.conf.d/lnmp.conf / sbin/ldconfig} # 8. Install the drawing engine module p_w_picpathmagick, similar to GD install_p_w_picpathmagick () {tar xzf / root/Downloads/bag/2-ImageMagick-6.7.8-9.tar.gz-C / usr/src/ cd / usr/src/ImageMagick-6.7.8-9 /. / configure make;make install / sbin/ldconfig} # 9. Install imagick (the channel that connects php to p_w_picpathmagick) install_imagick () {tar xf / root/Downloads/bag/3-imagick-3.1.2.tgz-C / usr/src/ cd / usr/src/imagick-3.1.2/ / usr/local/php/bin/phpize. / configure-- with-php-config=/usr/local/php/bin/php-config make Make install echo / usr/src/imagick-3.1.2/modules > > / etc/ld.so.conf.d/lnmp.conf / sbin/ldconfig} install_libiconv & & install_mhash-0.9.9.9 & & install_libmcrypt-2.5.8 & & install_mcrypt-2.6.6 & & install_pcre-7.9 & & install_php & & install_memcache & & install_p_w_picpathmagick & & install_imagick & & cp / usr/src/php -5.6.12/php.ini-production / usr/local/php/etc/php.ini
Note: if the PHP version is less than 5.6, you need to install php cache accelerator opcache.
Edit task
# vim tasks/main.yml
-name: copy shell copy: src=php.sh dest=/tmp/- name: bash shell shell: / bin/bash / tmp/php.sh- name: install configure template: src=php.ini dest=/usr/local/php/etc/php.ini tags:-ini
Add roles to site.yml
# vim / tmp/site.yml
-hosts: dbserver remote_user: root roles:-mysql-php
At this point, you can complete the installation of PHP
Step 3: compile and install nginx, version 1.13.x
# cd / tmp/roles/nginx
Write a script
# vim files/nginx.sh
Install_nginx () {# New nginx user useradd nginxtar xzf / root/Downloads/bag/1-nginx-1.8.1.tar.gz-C / usr/srccd / usr/src/nginx-1.8.1/./configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_gzip_static_module-- with-http_stub_status_module-- with-http_ssl_module & & make & & make install} install_nginx# configure php -fpm configuration file (configuration fastcgi) mv / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.confmkdir / var/run/fastcgichown nginx.nginx / var/run/fastcgi/mkdir / lnmp/web-pulimit-SHn 65535 > > / etc/rc.local
Create a yml file
# touch tasks/main.yml handlers/main.yml vars/main.yml
Create a task
# vim tasks/main.yml
-name: copy shell copy: src=nginx.sh dest=/tmp/- name: bash shell shell: / bin/bash / tmp/nginx.sh- name: change php-fpm.conf template: src=php-fpm.conf dest=/usr/local/php/etc/php-fpm.conf- name: change nginx.conf template: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf- name: change files open command: ulimit-SHn 65535
Add tasks to site.yml
# vim / tmp/site.yml
-hosts: dbserver remote_user: root roles:-mysql-php-nginx
Finally, execute ansible-playbook / tmp/site.yml
The implementation process takes a long time, so you need to wait patiently. At this point, the lnmp environment for ansible automation has been successfully completed.
The above are personal building steps, some of which are not written down, such as the configuration of the template, after all, the configuration of the template we need is different.
If you have any better suggestions, please leave your precious words, thank you.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.