十六周

1、源码编译安装LNMP架构环境;
centos 7系统
编译安装nginx
安装编译环境
[root@localhost ~]# yum -y groupinstall “Development Tools” “Development Libraries”
[root@localhost ~]# yum -y install pcre-devel
创建nignx的用户,用于运行nginx的worker进程
[root@localhost ~]# groupadd -r nginx
[root@localhost ~]# useradd -r -g nginx nginx
进入解压nginx的文件夹
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xf nginx-1.12.1
[root@localhost nginx-1.12.1]# cd /usr/local/src/nginx-1.12.1
编译安装nginx
[root@localhost nginx-1.12.1]# ./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/lock/nginx.lock –user=nginx –group=nginx –with-http_ssl_module –with-http_flv_module –with-http_stub_status_module –with-http_gzip_static_module –http-client-body-temp-path=/var/tmp/nginx/client –http-proxy-temp-path=/var/tmp/nginx/proxy –http-proxy-temp-path=/var/tmp/nginx/proxy –http-fastcgi-temp-path=/var/tmp/nginx/fcgi –http-uwsgi-temp-path=/var/tmp/nginx/uwcgi –http-scgi-temp-path=/var/tmp/nginx/scgi –with-pcre
[root@localhost nginx-1.12.1]# make && make install
修改配置文件
[root@localhost nginx]# vim /etc/nginx/nginx.conf
        location / {
            root   html;
            index  index.html index.htm index.php; —新增index.php项
       location ~ \.php$ {–启用php支持功能
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
二进制安装mysql
[root@localhost nginx]# cd ..
[root@localhost src]# tar xf mariadb-10.1.22-linux-glibc_214-x86_64.tar.gz -C /usr/local/  –解压压缩包
[root@localhost local]# ln -sv mariadb-10.1.22-linux-glibc_214-x86_64 mysql –链接解压的文件到mysql文件夹下
[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# groupadd -r -g 3306 mysql –创建mysql组
[root@localhost mysql]# useradd -r -g mysql -u 3306 mysql –创建mysql用户
[root@localhost mysql]# mkidr -p /datamysql/mysql –创建mysql的数据目录
[root@localhost mysql]# chown -R mysql:mysql /datamysql –更改mysql数据目录属主属组
[root@localhost mysql]# chown -R mysql:mysql . –更改解压出来的mysql文件的属组属主,用于初始化数据库
[root@localhost mysql]# scripts/mysql_install_db –user=mysql –datadir=/datamysql/mysql/ –初始化数据库
  [root@localhost mysql]# chown -R root . –为了安全性,更改当前目录的属主为root
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf –给与mysql数据库的配置文件
[root@localhost mysql]# echo “datadir=/datamysql/mysql” >> /etc/my.cnf –给与配置文件中data目录位置
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld –添加mysql的启动脚本
[root@localhost mysql]#echo “/usr/local/mysql/lib/” >/etc/ld.so.conf.d/mysql.conf –添加mysql的库文件到系统中
[root@localhost mysql]#echo “MANPATH /usr/local/mysql/man” >> /etc/man.config –输出mysql的man文档到系统路径中
[root@localhost mysql]#echo “PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile –输出mysql的二进制文件到系统中
[root@localhost mysql]#ln -sv /usr/local/mysql/include/ /usr/local/include/mysql –输出mysql的库文件到系统中
[root@localhost mysql]#ldconfig -v –加载并验证mysql的库文件是否输出
安装php
[root@localhost src]# tar xf php-7.2.2.tar.xz
[root@localhost php-7.2.2]#  ./configure –prefix=/usr/local/php –with-config-file-path=/etc –enable-fpm –with-fpm-user=nginx  –with-fpm-group=nginx –enable-inline-optimization –disable-debug –disable-rpath –enable-shared  –enable-soap –with-libxml-dir –with-xmlrpc –with-openssl  –with-mhash –with-pcre-regex –with-sqlite3 –with-zlib –enable-bcmath –with-iconv –with-bz2 –enable-calendar –with-curl –with-cdb –enable-dom –enable-exif –enable-fileinfo –enable-filter –with-pcre-dir –enable-ftp –with-gd –with-openssl-dir –with-jpeg-dir –with-png-dir –with-zlib-dir  –with-freetype-dir –enable-gd-jis-conv –with-gettext –with-gmp –with-mhash –enable-json –enable-mbstring –enable-mbregex –enable-mbregex-backtrack –with-libmbfl –with-onig –enable-pdo –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-zlib-dir –with-pdo-sqlite –with-readline –enable-session –enable-shmop –enable-simplexml –enable-sockets -enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-wddx –with-libxml-dir –with-xsl –enable-zip –enable-mysqlnd-compression-support –with-pear –enable-opcache
[root@localhost php-7.2.2]#  make && make install
[root@localhost php-7.2.2]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.2]# cp php.ini-production /etc/php.ini
[root@localhost php-7.2.2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  [root@localhost php-7.2.2]# chmod +x /etc/init.d/php-fpm
[root@localhost php-7.2.2]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-7.2.2]# service  php-fpm start
修改配置文件
2、编写一个脚本完成以下功能:
   (1)、一键搭建LNMP源码编译环境;
   (2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。
  #!/bin/bash
#
#
#
/usr/bin/mount /dev/cdrom /media >& /dev/null || echo “Please insert the disc” && exit 1
echo -e  ” Install Development Environment \n Please wait … “
/usr/bin/yum -y groupinstall “Development Tools” “Development Libraries”
/usr/bin/yum  -y install pcre-devel pcre openssl-devel ncurses-devel cmake pcre-devel libxml2-devel bzip2-devel libcurl-devel libmcrypt-devel
echo “Install NGINX”
NGINX_INSTLL () {
/usr/bin/cd /usr/local/src
/usr/bin/tar -xf /usr/local/src/nginx*.tar.gz .
/usr/bin/cd /usr/local/src/nginx.*/
id nginx >& /dev/null && userdel -r nginx
useradd -r -s /usr/sbin/nologin nginx
/bin/bash 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/lock/nginx.lock –user=nginx –group=nginx –with-http_ssl_module –with-http_flv_module –with-http_stub_status_module –with-http_gzip_static_module –http-client-body-temp-path=/var/tmp/nginx/client –http-proxy-temp-path=/var/tmp/nginx/proxy –http-proxy-temp-path=/var/tmp/nginx/proxy –http-fastcgi-temp-path=/var/tmp/nginx/fcgi –http-uwsgi-temp-path=/var/tmp/nginx/uwcgi –http-scgi-temp-path=/var/tmp/nginx/scgi –with-pcre
make && make install
 sed  -n ‘s/index.htm\>/index.htm  index.php/p’ /etc/nginx/nginx.conf
echo -e ”        location / { \n
            root   html;
            index  index.html index.htm index.php; —新增index.php项 \n
       location ~ \.php$ {–启用php支持功能\n
            root           html; \n
            fastcgi_pass   127.0.0.1:9000;\n
            fastcgi_index  index.php;\n
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; \n
            include        fastcgi_params; \n
        } \n
” >> /etc/nginx/nginx.conf
}
PHP7_INTALL () {
cd /usr/local/src
tar xf php*.tar.xz
cd /usr/local/src/php*
./configure –prefix=/usr/local/php –with-config-file-path=/etc –enable-fpm –with-fpm-user=nginx  –with-fpm-group=nginx –enable-inline-optimization –disable-debug –disable-rpath –enable-shared  –enable-soap –with-libxml-dir –with-xmlrpc –with-openssl  –with-mhash –with-pcre-regex –with-sqlite3 –with-zlib –enable-bcmath –with-iconv –with-bz2 –enable-calendar –with-curl –with-cdb –enable-dom –enable-exif –enable-fileinfo –enable-filter –with-pcre-dir –enable-ftp –with-gd –with-openssl-dir –with-jpeg-dir –with-png-dir –with-zlib-dir  –with-freetype-dir –enable-gd-jis-conv –with-gettext –with-gmp –with-mhash –enable-json –enable-mbstring –enable-mbregex –enable-mbregex-backtrack –with-libmbfl –with-onig –enable-pdo –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-zlib-dir –with-pdo-sqlite –with-readline –enable-session –enable-shmop –enable-simplexml –enable-sockets -enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-wddx –with-libxml-dir –with-xsl –enable-zip –enable-mysqlnd-compression-support –with-pear –enable-opcache
make && make install
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
}
MYSQL_INSTLL () {
tar xf /usr/local/srcmariadb-*-linux-glibc_214-x86_64.tar.gz -C /usr/local/  –解压压缩包
ln -sv /usr/local/mariadb-*-linux-glibc_214-x86_64 /usr/local/mysql –链接解压的文件到mysql文件夹下
cd /usr/local/mysql/
groupadd -r -g 3306 mysql –创建mysql组
useradd -r -g mysql -u 3306 mysql –创建mysql用户
mkidr -p /datamysql/mysql –创建mysql的数据目录
chown -R mysql:mysql /datamysql –更改mysql数据目录属主属组
chown -R mysql:mysql .   –更改解压出来的mysql文件的属组属主,用于初始化数据库
sh /usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/datamysql/mysql/ –初始化数据库
chown -R root .   –为了安全性,更改当前目录的属主为root
cp /usr/lcoal/mysql/support-files/my-large.cnf /etc/my.cnf –给与mysql数据库的配置文件
echo “datadir=/datamysql/mysql” >> /etc/my.cnf –给与配置文件中data目录位置
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld –添加mysql的启动脚本
echo “/usr/local/mysql/lib/” >/etc/ld.so.conf.d/mysql.conf –添加mysql的库文件到系统中
echo “MANPATH /usr/local/mysql/man” >> /etc/man.config –输出mysql的man文档到系统路径中
echo “PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile –输出mysql的二进制文件到系统中
ln -sv /usr/local/mysql/include/ /usr/local/incule
}
 echo INSTALL NGINX…
NGINX_INSTALL
if [ $? -eq  0 ] ;then
echo  NGINX install success
else
echo NGINX install fail
fi
PHP7_INSTALL
if [ $? -eq  0 ] ;then
echo  PHP7 install success
else
echo PHP7 install fail
fi
MYSQL_INSTALL
if [ $? -eq  0 ] ;then
echo  MYSQL install success
else
echo MYSQL install fail
fi

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92884

(0)
上一篇 2018-03-25 23:13
下一篇 2018-03-26 15:37

相关推荐

  • 在CentOS7上编译安装apache 2.4源码包,并启动此服务

    1 关闭firwalld systemctl stop firewalld systemctl disable firewalld 2 关闭SElinux setenforce 0 vim /etc/selinux/config 找到以SELINUX开头的那行,修改成SELINUX=disabled 以下就是脚本里的内容,执行就OK了 yum groupin…

    Linux笔记 2018-04-22
  • 生产环境中数据文件删除,空间不释放问题

    首先数据文件删除文件系统空间不释放的问题不只出现在Linux平台,所有平台都可能有这样的问题。这里只是在Linux平台做一些测试,其他平台类似;其次只有将数据文件存放在文件系统中才会有此类问题。空间没有释放我们可能是通过df命令确认的,当我们用du去扫描目录的大小可能会发现df和du两个命令看到的空间使用情况是不同的,可能差别很大,找了一些文档,解决了这个问题;写这篇博客,希望跟大家分享一下。

    2018-05-18
  • 網絡屬性配置第三種方式——修改配置文件

    網絡屬性配置第三種方式——修改配置文件 IP ,MASK,GW,DNS相關的配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0 路由相關的配置文件:/etc/sysconfig/network-scripts/route-enth0(這個文件默認不存在,需要手動去創建) (1)/etc/sys…

    Linux笔记 2018-05-06
  • Linux第六周作业

    1、简述osi七层模型和TCP/IP五层模型   2、简述iproute家族命令   3、详细说明进行管理工具htop、vmstat等相关命令,并举例   4、使用until和while分别实现192.168.0.0/24网段内,地址是否能够ping通,弱ping通则输出”success!”,若ping不…

    2018-08-06
  • 第三周作业

    时间不够啊,,先搭个架子

    Linux笔记 2018-07-07
  • Linux基础命令

    本文主要介绍:1、修改命令提示符 2、执行命令(内部,外部) 3、命令别名 4、命令history

    2018-04-01