侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

详解CentOS 7.0源码包搭建LNMP 实际环境搭建

linux  /  管理员 发布于 7年前   176

Centos7+Nginx1.11.7+MySQL5.7.16+PHP7.1.0+openssl-1.1.0c

一、linux 系统限制配置

1、关闭系统防火墙    

systemctl stop firewalld.service 关闭防火墙systemctl disable firewalld.service 禁用防火墙

2、关闭SElinux

sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config setenforce 0 selinux 立即生效

二、系统安装约定

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字

三、下载软件包

1、下载nginx最新稳定版本

 wget -P /usr/local/src http://nginx.org/download/nginx-1.11.7.tar.gz

2、下载mysql-boost-5.7.16 带 boost 如果不带源码安装如果网络环境不会可能会出现错误

wget -P /usr/local/src http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.16.tar.gz

3、下载php-7.1.0版本

wget -P /usr/local/src http://cn2.php.net/distributions/php-7.1.0.tar.gz

4、下载libmemcached-1.0.18

wget -P /usr/local/src https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz

5、下载php-memcached

yum -y install gitcd /usr/local/src git clone -b php7 https://github.com/php-memcached-dev/php-memcached.git

6、下载openssl-1.1.0c

wget -P /usr/local/src https://www.openssl.org/source/openssl-1.1.0c.tar.gz

四、安装编译器及依赖

yum -y insyall epel-releaseyum -y install patch gcc gcc-c++ readline-devel zlib-devel libffi-devel \ openssl openssl-devel make autoconf automake libtool bison libxml2 \ libxml2-devel libxslt-devel libyaml-devel python python-docutils \ cmake imake expat-devel libaio libaio-devel bzr ncurses-devel wget \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \ pcre-devel curl-devel libmcrypt libmcrypt-devel

五、编译安装mysql-boost-5.7.16 方便再次安装创建mysql_install.sh脚本

1、mysql_install.sh内容

#!/bin/bash#yum update -y#yum install -y cmake gcc-c++ ncurses-devel gcc make openssl*#mysql安装脚本DBDIR='/data/mysql' #mysql数据存储目录MYSQLDIR='/usr/local/mysql' # mysql安装目录PASSWD='123456' # mysql root密码 安装完成可远程ip登陆[ -d $DBDIR ] || mkdir $DBDIR -pid mysql &> /dev/nullif [ $? -ne 0 ];then useradd mysql -s /sbin/nologin -Mfichown -R mysql:mysql $DBDIRcd /usr/local/srctar -xvf mysql-boost-5.7.16.tar.gzcd mysql-5.7.16cmake . -DCMAKE_INSTALL_PREFIX=$MYSQLDIR \-DMYSQL_DATADIR=$DBDIR \-DSYSCONFDIR=/etc \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DWITH_LIBWRAP=0 \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DWITH_SSL=system \-DWITH_ZLIB=system \-DWITH_BOOST=/usr/local/src/mysql-5.7.16/boost/boost_1_59_0 \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ciif [ $? != 0 ];then echo "cmake error!" exit 1fimake && make installif [ $? -ne 0 ];then echo "install mysql is failed!" && /bin/falsefisleep 2chown -R mysql:mysql $MYSQLDIRchown -R root:root $MYSQLDIRcp $MYSQLDIR/support-files/my-default.cnf /etc/my.cnfecho export PATH=$PATH:$MYSQLDIR/bin:$MYSQLDIR/lib >>/etc/profilesource /etc/profilecat >> /etc/my.cnf << EOFcharacter_set_server = utf8basedir = $MYSQLDIRdatadir = $DBDIRport = 3306server_id = 1socket = /tmp/mysql.sockexplicit_defaults_for_timestamp=trueEOFsed -i 's/sql_mode=.*/sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER/g' /etc/my.cnf  source /etc/profile  sleep 5  cd $MYSQLDIR  cp support-files/mysql.server /etc/init.d/mysqld  chmod 700 /etc/init.d/mysqld  mysql_ssl_rsa_setup  rm -rf $DBDIR  mysqld --initialize --user=mysql  if [ $? -ne 0 ];then echo "install mysql is failed!" && /bin/falsefi#/etc/init.d/mysqld stop  mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  sleep 5  echo "update user set authentication_string=Password('$PASSWD') where user='root'; flush privileges;" | mysql mysql   echo "set password=Password('$PASSWD'); flush privileges;" | mysql -u root -p$PASSWD --connect-expired-password  sleep 5  echo "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '$PASSWD'; FLUSH PRIVILEGES; " | mysql -u root -p$PASSWD  /etc/init.d/mysqld restart  if [ $? -ne 0 ];then echo "install mysql is failed!" && /bin/falsefiIDSO=`cat /etc/ld.so.conf| grep $MYSQLDIR/lib | wc -l `if [ $IDSO -eq 0 ];thenecho "$MYSQLDIR/lib" >> /etc/ld.so.conf ldconfigfichkconfig mysqld on

