N25期–第十六周作业

1源码编译安装LNMP架构环境;

2、编写一个脚本完成以下功能:
   (1)、一键搭建LNMP源码编译环境;
   (2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。"


1、源码编译安装LNMP架构环境;

安装编译工具和库文件
1
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make cmake libtool* git tree

编译安装nginx
 [root@localhost opt]# wget http://nginx.org/download/nginx-1.8.1.tar.gz   #下载nginx安装包 
[root@localhost opt]# tar xzvf nginx-1.8.1.tar.gz        #解压安装包 
[root@localhost nginx-1.8.1]# ./configure \         
> --prefix=/usr/local/nginx \ 
> --with-http_realip_module \ 
> --with-http_sub_module \ 
> --with-http_ssl_module \ 
> --with-http_gzip_static_module \ 
> --with-pcre 
[root@localhost nginx-1.8.1]# make && make install 
[root@localhost nginx-1.8.1]# vim /usr/local/nginx/conf/nginx.conf        #修改php相关配置 
        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;         
        } 
[root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx        #启动nginx


编译安装mysql
 [root@localhost opt]# groupadd mysql        #添加mysql组 
[root@localhost opt]# useradd -r -g mysql mysql        #添加mysql用户 
[root@localhost opt]# tar xzvf mysql-5.6.24.tar.gz  
[root@localhost opt]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio        #安装编译代码所需要的包 
[root@localhost opt]# cd /opt/mysql-5.6.24 
[root@localhost mysql-5.6.24]#  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \              [MySQL安装的根目录] 
-DMYSQL_DATADIR=/mydata/mysql/data  \                   [MySQL数据库文件存放目录] 
-DSYSCONFDIR=/etc \                                     [MySQL配置文件所在目录] 
-DMYSQL_USER=mysql \                                    [MySQL用户名]       
-DWITH_MYISAM_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎] 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                      [MySQL的数据库引擎] 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                       [MySQL的数据库引擎] 
-DWITH_MEMORY_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎] 
-DWITH_READLINE=1 \                                     [MySQL的readline library] 
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \           [MySQL的通讯目录] 
-DMYSQL_TCP_PORT=3306 \                                 [MySQL的监听端口] 
-DENABLED_LOCAL_INFILE=1 \                              [启用加载本地数据] 
-DENABLE_DOWNLOADS=1 \                                  [编译时允许自主下载相关文件] 
-DWITH_PARTITION_STORAGE_ENGINE=1  -DEXTRA_CHARSETS=all \       [使MySQL支持所有的扩展字符] 
-DDEFAULT_CHARSET=utf8 \                                [设置默认字符集为utf8] 
-DDEFAULT_COLLATION=utf8_general_ci \                   [设置默认字符校对] 
-DWITH_DEBUG=0 \                                        [禁用调试模式] 
-DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled \    [通讯时支持ssl协议] 
-DWITH_ZLIB:STRING=bundled                              [允许使用zlib library] 
[root@localhost mysql-5.6.24]# make && make install 
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/        #修改mysql文件夹属组和属主 
[root@localhost local]# chown -R mysql:mysql /mydata/mysql/data 
[root@localhost etc]# vim /etc/my.cnf        #修改my.conf配置文件 
# For advice on how to change settings please see 
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html 
 
[mysqld]
  
# Remove leading # and set to the amount of RAM for the most important data 
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 
# innodb_buffer_pool_size = 128M 
 
# Remove leading # to turn on a very important data integrity option: logging 
# changes to the binary log between backups. 
# log_bin 
 
# These are commonly set, remove the # and set as required. 
basedir=/usr/local/mysql 
datadir=/mydata/mysql/data 
socket=/var/lib/mysql/mysql.sock 
character-set-server=utf8 
user= mysql 
# Remove leading 
# to set options mainly useful for reporting servers. 
# The server defaults are faster for transactions and fast SELECTs. 
# Adjust sizes as needed, experiment to find the optimal values. 
# join_buffer_size = 128M 
# sort_buffer_size = 2M 
# read_rnd_buffer_size = 2M 
[mysqld_safe] 
log-error=/var/log/mariadb/mariadb.log 
pid-file=/var/run/mariadb/mariadb.pid 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
[root@localhost local]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data        #初始化mysql数据库



