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

相关推荐

  • 面向对象魔术方法

    ##**特殊属性**– __name__ 类、函数、方法等的名字– __module__ 类定义所在的模块名– __class__ 对象或类所属的类– __bases__ 类的基类的元组,顺序为它们在基类列表中出现的顺序– __doc__ 类、函数的文档字符串,如果没有定义则为None–…

    Linux干货 2017-11-21
  • TCP详解

    TCP协议详解   TCP/IP协议不是TCP和IP这两个协议的合称,而是指因特网整个使用TCP/IP协议的协议集合。他取代了OSI七层模型,成为事实上的应用于实际的模型。 TCP/IP协议与OSI协议的关系如下:   各层的作用如下: TCP特性: 工作在传输层面向连接协议 全双工协议 半关闭 错误检查 将数据打包成段,排序 确认机制 …

    2017-09-02
  • 马哥教育网络班20期+第2周课程练习

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示 文件管理命令:ls、cd、pwd、mkdir、rmdir、cp、rm.、mv、touch、cat、more、less、head、tail 1)ls命令:显示目录文件   -a 显示所有文件,包括隐藏文件  ~]# ls -a /etc.  &n…

    Linux干货 2016-06-23
  • 11文件查找find和locate

    有些时候我们是想要在系统中查找某个具体的文件,却不知道路径在哪里,只是知道其中的某些特性,比如大小或者名字什么的。这时候就要用到查找工具啦。 在文件系统上查找符合条件的文件命令有两个,locate和find,其中locate是非实时查找即数据库查找。而find是实时查找 locate: 用法:locate [OPTION]… [PATTERN]&…

    Linux干货 2016-11-27
  • Linux学习之课前环境安装调试

    系统安装,VNC,VMware软件安装

    2018-03-26
  • 第一周博客作业

       本文介紹計算机的组成及其功能 、Linux各版本的联系与区别、Linux的哲学思想、Linux系统上命令的使用格式及介绍部分命令、如何在Linux系统上获取帮助信息以及Linux发行版的基础目录名称以及规定。 一、计算机的组成及其功能 1)什么是计算机? 想了解计算机的组成,首先得了解计算机的含义。计算机其实是:接收用户输入指令与数…

    Linux干货 2016-12-04

评论列表(1条)

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

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