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

相关推荐

  • 【招聘福利】深圳/系统运维工程师/薪资弹性,可面谈

    深圳市鑫顺诺科技有限公司 有意向的学员,请联系magedu-小助手QQ:1522609717 职位职能: 系统运维工程师岗位职责:1、公司日常机房网络和办公室网络管理调优、日常办公电脑维护。2、管理、维护网站服务器运行状态,处理系统运行故障;3、负责服务器集群的操作系统安装、升级、定制、部署与维护工作;4、负责服务器集群的系统监控和自动化脚本的设计与部署;5…

    Linux干货 2015-11-06
  • 进程管理工具

    进程管理工具 kill man 7 signal 1) SIGHUP: 无须关闭进程而让其重读配置文件 kill -1 进程编号 2) SIGINT: 中止正在运行的进程;相当于Ctrl+c 9) SIGKILL: 杀死正在运行的进程 再生进程 kill -9 杀不掉 15) SIGTERM:终止正在运行的进程 kill -15/或不写(默认) +进程编号。…

    Linux干货 2016-09-11
  • 开篇

    新人报道

    Linux干货 2016-10-24
  • ipvsadm用法

    ipvsadm命令的用法:      1.用于管理Lvs集群服务      2.用于进行RS的增删改      3.查看配置  lvs服务器架设步骤:  1.判断内核是否支持ipvs(看到CONFIG_NETFIFLER_XT_MATCH_IPVS=…

    Linux干货 2017-01-10
  • MongoDB安装部署手稿

    Edit MongoDB 手册 MongoDB 手册 第一章 Introduction MongoDB入门学习目录(建议) Databases Collections Documents 第二章 部署安装 1. Import the MongoDB public key 2. Configure the package management system (…

    Linux干货 2016-03-26

评论列表(1条)

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

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