今天嘗試用ansible自動(dòng)化編譯安裝了lnmp環(huán)境,是以把自己的見解和大家分享,不足之處還望大家指正。
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比遼中網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式遼中網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋遼中地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。
lnmp的構(gòu)成
lnmp = linux + nginx + MySQL + php/python/perl
下面給大家介紹下我的安裝步驟
系統(tǒng):linux7
首先下載lnmp環(huán)境所需模塊,創(chuàng)建ansible角色
# mkdir -pv /tmp/roles/{mysql,php,nginx}/{files,vars,templates,tasks,handlers,meta}
# cd /tmp/roles/mysql/
第一步:安裝mysql,我安裝的版本是5.6.x
編寫腳本
vim /tmp/roles/mysql/files/mysql.sh
#!/bin/bash mount -o loop /dev/sr0 /yum yum clean all yum list #導(dǎo)入lnmp環(huán)境所需依賴包 yum install cmake* gcc gcc-c++ ncurses-devel perl libxml* libcurl* libjpeg* libpng* freetype* sleep 10 #解壓mysql壓縮包 tar xzf /root/Downloads/bag/11-mysql-5.6.26.tar.gz -C /usr/src cd /usr/src/mysql-5.6.26 cmake . -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 #安裝后,編寫mysql配置文件 #1,手動(dòng)編寫my.cnf配置文件 mkdir /usr/local/mysql/etc cat > /usr/local/mysql/etc/my.cnf << EOF [mysqld] port=3307 datadir=/data56 pid-file=/var/run/mysqld/mysql56.pid socket=/tmp/mysql.sock log-error=/var/log/mysqld/mysql56-err.log user=mysql [client] port=3307 socket=/tmp/mysql.sock EOF #2:創(chuàng)建mysql相關(guān)目錄,并修改權(quán)限 useradd -u 27 mysql mkdir /data56 /var/run/mysqld /var/log/mysqld chown mysql.mysql /data56 /var/run/mysqld /var/log/mysqld /usr/local/mysql/ -R #3:初始化數(shù)據(jù)庫 /usr/local/mysql/scripts/mysql_install_db --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --user=mysql #--拷貝服務(wù)啟動(dòng)腳本 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql56 cp /usr/local/mysql/bin/mysql /usr/bin/
保存退出
創(chuàng)建yml文件
touch tasks/main.yml handlers/main.yml vars/main.yml
編輯任務(wù)
vim tasks/main.yml
- name: copy tar copy: src=/run/media/zsy/KINGSTON/運(yùn)維資料/20-Nginx(web服務(wù)器、反向代理負(fù)>載均衡、LNMP)/Nginx-軟件包/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
保存退出
創(chuàng)建site.yml
#vim /tmp/site.yml
- hosts: dbserver remote_user: root roles: - mysql
至此完成數(shù)據(jù)庫的安裝
第二步:安裝PHP,我這安裝的是5.6.x版本
# cd /tmp/roles/php/
創(chuàng)建yml
# touch tasks/main.yml handlers/main.yml vars/main.yml
編寫腳本
vim files/php.sh
#!/bin/bash #安裝個(gè)大模塊 #1,安裝libiconv-1.13.tar.gz --語言編碼轉(zhuǎn)換 install_libiconv(){ tar xzf /root/Downloads/bag/4-libiconv-1.13.tar.gz -C /usr/src cd /usr/src/libiconv-1.13/ ./configure && make && make install echo /usr/local/lib > /etc/ld.so.conf.d/lnmp.conf /sbin/ldconfig } #2.安裝mhash-0.9.9.9.tar.bz2 install_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.安裝libmcrypt-2.5.8.tar.bz2 install_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.安裝mcrypt-2.6.6.tar.gz install_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.安裝pcre-7.9.tar.gz--perl兼容正則表達(dá)式,--或者使用rpm自帶的也可以(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.編譯安裝php install_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.安裝緩存模塊memcache install_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.安裝繪圖引擎模塊p_w_picpathmagick,與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.安裝imagick(連接php與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
注:如PHP版本小于5.6還需安裝php的緩存加速器opcache
編輯任務(wù)
#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
把角色加到site.yml中
#vim /tmp/site.yml
- hosts: dbserver remote_user: root roles: - mysql - php
至此可完成PHP的安裝
第三步:編譯安裝nginx,版本1.13.x
#cd /tmp/roles/nginx
編寫腳本
#vim files/nginx.sh
install_nginx(){ #新建nginx用戶 useradd nginx tar xzf /root/Downloads/bag/1-nginx-1.8.1.tar.gz -C /usr/src cd /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 #配置php-fpm配置文件 (配置fastcgi) mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf mkdir /var/run/fastcgi chown nginx.nginx /var/run/fastcgi/ mkdir /lnmp/web -p ulimit -SHn 65535 >> /etc/rc.local
創(chuàng)建yml文件
# touch tasks/main.yml handlers/main.yml vars/main.yml
創(chuàng)建任務(wù)
# 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
把任務(wù)加到site.yml中
# vim /tmp/site.yml
- hosts: dbserver remote_user: root roles: - mysql - php - nginx
最后執(zhí)行ansible-playbook /tmp/site.yml
執(zhí)行過程比較久,需耐心等待。至此ansible自動(dòng)化搭建lnmp環(huán)境圓滿結(jié)束。
以上屬個(gè)人搭建步驟,其中有些小步驟沒有寫上,如模版的配置,畢竟大家所需模版的配置不一。
如有更好的建議,請(qǐng)留下你珍貴的一言,謝謝。
網(wǎng)頁題目:ansible自動(dòng)化安裝lnmp
文章網(wǎng)址:http://aaarwkj.com/article38/gihgpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站收錄、動(dòng)態(tài)網(wǎng)站、響應(yīng)式網(wǎng)站、網(wǎng)站改版、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)