One-click lnmp installation script

Source: Internet
Author: User
Tags openldap

Some time ago, a friend needs to install lnmp on centos 6.5 x64 of a new server. He thinks that manual installation is time-consuming and he needs to write an installation script.


Later, I helped him write an lnmp_install.tar.gz with a size of 55.3 MB.

After decompression, there is a directory lnmp_install, which contains several required software packages.

Nginx is a tengine. You will know about it in Baidu.

The structure is as follows:

Lnmp_install

── Mysql-5.6.24.tar.gz

── Openssl-1.0.2a.tar.gz

── Pcre-8.36.tar.gz

── Php-5.5.22.tar.gz

── Setup. Sh

── Tengine-2.1.0.tar.gz

── Zlib-1.2.8.tar.gz


If necessary, create the lnmp_install directory, download the above software package, and then package it with the tar command.


The following is the setup. Sh code.


#! /Bin/bash


Patha = 'pwd'

Yum install-y Dialog

Dialog -- title "The lnmp install script" -- msgbox "welcome to the lnmp installation script. This script only provides simple installation and is not optimized. Optimize related parameters in the production environment according to actual conditions. Do not use "9 30" directly.

Dialog -- menu "select the installation path" 15 30 4 1 "/usr/local (default)" 2 "other" 2>/tmp/1.txt

Xuan = 'cat/tmp/1.txt'

If [$ Xuan-EQ 1]; then

Echo "/usr/local">/tmp/ins.txt

Else

Dialog -- title "The lnmp install script" -- inputbox "Enter the installation path" 9 30 2>/tmp/2.txt

Choice = $ (CAT/tmp/2.txt)

If [! -D $ choice]; then

Echo "the installation path does not exist. Check whether the path is correct! "

Exit

Else

CAT/tmp/2.txt>/tmp/ins.txt

Fi

Fi


Position = 'cat/tmp/ins.txt'

Echo "the installation path selected this time is $ position"


# Check the system version

System = 'cat/etc/issue | head-1'


If ["$ System" x = "centos release 6.5 (final)" X]; then

Echo-e "Check System Version \ 033 [32 m [OK] \ 033 [0 m"

Else

Echo-e "Check System Version \ 033 [31 m [fail] \ 033 [0 m"

Echo "this script is written for centos 6.5 x64, and other systems may run incorrectly"

Exit

Fi


############## MySQL ######################### #################################

# Check whether MySQL is installed

Rpm-Q mysql>/dev/null

A = 'echo $? '


If [$ A-EQ 0]; then

Echo "MySQL is install"

Yum-y remove MySQL

Echo "MySQL remove is OK"

Fi


If [-F "/etc/My. CNF"]; then

MV/etc/My. CNF/OPT

Fi


# Checking network connectivity #

Ping www.baidu.com-C 2>/dev/null

Dbnet = 'echo $? '

If [$ dbnet-EQ 0]; then

Echo-e "Check Network \ 033 [32 m [OK] \ 033 [0 m"

Else

Echo-e "Check Network \ 033 [31 m [fail] \ 033 [0 m"

Echo "Check the network; otherwise, yum cannot be used"

Exit

Fi


# Disable SELinux

Setenforce 0

Sed-I '7s/enforcing/disabled/'/etc/sysconfig/SELinux

# Install the epel update source

Rpm-IVH http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

Sed-I "s/https/HTTP/"/etc/yum. Repos. d/epel. Repo

Yum-y install Yum-fastestmirror

Rpm -- import/etc/pki/rpm-GPG/RPM *

# Install the compiling environment

Yum groupinstall-y "development tools"

# Update bash and OpenSSL Vulnerabilities

Yum install-y bash OpenSSL * NTP Vim

Yum clean all

# Update Beijing Time

Ntpdate ntp.fudan.edu.cn


# Install the MySQL package

Yum-y install ncurses-devel OpenSSL * cmake

# Creating users and groups

Groupadd MySQL

Useradd-G MySQL

Usermod-S/sbin/nologin MySQL

Mkdir-P/data/3306/data/3306/logs



If [-F "mysql-5.6.24.tar.gz"]; then

Echo "mysql-5.6.24.tar.gz is found"

Else

Echo "The mysql-5.6.24.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


# Unzip and install

Tar zxvf mysql-5.6.24.tar.gz-C/usr/src

CD/usr/src/mysql-5.6.24

Cmake-dcmake_install_prefix = $ position/MySQL \

-Dmysql_datadir =/data/3306/data \

-Dmysql_tcp_port = 3306 \

-Dmysql_unix_addr =/data/3306/mysqld. Sock \

-Ddefault_charset = utf8 \

-Ddefault_collation = utf8_general_ci \

-Dwith_extra_charsets = all \

-Dwith_myisam_storage_engine = 1 \

