标签:lnmp
1、源码编译安装LNMP架构环境;
一、安装Nginx 1、解决依赖 [root@localhost ~]# yum groupinstall 开发工具 服务器平台开发 -y 2、安装 [root@localhost ~]# tar xf pcre-8.37.tar.bz2 -C /usr/local/src/ [root@localhost ~]# tar xf nginx-1.8.0.tar.gz -C /usr/local/src/ [root@localhost ~]# groupadd -r nginx [root@localhost ~]# useradd -g nginx -r -s /sbin/nologin nginx [root@localhost ~]# cd /usr/local/src/nginx-1.8.0 [root@localhost nginx-1.8.0]#./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.37 [root@localhost nginx-1.8.0]# make -j 4 && make install && cd [root@localhost ~]# mkdir /var/tmp/nginx/client -p 3、配置nginx支持php [root@localhost ~]# vim /etc/nginx/nginx.conf 修改 #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} 为 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; } #启动nginx [root@localhost ~]# /usr/local/nginx/sbin/nginx 二、安装mysql-5.6.26 1、安装依赖 [root@localhost ~]# yum -y install cmake ncurses-devel 2、编译安装mysql [root@localhost ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/src/ [root@localhost ~]# cd /usr/local/src/mysql-5.6.26/ [root@localhost mysql-5.6.26]# useradd -M -s /sbin/nologin -r mysql [root@localhost mysql-5.6.26]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql [root@localhost mysql-5.6.26]# make -j 4 && make install && cd [root@localhost ~]# chown -R mysql.mysql /usr/local/mysql/ [root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# sed -i ‘s#^basedir=#basedir=/usr/local/mysql#‘ /etc/init.d/mysqld [root@localhost ~]# sed -i ‘s#^datadir=#datadir=/usr/local/mysql/data#‘ /etc/init.d/mysqld [root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf [root@localhost ~]# sed -i ‘/^\[mysqld\]/adatadir = /usr/local/mysql/data‘ /etc/my.cnf [root@localhost ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf [root@localhost ~]# chkconfig mysqld on [root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --defaults-file=/etc/my.cnf [root@localhost ~]# echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh [root@localhost ~]# . /etc/profile.d/mysql.sh [root@localhost ~]# service mysqld start 三、安装PHP php-5.6.13 1、PHP添加libmcrypt拓展 [root@localhost ~]# tar xf libmcrypt-2.5.8.tar.bz2 [root@localhost ~]# cd libmcrypt-2.5.8 [root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt [root@localhost ~]# make && make install && cd [root@localhost ~]# sed -i ‘1a/usr/local/libmcrypt/lib‘ /etc/ld.so.conf 2、解决依赖 [root@localhost ~]# yum -y install php-pear [root@localhost ~]# sed -i ‘2a/usr/local/mysql/lib‘ /etc/ld.so.conf [root@localhost ~]# ldconfig [root@localhost ~]# echo ‘ldconfig‘ >> /etc/rc.local [root@localhost ~]# yum -y install libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel 3、编译安装php-5.6.13 [root@localhost ~]# tar xf php-5.6.13.tar.bz2 [root@localhost ~]# cd php-5.6.13 [root@localhost php-5.6.13]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-mcrypt=/usr/local/libmcrypt/ --with-gettext [root@localhost php-5.6.13]# make -j 4 && make install 4、配置php和php-fpm [root@localhost php-5.6.13]# cp php.ini-production /usr/local/php/php.ini [root@localhost php-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost php-5.6.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-5.6.13]# cd [root@localhost ~]# chmod +x /etc/init.d/php-fpm [root@localhost ~]# chkconfig php-fpm on [root@localhost ~]# /etc/init.d/php-fpm start #添加测试页 [root@localhost ~]# echo "<?php phpinfo(); ?>" >/usr/local/nginx/html/index.php [root@localhost ~]#
2、编写一个脚本完成以下功能:
(1)、一键搭建LNMP源码编译环境;
(2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。
[root@localhost ~]# cat lnmp.sh
#!/bin/bash function download { echo -e "\033[32m=========download about all web server source package==========\033[0m" rpm -q lftp || yum -y install lftp [ -d $lcd ] || mkdir $lcd HOST=$host USER="$fuser" PASS="$fpass" LCD=$lcd RCD=$rcd /usr/bin/lftp <<EOF open ftp://$USER:$PASS@$HOST mirror $RCD $LCD EOF echo -e "\033[32m=========all web server source package download finised !==========\033[0m" } function install_nginx { echo -e "\033[32m=========now start install source nginx========\033[0m" useradd -r -s /sbin/nologin nginx cd $lcd tar xf pcre-8.37.tar.bz2 -C /usr/local/src/ tar xf nginx-1.8.0.tar.gz -C /usr/local/src/ cd /usr/local/src/nginx-1.8.0 ./configure --prefix=$n_pre --sbin-path=$ns_path --conf-path=$nc_path --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.37 make -j 4 && make install && cd echo -e "\033[32m=========nginx is ok========\033[0m" } function config_nginx { mkdir /var/tmp/nginx/client -p sed -i ‘/# pass/a location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; }‘ /etc/nginx/nginx.conf $ns_path } function install_mysql { yum -y install cmake ncurses-devel cd $lcd tar xf mysql-5.6.26.tar.gz -C /usr/local/src/ cd /usr/local/src/mysql-5.6.26/ useradd -M -s /sbin/nologin -r mysql cmake -DCMAKE_INSTALL_PREFIX=$m_pre -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=$m_data -DMYSQL-USER=mysql make -j 4 && make install && cd echo -e "\033[32m=========mysqld is ok========\033[0m" } function config_mysql { echo -e "\033[32m frist,Associated system path,and Initialization database \033[0m" chown -R mysql.mysql $m_pre sed -i "s#^basedir=#basedir=$m_pre#" /etc/init.d/mysqld sed -i "s#^datadir=#datadir=$m_data#" /etc/init.d/mysqld cp $m_pre/support-files/my-default.cnf /etc/my.cnf sed -i "/^\[mysqld\]/adatadir = $m_data" /etc/my.cnf sed -i "/^\[mysqld\]/abasedir = $m_pre" /etc/my.cnf chkconfig mysqld on cp $m_pre/support-files/mysql.server /etc/init.d/mysqld $m_pre/scripts/mysql_install_db --user=mysql --basedir=$m_pre --datadir=$m_data --defaults-file=/etc/my.cnf ln -s $m_pre/bin/* /usr/bin chkconfig mysqld on service mysqld start } function install_php_fpm { cd $lcd tar xf libmcrypt-2.5.8.tar.bz2 cd libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt make && make install && cd .. sed -i ‘1a/usr/local/libmcrypt/lib‘ /etc/ld.so.conf yum -y install php-pear sed -i ‘2a/usr/local/mysql/lib‘ /etc/ld.so.conf ldconfig echo ‘ldconfig‘ >> /etc/rc.local yum -y install libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel tar xf php-5.6.13.tar.bz2 cd php-5.6.13 ./configure --prefix=$p_pre --with-config-file-path=$p_pre --with-mysql=$m_pre --with-mysqli=$m_pre/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-mcrypt=/usr/local/libmcrypt/ --with-gettext make -j 4 && make install echo -e "\033[32m=========php-fpm is ok========\033[0m" } function config_php_fpm { cp $lcd/php-5.6.13/php.ini-production $p_pre/php.ini cp $p_pre/etc/php-fpm.conf.default $p_pre/etc/php-fpm.conf cp $lcd/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm chkconfig php-fpm on /etc/init.d/php-fpm start echo "<?php phpinfo(); ?>" > $n_pre/html/index.php } function install_lnmp { install_nginx $lcd,$n_pre,$ns_path,$nc_path config_nginx $lcd,$n_pre,$ns_path install_mysql $lcd,$m_pre,$m_data config_mysql $lcd,$m_pre,$m_data install_php_fpm $lcd,$p_pre,$m_pre config_php_fpm $lcd,$p_pre,$m_pre,$n_pre } echo -e "\033[32m====now,download all web package====\033[0m" read -p "Please input source package store direcotry:" lcd read -p "Please input ftp host:" host read -p "Please input ftp user:" fuser read -p "Please input the password:" fpass read -p "Please input require download directory:" rcd download $lcd,$host,$fuser,$fpass,$rcd echo -e "\033[32m====install development packages====\033[0m" yum -y groupinstall "Development tools" "Server Platform Development" echo -e "\033[32m=========you can choice you need install package==========\033[0m" cat <<EOF nginx|N) install nginx source package. mysql|M) install mysql source package. php|P) install php source package. php-fpm|PF) install php-fpm source package. lamp) install lamp source package. lnmp) install lnmp source package. q|Q) quit EOF read -p "Please choose to install: " Choice echo -e "\033[32m=====start install $Choice====\033[0m" until [ $Choice == q -o $Choice == Q ];do case $Choice in nginx|N) [ -z $n_pre ] && read -p "nginx prefix path:" n_pre [ -z $ns_path ] && read -p "nginx sbin path:" ns_path [ -z $nc_path ] && read -p "nginx conf path:" nc_path install_nginx $lcd,$n_pre,$ns_path,$nc_path config_nginx $lcd,$n_pre,$ns_path ;; mysql|M) install_mysql $lcd,$m_pre,$m_data config_mysql $lcd,$m_pre,$m_data ;; php-fpm|PF) [ -z $n_pre ] && read -p "nginx prefix path:" n_pre [ -z $p_pre ] && read -p "php prefix path:" p_pre [ -z $m_pre ] && read -p "mysql prefix path:" m_pre install_php_fpm $lcd,$p_pre,$m_pre config_php_fpm $lcd,$p_pre,$m_pre,$n_pre ;; lnmp) [ -z $n_pre ] && read -p "nginx prefix path:" n_pre [ -z $ns_path ] && read -p "nginx sbin path:" ns_path [ -z $nc_path ] && read -p "nginx conf path:" nc_path [ -z $m_pre ] && read -p "mysql prefix path:" m_pre [ -z $m_data ] && read -p "mysql data store:" m_data [ -z $p_pre ] && read -p "php prefix path:" p_pre install_lnmp $lcd,$n_pre,$ns_path,$nc_path,$m_pre,$m_date,$p_pre;; q|Q) rm -rf $lcd break esac cat <<EOF apache|A) install apache source package. nginx|N) install nginx source package. mysql|M) install mysql source package. php|P) install php source package. php-fpm|PF) install php-fpm source package. lamp) install lamp source package. lnmp) install lnmp source package. q|Q) quit EOF read -p "Have any choice agin, if you no,q|Q is quit: " Choice done
本文出自 “追梦” 博客,请务必保留此出处http://sihua.blog.51cto.com/377227/1882764
标签:lnmp
原文地址:http://sihua.blog.51cto.com/377227/1882764