编译安装php
 [root@localhost opt]# tar xzvf php-5.6.5.tar.gz  
[root@localhost php-5.6.5]# ./configure --enable-opcache --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 --enable-mbstring=all --with-pdo-mysql --enable-sockets --enable-mbstring --enable-fpm --with-curl --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-gd  --with-libxml-dir=/usr --enable-xml --with-openssl --with-iconv 
[root@localhost php-5.6.5]# make && make install 
[root@localhost etc]# cp /opt/php-5.6.5/php.ini-development /usr/local/php/etc/php.ini 
[root@localhost etc]# cd /usr/local/php/etc/ 
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf         
[root@localhost etc]# /usr/local/php/sbin/php-fpm        #启动php 
[root@localhost html]# vim /usr/local/nginx/html/index.php        #创建一个php页面 
<?php 
phpinfo(); 
?>


2、编写一个脚本完成以下功能:

(1)、一键搭建LNMP源码编译环境;


•   安装编译工具和库文件
1   yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make cmake libtool* git tree

编译安装nginx
 [root@localhost opt]# wget http://nginx.org/download/nginx-1.8.1.tar.gz   #下载nginx安装包 
[root@localhost opt]# tar xzvf nginx-1.8.1.tar.gz        #解压安装包 
[root@localhost nginx-1.8.1]# ./configure \         
> --prefix=/usr/local/nginx \ 
> --with-http_realip_module \ 
> --with-http_sub_module \ 
> --with-http_ssl_module \ 
> --with-http_gzip_static_module \ 
> --with-pcre 
[root@localhost nginx-1.8.1]# make && make install 
[root@localhost nginx-1.8.1]# vim /usr/local/nginx/conf/nginx.conf        #修改php相关配置 
        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;         
        } 
[root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx        #启动nginx

编译安装mysql
 [root@localhost opt]# groupadd mysql        #添加mysql组 
[root@localhost opt]# useradd -r -g mysql mysql        #添加mysql用户 
[root@localhost opt]# tar xzvf mysql-5.6.24.tar.gz  
[root@localhost opt]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio        #安装编译代码所需要的包 
[root@localhost opt]# cd /opt/mysql-5.6.24 
[root@localhost mysql-5.6.24]#  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \              [MySQL安装的根目录] 
-DMYSQL_DATADIR=/mydata/mysql/data  \                   [MySQL数据库文件存放目录] 
-DSYSCONFDIR=/etc \                                     [MySQL配置文件所在目录] 
-DMYSQL_USER=mysql \                                    [MySQL用户名]       
-DWITH_MYISAM_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎] 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                      [MySQL的数据库引擎] 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                       [MySQL的数据库引擎] 
-DWITH_MEMORY_STORAGE_ENGINE=1 \                        [MySQL的数据库引擎] 
-DWITH_READLINE=1 \                                     [MySQL的readline library] 
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \           [MySQL的通讯目录] 
-DMYSQL_TCP_PORT=3306 \                                 [MySQL的监听端口] 
-DENABLED_LOCAL_INFILE=1 \                              [启用加载本地数据] 
-DENABLE_DOWNLOADS=1 \                                  [编译时允许自主下载相关文件] 
-DWITH_PARTITION_STORAGE_ENGINE=1  -DEXTRA_CHARSETS=all \       [使MySQL支持所有的扩展字符] 
-DDEFAULT_CHARSET=utf8 \                                [设置默认字符集为utf8] 
-DDEFAULT_COLLATION=utf8_general_ci \                   [设置默认字符校对] 
-DWITH_DEBUG=0 \                                        [禁用调试模式] 
-DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled \    [通讯时支持ssl协议] 
-DWITH_ZLIB:STRING=bundled                              [允许使用zlib library] 
[root@localhost mysql-5.6.24]# make && make install 
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/        #修改mysql文件夹属组和属主 
[root@localhost local]# chown -R mysql:mysql /mydata/mysql/data 
[root@localhost etc]# vim /etc/my.cnf        #修改my.conf配置文件 
# For advice on how to change settings please see 
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html 
 