-Dwith_innobase_storage_engine = 1 \

-Denabled_local_infile = 1 \

-Dextra_charsets = all \

-Dwith_embedded_server = 1 \

-Dwith_ssl = bundled \

-Dwith_debug = 0 \

-Denable_downloads = 1


Make

Make install


# Initialization

$ Position/MySQL/scripts/mysql_install_db \

-- Basedir = $ position/MySQL \

-- Datadir =/data/3306/data \

-- User = MySQL


Sleep 1

CP $ position/MySQL/My. CNF $ position/MySQL/My. CNF. Bak


# Editing the configuration file

Cat> $ position/MySQL/My. CNF <EOF

[Mysqld]

Basedir = $ position/MySQL

Data =/data/3306/Data

Port = 3306

Server_id = 2

Socket =/data/3306/mysqld. Sock

PID-file = $ position/MySQL. PID

Max_allowed_packet = 16 m

Log-bin = mysql-bin

SQL _mode = no_engine_substitution, strict_trans_tables

EOF


# Add a STARTUP script

Chown MYSQL: mysql-r/data/3306 $ position/MySQL

CP/usr/src/mysql-5.6.24/support-files/MySQL. Server/etc/init. d/mysqld

Chmod + x/etc/init. d/mysqld

Chkconfig -- add mysqld

Chkconfig -- level 2345 mysqld on


# Add Environment Variables

Echo 'path = $ path: '"$ position/MySQL/bin">/etc/profile

Sleep 1

Source/etc/profile

# Start

/Etc/init. d/mysqld start

Echo-e "MySQL 5.6.24 has been installed \ 033 [32 m [completed] \ 033 [0 m"

Dialog -- title "The lnmp install script" -- yesno "do you need to set the MySQL Root User Password? "9 30

AA = 'echo $? '

If [$ AA-EQ 0]; then

Dialog -- title "The lnmp install script" -- inputbox "enter the password" 9 30 2>/tmp/3.txt

Pass = 'cat/tmp/3.txt'

Echo "the password entered this time is $ pass. Remember the password! "

Sleep 1

Mysqladmin-u Root Password $ pass

Rm-RF/tmp/3.txt

Fi


############## PHP ######################### #################################

CD $ patha

# Check whether PHP is installed

Rpm-Q php>/dev/null

A = 'echo $? '


If [$ A-EQ 0]; then

Echo "PHP is installed"

Yum-y Remove PHP

Echo "php remove is OK"

Fi


Groupadd WWW

Useradd-G WWW

Usermod-S/sbin/nologin WWW


Yum install-y libxml2 libxml2-devel libxml2-python curl-devel libjpeg-devel libpng sans libpng10-devel libpng-devel FreeType-devel unzip OpenLDAP openldap-clients openldap-devel openldap-servers libmcrypt-devel -Gd OpenSSL-devel

Yum clean all

\ CP-FRP/usr/lib64/libldap */usr/lib


If [-F "php-5.5.22.tar.gz"]; then

Echo "php-5.5.22.tar.gz is found"

Else

Echo "The php-5.5.22.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


Tar zxvf php-5.5.22.tar.gz-C/usr/src/

CD/usr/src/php-5.5.22/

./Configure -- prefix = $ position/PHP -- With-config-file-Path = $ position/PHP/etc \

-- With-FreeType-dir -- With-JPEG-dir -- With-PNG-dir -- With-zlib \

-- With-libxml-Dir =/usr -- enable-XML -- enable-bcmath \

-- Enable-shmop -- enable-sysvsem -- enable-inline-optimization -- With-curl \

-- Enable-mbregex -- enable-FPM -- enable-mbstring \

-- With-mcrypt -- With-Gd -- enable-Gd-native-TTF -- With-OpenSSL -- With-mhash \

-- Enable-pcntl -- enable-sockets -- With-LDAP-sasl \

-- With-XMLRPC -- enable-zip -- enable-soap-with-pdo_mysql = $ position/MySQL \

-- With-mysql = $ position/MySQL -- enable-embedded-mysqli \

-- With-mysqli = $ position/MySQL/bin/mysql_config -- With-mysql-Sock =/data/3306/mysqld. Sock \

-- With-curl =/usr -- With-gettext -- With-iconv


Make

Make install


\ CP/usr/src/php-5.5.22/PHP. ini-production $ position/PHP/etc/PHP. ini

\ CP $ position/PHP/etc/php-fpm.conf.default $ position/PHP/etc/php-fpm.conf

\ CP/usr/src/php-5.5.22/SAPI/FPM/init. d. php-FPM/etc/init. d/PHP-FPM


# Add Environment Variables

Echo 'path = $ path: '"$ position/PHP/bin">/etc/profile