2、给 mysql_install.sh  可执行权限

chmod +x mysql_install.sh

3、运行mysql_install.sh 

./mysql_install.sh

六、编译安装php7  创建php安装脚本php7_install.sh

1、vim php7_install.sh

#!/bin/bashif [ $( find / -name mysql | wc -l ) -gt 1 ];thenecho " mysql is install "elseyum install -y mysqlficd /usr/local/srctar -xzvf php-7.1.0.tar.gzcd ./php-7.1.0./configure \--prefix=/usr/local/php7 \--exec-prefix=/usr/local/php7 \--with-config-file-path=/usr/local/php7/etc \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --with-zlib-dir \ --with-mhash \ --with-mcrypt \ --with-openssl-dir \ --with-jpeg-dir \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zipmake && make install # 中文php画图取消这个参数,不然会出现乱码# --enable-gd-jis-conv \

2、给 php7_install.sh 可执行权限

chmod +x php7_install.sh

3、执行 php7_install.sh

./php7_install.sh

4、编译安装libmemcached-1.0.18

vim libmemcached_install.sh

#/!bin/bashcd /usr/local/srctar -zxvf libmemcached-1.0.18.tar.gzcd ./libmemcached-1.0.18./configure --prefix=/usr/local/libmemcachedmake && make installchmod +x libmemcached_install.sh./libmemcached_install.sh

5、编译安装php-memcached

vim memcached_install.sh

#!/bin/bashcd /usr/local/src/php-memcached/usr/local/php7/bin/phpize./configure --with-libmemcached-dir=/usr/local/libmemcached \ --with-php-config=/usr/local/php7/bin/php-config \ --disable-memcached-saslmake && make installchmod +x memcached_install.sh./memcached_install.sh

留意编完成生成文件路径

Installing shared extensions:  /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/

七、编译安装openssl-1.1.0c

vim openssl_install.sh

#!/bin/bash#openssl installcd /usr/local/srctar -xvf openssl-1.1.0c.tar.gzcd /usr/local/src/openssl-1.1.0c./config --openssldir=/usr/local/sslmake && make install./config shared --openssldir=/usr/local/sslmake cleanmake && make installIDSO=`cat /etc/ld.so.conf| grep /usr/local/lib64 | wc -l `if [ $IDSO -eq 0 ];thenecho "/usr/local/lib64" >> /etc/ld.so.conffildconfigchmod +x openssl_install.sh./openssl_install.sh

八、编译安装nginx-1.11.7

vim nginx_install.sh

#!/bin/bash# nginx installid nginx &> /dev/nullif [ $? -ne 0 ];then groupadd -r nginx useradd -g nginx -r nginxficd /usr/local/srctar -xvf nginx-1.11.7.tar.gzcd /usr/local/src/nginx-1.11.7./configure --prefix=/usr/local/nginx \--sbin-path=/usr/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/run/nginx.pid \--lock-path=/var/run/nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/proxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=nginx \--group=nginx \--with-http_ssl_module \--with-http_realip_module \--with-http_addition_module \--with-http_sub_module \--with-http_dav_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_random_index_module \--with-http_secure_link_module \--with-http_stub_status_module \--with-http_auth_request_module \--with-threads \--with-stream \--with-openssl=/usr/local/src/openssl-1.1.0c \ # openssl 源码解压路径--with-stream_ssl_module \--with-http_slice_module \--with-mail \--with-mail_ssl_module \--with-file-aio \--with-http_v2_module \--with-ipv6 mkdir -pv /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}make && make install

2、给nginx_install.sh可执行权限

 chmod +x nginx_install.sh ./nginx_install.sh

九、配置PHP7

/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/memcached.so

这个路径是 随机可变的所以要注意

留意变完成生成文件路径

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/

cd /usr/local/src/php-7.1.0cp php.ini-production /usr/local/php7/etc/php.inicp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.confcp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.confsed -i "s/user = .*/user = nginx/g" /usr/local/php7/etc/php-fpm.d/www.confsed -i "s/group = .*/group = nginx/g" /usr/local/php7/etc/php-fpm.d/www.confcp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpmchkconfig php-fpm oncat >> /usr/local/php7/etc/php.ini<< EOFsoap.wsdl_cache_enabled=1max_input_time = 600max_execution_time = 300date.timezone = Asia/Shanghaipost_max_size = 32Mmemory_limit = 128Mmbstring.func_overload = 1extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/memcached.soEOFcat > /usr/local/nginx/html/index.php<<EOF<?phpphpinfo();?> EOFservice php-fpm start

十、配置nginx

1、重命名:/etc/nginx/nginx.conf

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back

2、新建/etc/nginx/nginx.conf

