十六周

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
下一篇 2018-03-26

相关推荐