[mysqld]
  
# Remove leading # and set to the amount of RAM for the most important data 
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 
# innodb_buffer_pool_size = 128M 
 
# Remove leading # to turn on a very important data integrity option: logging 
# changes to the binary log between backups. 
# log_bin 
 
# These are commonly set, remove the # and set as required. 
basedir=/usr/local/mysql 
datadir=/mydata/mysql/data 
socket=/var/lib/mysql/mysql.sock 
character-set-server=utf8 
user= mysql 
# Remove leading 
# to set options mainly useful for reporting servers. 
# The server defaults are faster for transactions and fast SELECTs. 
# Adjust sizes as needed, experiment to find the optimal values. 
# join_buffer_size = 128M 
# sort_buffer_size = 2M 
# read_rnd_buffer_size = 2M 
[mysqld_safe] 
log-error=/var/log/mariadb/mariadb.log 
pid-file=/var/run/mariadb/mariadb.pid 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
[root@localhost local]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data    



编译安装php

 [root@localhost opt]# tar xzvf php-5.6.5.tar.gz  
[root@localhost php-5.6.5]# ./configure --enable-opcache --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 --enable-mbstring=all --with-pdo-mysql --enable-sockets --enable-mbstring --enable-fpm --with-curl --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-gd  --with-libxml-dir=/usr --enable-xml --with-openssl --with-iconv 
[root@localhost php-5.6.5]# make && make install 
[root@localhost etc]# cp /opt/php-5.6.5/php.ini-development /usr/local/php/etc/php.ini 
[root@localhost etc]# cd /usr/local/php/etc/ 
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf         
[root@localhost etc]# /usr/local/php/sbin/php-fpm        #启动php 
[root@localhost html]# vim /usr/local/nginx/html/index.php        #创建一个php页面 
<?php 
phpinfo(); 
?>



2、编写一个脚本完成以下功能:

(2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。
 [root@localhost shell]# cat /shell/LNMP.conf         #参数较多放在一个配置文件中 
nginx_dir=/usr/local/nginx 
mysql_dir=/user/local/mysql 
mysqldata_dir=/mysqldata 
php_dir=/usr/local/php 
 
 
[root@localhost shell]# cat /shell/LNMP.sh  
#!/bin/bash #加载配置文件 
 
source $1 #nginx安装函数 
nginx() {
     groupadd -r nginx
     useradd -s /sbin/nologin -g nginx -r nginx
     cd /opt
     echo "------------开始安装nginx-1.8.1------------"
     wget http://nginx.org/download/nginx-1.8.1.tar.gz
     tar xzvf nginx-1.8.1.tar.gz
     cd nginx-1.8.1
     ./configure --prefix=${nginx_dir} --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
     make && make install 
} 
 
#mysql安装模块
mysql() {
     groupadd mysql
     useradd -r -g mysql mysql
     cd /opt     echo "------------开始安装libmcrypt-2.5.7------------" 
     wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz 
     tar mysql-5.6.24.tar.gz     cd mysql-5.6.24
     cmake . -DCMAKE_INSTALL_PREFIX=${mysql_dir} \ 
     -DMYSQL_DATADIR=${mysqldata_dir}  \ 
     -DDEFAULT_CHARSET=utf8  \ 
     -DDEFAULT_COLLATION=utf8_general_ci \
     -DMYSQL_USER=mysql \
     -DMYSQL_GROUP=mysql
     make && make install
     cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
     chown -R root:mysql ${mysql_dir}
     chown -R root:mysql ${mysqldata_dir} 
} 
 
#php安装模块 
 
php() {
     cd /opt
     echo "------------开始安装libmcrypt-2.5.7------------"
     wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
     tar xvf libmcrypt-2.5.7.tar.gz 
     cd /opt/libmcrypt-2.5.7
     ./configure  --prefix=/usr/local/libmcrypt && make && make instal
l     
     echo "------------开始安装php-5.6.5------------"
     wget http://cn2.php.net/distributions/php-5.6.5.tar.gz
     tar xzvf php-5.6.5.tar.gz
     cd php-5.6.5 
     ./configure --enable-opcache --prefix=${php_dir} --with-config-file-path=${php_dir}/etc --with-mysql=${mysql_dir} --with-mysqli=${mysql_dir}/bin/mysql_config --enable-mbstring=all --with-pdo-mysql --enable-sockets --enable-mbstring --enable-fpm --with-curl --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-gd  --with-libxml-dir=/usr --enable-xml --with-openssl --with-iconv && make && make install
     cp ${php_dir}/etc/php-fpm.conf.default  ${php_dir}/etc/php-fpm.conf 
     cp /opt/php-5.6.5/php.ini-development ${php_dir}/etc/php.ini 
}
 
 yum -y install gcc gcc-c++ make pcre-* zlib-* cmake ncurses-devel libjpeg* libpng* freetype* libcurl-devel libvpx-devel libxml2 libxml2-devel libXpm libXpm-devel libXpm.i686 libXpm.i686-devel openldap-devel
 
#安装nginx软件
 
nginx 
if [ $? -eq 0 ];then
    echo "nginx安装成功!!!"
 else
    echo "nginx安装异常!!!" 
    exit
 fi 
 
#安装mysql数据库 
 
mysql 
if [ $? -eq 0 ];then
    echo "mysql安装成功!!!" 
else
    echo "mysql安装异常!!!"
    exit 
fi 
 
#安装php
 
 php if [ $? -eq 0 ];then
    echo "php安装成功!!!"
    exit 
else
    echo "php安装异常!!!"
    exit
fi

原创文章,作者:victorli88,如若转载,请注明出处:http://www.178linux.com/73088

(0)
victorli88victorli88
上一篇 2017-05-08
下一篇 2017-05-08

相关推荐

  • 马哥教育网络21期+第五周练习博客

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]#  grep '[^[:space:]]\+' /boot/grub2/grub.cfg 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符…

    Linux干货 2016-08-08
  • N25第三周作业

    .列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登陆多次,则只显示一次即可。 此题主要考察命令who,cut,sort以及管道的基本用法:who:列出当前已登陆的用户名,登陆设备名,时间以及ip地址。 cut:    顾名思义就是截取之意, -d 指定要截取信息的分隔符,此处是以空格为分隔符,-f指定要截取的字段,此…

    Linux干货 2016-12-20
  • python快速入门之数据类型

        Python 是 90 年代初由 Guido Van Rossum 为了打发圣诞节而创建的语言。如今它已是当前最流行的程序语言之一.     Python的关键要素有以下几点:1.基本数据类型;2.对象引用;3.组合数据类型;4.逻辑操作符;5.控制流语句;6.算数操作符…

    Python干货 2015-12-10
  • 网络协议端口号查询表

    TCP 0= ReservedTCP 1=TCP Port Service MultiplexerTCP 2=DeathTCP 5=Remote Job Entry,yoyoTCP 7=EchoTCP 11=SkunTCP 12=BomberTCP 16=SkunTCP 17=SkunTCP 18=消息传输协议,skunTCP 19=SkunTCP 20=F…

    Linux干货 2017-08-15
  • Linux文件系统简介

    文件系统是Linux的十分基础的知识,同时也是学习Linux必不可少的知识。本文将简单的介绍一下Linux的文件系统,主要包括FHS文件层级结构、Linux的文件类型及对应的颜色标识、man帮助手册页以及命令编辑特性的快捷键的介绍。这仅仅是属于自己的一个总结,以后会对深入学习Linux有一定的帮助吧。 如有不对之处还请帮忙指出。 FHS文件层级结构 FHS(…

    Linux干货 2016-10-19
  • Linux文件系统

      文件系统是一个逻辑上的概念,本身与磁盘没有什么关系,它是一个外围性永久存储设备,我们知道,计算机共有五大部件,存储设备是一种,内存是个临时性质的存储设备,无论是关机还是断电,存在里面的数据都会消失,我们需要一个永久性存储的设备,来弥补内存只是临时存储性。   对于Linux来说,其哲学思想之一就是一切皆文件,我们L…

    Linux干货 2016-11-11

评论列表(1条)

  • 马哥教育
    马哥教育 2017-06-20 11:25

    写点很棒,希望可以继续保持,再接再厉