cat > /etc/nginx/nginx.conf << EOFuser nginx;worker_processes 1; error_log /var/log/nginx/error.log warn;pid  /var/run/nginx.pid;  events { worker_connections 1024;}  http { include  /etc/nginx/mime.types; default_type application/octet-stream;  log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '      '\$status \$body_bytes_sent "\$http_referer" '      '"\$http_user_agent" "\$http_x_forwarded_for"';  access_log /var/log/nginx/access.log main;  sendfile  on; #tcp_nopush  on;  keepalive_timeout 65;  #gzip on;  include /etc/nginx/conf.d/*.conf;}EOF

3、创建/etc/nginx/conf.d

mkdir -p /etc/nginx/conf.d

4、创建支持php-fpm web nginx配置

cat > /etc/nginx/conf.d/default.conf << EOFserver {  listen  80;  server_name localhost;   #charset koi8-r;   #access_log logs/host.access.log main;   location / {   root /usr/local/nginx/html;   index index.php index.html index.htm;  }   #error_page 404    /404.html;   # redirect server error pages to the static page /50x.html  #  error_page 500 502 503 504 /50x.html;  location = /50x.html {   root html;  }   # proxy the PHP scripts to Apache listening on 127.0.0.1:80  #  #location ~ \.php$ {  # proxy_pass http://127.0.0.1;  #}   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  #  location ~ \.php$ {   root   /usr/local/nginx/html;   fastcgi_pass 127.0.0.1:9000;   fastcgi_index index.php;   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   include  fastcgi_params;  }  location ~* ^.+\.(jpg|jpeg|gif|png|bmp)$ {   access_log off;   root  opencart;   expires  30d;      break;  }}EOF

5、创建nginx启动脚本

vim /etc/init.d/nginx

# chkconfig: 2345 10 90# description: Start and Stop nginx PATH=/usr/local/bin:/sbin:/usr/bin:/bin EXEC=/usr/sbin/nginxPIDFILE=/var/run/nginx.pidCONF="/etc/nginx/nginx.conf"AUTH="1234" case "$1" in  start)    if [ -f $PIDFILE ]    then      echo "$PIDFILE exists, process is already running or crashed."    else      echo "Starting nginx server..."      $EXEC -c $CONF &    fi    if [ "$?"="0" ]    then      echo "nginx is running..."    fi    ;;  stop)    if [ ! -f $PIDFILE ]    then      echo "$PIDFILE exists, process is not running."    else      PID=$(cat $PIDFILE)      echo "Stopping..."      kill -9 $PID      PID=$(pidof nginx)      kill -9 $PID      rm -rf /var/run/nginx.pid      sleep 2      while [ -x $PIDFILE ]      do        echo "Waiting for nginx to shutdown..."        sleep 1      done      echo "nginx stopped"    fi    ;;  reload)    $EXEC -s reload    ;;  restart|force-reload)    ${0} stop    ${0} start    ;;  *)    echo "Usage: /etc/init.d/nginx {start|stop|restart|force-reload|reload}" >&2    exit 1esac

6、给 /etc/init.d/nginx 可执行权限

chmod +x /etc/init.d/nginx

7、设置开机启动

chkconfig nginx on

8、启动nginx

service nginx start

十一、测试

[root@QKA169 src]# openssl version  OpenSSL 1.1.0c 10 Nov 2016mysql -u root -p123456mysql> show databases; +--------------------+| Database   |+--------------------+| information_schema || mysql    || performance_schema || sys    |+--------------------+4 rows in set (0.00 sec)看看是否登陆成功。远程带IP是否登陆成功mysql -u root -h192.168.1.69 -p123456mysql> show databases; +--------------------+| Database   |+--------------------+| information_schema || mysql    || performance_schema || sys    |+--------------------+4 rows in set (0.00 sec) mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.16 Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

测试nginx 是否能打开

[root@QKA169 html]# ps -ef | grep php-fpmroot  337433  1 0 18:03 ?  00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)nobody 337434 337433 0 18:03 ?  00:00:00 php-fpm: pool wwwnobody 337435 337433 0 18:03 ?  00:00:00 php-fpm: pool wwwroot  337454 37888 0 18:12 pts/0 00:00:00 grep --color=auto php-fpm[root@QKA169 html]# ps -ef | grep nginxroot  337400  1 0 18:01 ?  00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confnginx  337401 337400 0 18:01 ?  00:00:00 nginx: worker processroot  337456 37888 0 18:13 pts/0 00:00:00 grep --color=auto nginx[root@QKA169 html]# netstat -nalp | grep 80tcp  0  0 0.0.0.0:80    0.0.0.0:*    LISTEN  337400/nginx: maste tcp  0  0 192.168.1.69:80   192.168.6.6:54714  TIME_WAIT -     tcp  0  0 192.168.1.69:80   192.168.6.6:54709  TIME_WAIT - 远程打开     http://192.168.1.69/

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    linux中了minerd之后的完全清理过程(详解)
    下一条:
    在CentOS 7上进行 Nginx安装教程
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客