Echo 'path = $ path: '"$ position/PHP/sbin">/etc/profile

Sleep 1

Source/etc/profile


# Modify the user and group to www

Sed-I '149s/Nobody/www/'$ position/PHP/etc/php-fpm.conf

Sed-I '150s/Nobody/www/'$ position/PHP/etc/php-fpm.conf

# Enable the record PID Process

Sed-I '25s/; // '$ position/PHP/etc/php-fpm.conf


# Enable the abbreviated form of code flag

Sed-I '202s/Off/on/'$ position/PHP/etc/PHP. ini

# CGI settings

Sed-I '755s/; // '$ position/PHP/etc/PHP. ini

Sed-I '75 5s/1/0/'$ position/PHP/etc/PHP. ini


# Set the time zone

Sed-I '910d '$ position/PHP/etc/PHP. ini

Sed-I "909 A \ date. timezone = Asia/Shanghai" $ position/PHP/etc/PHP. ini


# Add auto-start upon startup

Chmod + x/etc/init. d/PHP-FPM

Chkconfig -- add PHP-FPM

Chkconfig -- level 2345 PHP-FPM on

# Start PHP-FPM

/Etc/init. d/PHP-FPM start

Echo-e "php 5.5.22 has been installed \ 033 [32 m [completed] \ 033 [0 m"


############# Tengin ######################### #################################

CD $ patha

If [-F "openssl-1.0.2a.tar.gz"]; then

Echo "openssl-1.0.2a.tar.gz is found"

Else

Echo "The openssl-1.0.2a.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


If [-F "pcre-8.36.tar.gz"]; then

Echo "pcre-8.36.tar.gz is found"

Else

Echo "The pcre-8.36.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


If [-F "zlib-1.2.8.tar.gz"]; then

Echo "zlib-1.2.8.tar.gz is found"

Else

Echo "The zlib-1.2.8.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


If [-F "tengine-2.1.0.tar.gz"]; then

Echo "tengine-2.1.0.tar.gz is found"

Else

Echo "The tengine-2.1.0.tar.gz does not exist, make sure that the package and script are in the same directory"

Exit

Fi


Tar zxvf openssl-1.0.2a.tar.gz-C/usr/src/

Tar zxvf pcre-8.36.tar.gz-C/usr/src/

Tar zxvf zlib-1.2.8.tar.gz-C/usr/src/

Tar zxvf tengine-2.1.0.tar.gz-C/usr/src/

CD/usr/src/tengine-2.1.0/

. /Configure -- prefix = $ position/nginx -- user = WWW -- group = WWW -- with-http_stub_status_module -- with-http_ssl_module -- with-http_gzip_static_module -- With-OpenSSL =/usr/src/openssl-1.0.2a -- With-zlib =/ usr/src/zlib-1.2.8 -- With-PCRE =/usr/src/pcre-8.36

Make & make install


Mkdir $ position/nginx/CONF/vhosts

CP $ position/nginx/CONF/nginx. conf $ position/nginx/CONF/nginx. conf. Bak


Sed-I '2s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '2s/Nobody/WWW www/'$ position/nginx/CONF/nginx. conf

Sed-I '5s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '9s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '27s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '28s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '29s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '31s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '71s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '72s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '73s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '74s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '75s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '76s/# // '$ position/nginx/CONF/nginx. conf

Sed-I '77s/# // '$ position/nginx/CONF/nginx. conf

Sed-I "121 A \ include vhosts/*;" $ position/nginx/CONF/nginx. conf


Echo 'fastcgi _ Param script_filename $ document_root $ fastcgi_script_name; '> $ position/nginx/CONF/fastcgi_params


Cat> $ position/nginx/html/test. php <EOF

<? PHP

Phpinfo ();

?>

EOF


$ Position/nginx/sbin/nginx

Echo-e "tengine 2.1.0 has been installed \ 033 [32 m [completed] \ 033 [0 m"

/Etc/init. d/iptables stop

IP = 'ifconfig eth0 | grep' Inet ADDR '| awk' {print $2} '| cut-d ":"-F 2'

Echo-e "Please enter \ 033 [32 m [http: // $ IP/test. php] \ 033 [0 m access PHP webpage in the browser address bar"


The running effect is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/6C/81/wKioL1VLAL3Q2FU1AACH7KoNjec556.jpg "Title =" qq20150507135926.png "alt =" wkiol1vlal3q2fu1aach7konjec556.jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/6C/85/wKiom1VK_2nQlq8jAABfKiIGPF4604.jpg "Title =" qq20150507135957.png "alt =" wkiom1vk_2nqlq8jaabfkiigpf4604.jpg "/>


This article from the "Fallen Star" blog, please be sure to keep this source http://xiao987334176.blog.51cto.com/2202382/1643832

One-click lnmp installation script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.