当前位置:   article > 正文

[Linux]LNMP网站服务器架构搭建_linux lnmp网站搭建 项目描述

linux lnmp网站搭建 项目描述

1、介绍

LNMP为运行动态网站或服务器的架构,由Linux,Nginx,Mysql,PHP组成,其中的Mysql也可为MariaDB,PHP也可为Python。

2、环境设置

rhel 6.5

服务器IP:172.25.69.11

本地测试主机IP:172.25.69.250

3、安装PHP

方法一:通过配置的yum源进行安装

方法二:下载源码包,通过源码编译进行安装

以下介绍方法二的实现

(1)将下载的PHP源码包解压

命令:tar jxf php-5.6.35.tar.bz2

(2)源码编译和安装

configure脚本执行:(添加安装选项)

  1. ./configure --prefix=/usr/local/lnmp/php \
  2. --with-config-file-path=/usr/local/lnmp/php/etc \
  3. --with-openssl \
  4. --with-snmp \
  5. --with-gd \
  6. --with-zlib \
  7. --with-curl \
  8. --with-libxml-dir \
  9. --with-png-dir \
  10. --with-jpeg-dir \
  11. --with-freetype-dir \
  12. --with-gmp \
  13. --with-gettext \
  14. --with-pear \
  15. --enable-mysqlnd \
  16. --with-mysql=mysqlnd \
  17. --with-mysqli=mysqlnd \
  18. --with-pdo-mysql=mysqlnd \
  19. --enable-inline-optimization \
  20. --enable-soap \
  21. --enable-ftp \
  22. --enable-sockets \
  23. --enable-mbstring \
  24. --enable-fpm \
  25. --with-fpm-user=nginx \
  26. --with-fpm-group=nginx \
  27. --with-mcrypt \
  28. --with-mhash

其中可能遇到以下错误

error: xml2-config not found. Please check your libxml2 installation.

安装libxml2-devel.x86_64

error: Cannot find OpenSSL's <evp.h>

安装openssl-devel

error: Please reinstall the libcurl distribution -
           easy.h should be in <curl-dir>/include/curl/

安装:libcurl-devel-7.19.7-37.el6_4.x86_64

If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

安装:libjpeg-turbo-devel-1.2.1-1.el6.x86_64

If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

安装:libpng-devel-1.2.49-1.el6_2.x86_64

If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes

If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

安装:freetype-devel

configure: error: Unable to locate gmp.h
安装:gmp-devel-4.3.1-7.el6_2.2.x86_64

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

安装:libmcrypt和libmcrypt-devel        (这两包可能在yum源中不存在,需要单独下载)

error: Could not find net-snmp-config binary. Please check your net-snmp installation.

安装:net-snmp-devel-5.5-49.el6.x86_64

configure 完成后使用make && make install

(3)进入安装目录下的配置文件目录

路径:/usr/local/lnmp/php/etc

将解压包下的默认配置文件(php.ini-production)拷贝至当前位置修改名称为php.ini

编辑该文件设定时区

date.timezone = Asia/Shanghai

(4)设置启动脚本

将安装目录下的启动脚本拷贝至/etc/init.d

启动脚本路径:/usr/local/lnmp/php/sbin/php-fpm

4、安装Nginx

方法一:下载官方rpm包进行安装

方法二:下载源码包,根据自行设定进行安装

以下介绍方法二

(1)将下载的源码进行解压

命令: tar zxf nginx-1.16.0.tar.gz

(2)源码编译和安装

关闭debug日志

路径:/root/nginx-1.16.0/auto/cc/gcc

隐藏版本号

路径:/root/nginx-1.16.0/src/core/nginx.h

configure脚本执行

  1. ./configure --prefix=/usr/local/lnmp/nginx \
  2. --with-http_ssl_module \
  3. --with-http_stub_status_module \
  4. --with-threads \
  5. --with-file-aio \
  6. --user=nginx \
  7. --group=nginx

其中可能遇到缺少pcre,安装pcre-devel即可

configure完成后执行make && make install

(3)进入安装目录下的配置文件目录

编辑配置文件:/usr/local/lnmp/nginx/conf/nginx.conf

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. #charset koi8-r;
  5. #access_log logs/host.access.log main;
  6. location / {
  7. root html;
  8. index index.php index.html index.htm;
  9. }
  10. }
  11. location ~ \.php$ {
  12. root html;
  13. fastcgi_pass 127.0.0.1:9000;
  14. fastcgi_index index.php;
  15. include fastcgi.conf;
  16. }

(4)测试是否能访问php发布文件

发布文件目录:/usr/local/lnmp/nginx/html/index.php(发布文件由个人编写)

5、安装Mysql

方法一:下载官方rpm包进行安装

方法二:下载源码包,根据自行设定进行安装

以下介绍方法二

(1)将下载的源码进行解压

命令: tar zxf mysql-boost-5.7.17.tar.gz

(2)源码编译和安装

在执行cmake脚本前先进行安装以下组件:cmake,ncurses-devel,gcc-c++.x86_64,bison

cmake脚本执行:

  1. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
  2. -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \、
  3. -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
  4. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  5. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  6. -DDEFAULT_CHARSET=utf8 \
  7. -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \
  8. -DWITH_BOOST=boost/boost_1_59_0/

 若出现问题,安装所需软件后需删除CMakeCache.txt,再执行cmake

完成后执行make && make install

(3)配置Mysql

复制默认配置文件:/usr/local/lnmp/mysql/support-files 至/etc/my.cnf并编辑

  1. basedir =/usr/local/lnmp/mysql #Mysql安装目录
  2. datadir =/usr/local/lnmp/mysql/data #Mysql的数据目录
  3. socket =/usr/local/lnmp/mysql/data/mysql.sock

新建mysql用户组,组号为27,并创建mysql用户

groupadd -g 27 mysql

useradd -u 27 -g 27 mysql

修改安装目录下的所属组

chgrp mysql /usr/local/lnmp/mysql -R

chown mysql data -R

(4)执行Mysql配置初始化文件

可将生成的二进制命令目录放入系统环境变量文件中,方便使用

编辑:~/.bash_profile

添加/usr/local/lnmp/mysql/bin

重新加载文件source ~/.bash_profile

初始化Mysql初始化文件

命令:/usr/local/lnmp/mysql/bin/mysqld --user=mysql --initialize

由图可得LkSHtzwlc2(?为root用户初始化密码

开启mysql

命令:/etc/init.d/mysqld start

Mysql的安全初始化

./mysql_secure_installation

  1. Enter password for user root: #输入原root密码
  2. New password: #设置新密码
  3. Re-enter new password:
  4. VALIDATE PASSWORD PLUGIN can be used to test passwords
  5. and improve security. It checks the strength of password
  6. and allows the users to set only those passwords which are
  7. secure enough. Would you like to setup VALIDATE PASSWORD plugin?
  8. #是否添加验证密码插件
  9. Press y|Y for Yes, any other key for No:
  10. Using existing password for root.
  11. Change the password for root ? ((Press y|Y for Yes, any other key for No) :
  12. #是否修改root密码
  13. ... skipping.
  14. By default, a MySQL installation has an anonymous user,
  15. allowing anyone to log into MySQL without having to have
  16. a user account created for them. This is intended only for
  17. testing, and to make the installation go a bit smoother.
  18. You should remove them before moving into a production
  19. environment.
  20. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  21. Success.
  22. #是否移除匿名用户
  23. Normally, root should only be allowed to connect from
  24. 'localhost'. This ensures that someone cannot guess at
  25. the root password from the network.
  26. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  27. Success.
  28. #是否允许匿名用户远程登陆
  29. By default, MySQL comes with a database named 'test' that
  30. anyone can access. This is also intended only for testing,
  31. and should be removed before moving into a production
  32. environment.
  33. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  34. - Dropping test database...
  35. Success.
  36. #是否移除测试数据库
  37. - Removing privileges on test database...
  38. Success.
  39. Reloading the privilege tables will ensure that all changes
  40. made so far will take effect immediately.
  41. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  42. Success.
  43. #是否重新加载数据库

6、部署论坛测试lnmp架构

(1)在php配置文件添加mysql.socket

配置文件:/usr/local/lnmp/php/etc/php.ini

(2)将Discuz解压至Nginx发布目录下

访问该路径并进行安装

若出现以下错误

进入解压后的目录修改权限

选择全新安装

设置安装的数据库信息及管理员

安装成功

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/247005
推荐阅读
相关标签
  

闽ICP备14008679号