LNMP的平台搭建及源码编译

本文详述了LNMP(Linux, Nginx, MySQL, PHP)平台的搭建过程,包括虚拟机内存分配、各组件的源码编译及配置,如MySQL、PHP的编译技巧,Nginx的配置与测试。还涉及到了论坛搭建、Memcache与Memcached的介绍及实验配置,以及OpenResty的lua应用和加速效果验证。" 119476564,10012219,深澜系统服务器与Portal认证配置详解,"['网络认证', '深澜系统', '服务器配置', '网络安全', 'Radius服务']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

lnmp简介:

LNMP指的是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。
可以在VPS、独立主机上轻松的安装LNMP生产环境。

lnmp的组成:

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

lnmp的特点:

Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 
Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。
Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
优点
编辑
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器
对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一
也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,
还能够在不间断服务的情况下进行软件版本的升级。

准备一个新的虚拟机分配一个可给予的最大内存方便后来的编译不然会很卡:

这里写图片描述

mysql的源码编译:

[root@server6 ~]# ls 准备安装包
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# tar zxf mysql-boost-5.7.17.tar.gz  解压安装包
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# cd mysql-5.7.17/ 进入解压路径
[root@server6 mysql-5.7.17]# ls
boost            dbug                 libmysql     rapid          testclients
BUILD            Docs                 libmysqld    README         unittest
client           Doxyfile-perfschema  libservices  regex          VERSION
cmake            extra                man          scripts        vio
CMakeLists.txt   include              mysql-test   sql            win
cmd-line-utils   INSTALL              mysys        sql-common     zlib
config.h.cmake   libbinlogevents      mysys_ssl    storage
configure.cmake  libbinlogstandalone  packaging    strings
COPYING          libevent             plugin       support-files
[root@server6 mysql-5.7.17]# cd ..
[root@server6 ~]# yum install cmake-  2.8.12.2-4.el6.x86_64.rpm  安装cmake编译工具

这里写图片描述

[root@server6 ~]# cd ..
[root@server6 /]# cd
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# cd mysql-5.7.17/
[root@server6 mysql-5.7.17]# ls
boost            dbug                 libmysql     rapid          testclients
BUILD            Docs                 libmysqld    README         unittest
client           Doxyfile-perfschema  libservices  regex          VERSION
cmake            extra                man          scripts        vio
CMakeLists.txt   include              mysql-test   sql            win
cmd-line-utils   INSTALL              mysys        sql-common     zlib
config.h.cmake   libbinlogevents      mysys_ssl    storage
configure.cmake  libbinlogstandalone  packaging    strings
COPYING          libevent             plugin       support-files

这里写图片描述

[root@server6 mysql-5.7.17]# yum install gcc gcc-c++ -y 安装所需解决依赖性

这里写图片描述

[root@server6 mysql-5.7.17]# cmake 编译-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all 
-- Running cmake version 2.8.12.2
-- Could NOT find Git (missing:  GIT_EXECUTABLE) 
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void *
-- Check size of void * - done
-- SIZEOF_VOIDP 8
-- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG
-- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG - Failed
-- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG
-- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG - Failed
-- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD
-- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD - Failed
-- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD
-- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD - Failed
-- Performing Test HAVE_C_FP_CONTRACT_FLAG
-- Performing Test HAVE_C_FP_CONTRACT_FLAG - Failed
-- Performing Test HAVE_CXX_FP_CONTRACT_FLAG
-- Performing Test HAVE_CXX_FP_CONTRACT_FLAG - Failed
-- MySQL 5.7.17
-- Packaging as: mysql-5.7.17-Linux-x86_64
-- Looked for boost/version.hpp in  and 
-- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
-- LOCAL_BOOST_DIR 
-- LOCAL_BOOST_ZIP 
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 
 -DWITH_BOOST=<directory>
 提示的报错信息,加在编译后面即可

  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.

  If you are inside a firewall, you may need to use an http proxy:

  export http_proxy=http://example.com:80

Call Stack (most recent call first):
  cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:455 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.17/CMakeFiles/CMakeError.log".
[root@server6 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=    两下Tab键可以补齐
boost/               include/             regex/
BUILD/               INSTALL              scripts/
client/              libbinlogevents/     sql/
cmake/               libbinlogstandalone/ sql-common/
CMakeCache.txt       libevent/            storage/
CMakeFiles/          libmysql/            strings/
CMakeLists.txt       libmysqld/           support-files/
cmd-line-utils/      libservices/         testclients/
config.h.cmake       man/                 unittest/
configure.cmake      mysql-test/          VERSION
COPYING              mysys/               VERSION.dep
dbug/                mysys_ssl/           vio/
Docs/                packaging/           win/
Doxyfile-perfschema  plugin/              zlib/
extra/               rapid/               
.gitignore           README               
[root@server6 mysql-5.7.17]# cmake 保留两层路径即可-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=boost/boost_1_59_0/

这里写图片描述

系统提示必须删除CMakeCache.txt,不然解决的依赖性不会被读取
     remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.17/CMakeFiles/CMakeError.log".
[root@server6 mysql-5.7.17]# yum install ncurses-devel -y
安装提示的服务

这里写图片描述

编译时会占用大量的系统资源,建议使用多个核心同时进行编译,否则可能会编译失败,耐心等待即可:

[root@server6 mysql-5.7.17]# rm -fr CMakeCache.txt  删除缓存[root@server6 mysql-5.7.17]# yum install bison -y 安装依赖性
[root@server6 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=boost/boost_1_59_0/

这里写图片描述

[root@server6 mysql-5.7.17]# make 进行读取配置文件

这里写图片描述

[root@server6 mysql-5.7.17]# make install 进行安装

这里写图片描述

[root@server6 mysql-5.7.17]# cd /usr/local/lnmp/mysql/
[root@server6 mysql]# ls
bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[root@server6 mysql]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@server6 mysql]# ll /etc/my.cnf 
-rw-r--r--. 1 root root 251 Aug  9  2013 /etc/my.cnf
[root@server6 mysql]# cat /etc/my.cnf  查看配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@server6 mysql]# cd support-files/
[root@server6 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

这里写图片描述

[root@server6 support-files]# cp my-default.cnf /etc/my.cnf  直接覆盖文件
cp: overwrite `/etc/my.cnf'? y
[root@server6 support-files]# vim /etc/my.cnf  编辑填写提示即可

这里写图片描述

[root@server6 support-files]# file mysql.server  查看文件类型
mysql.server: POSIX shell script text executable
[root@server6 support-files]# cp mysql.server /etc/init.d/mysqld  复制过去即可
[root@server6 support-files]# ll /etc/init.d/mysqld 
-rwxr-xr-x 1 root root 10916 Aug  5 11:02 /etc/init.d/mysqld
[root@server6 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server6 support-files]# cd ..
[root@server6 mysql]# ls
bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[root@server6 mysql]# ll
total 56
drwxr-xr-x  2 root root  4096 Aug  5 10:25 bin
-rw-r--r--  1 root root 17987 Nov 28  2016 COPYING
drwxr-xr-x  2 root root  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root root  4096 Aug  5 10:25 include
drwxr-xr-x  4 root root  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root root  4096 Aug  5 10:25 man
drwxr-xr-x 10 root root  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root root  2478 Nov 28  2016 README

这里写图片描述

[root@server6 mysql]# groupadd -g 27 mysql  建立用户指定组
[root@server6 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql
[root@server6 mysql]# cd bin/
[root@server6 bin]# ls
innochecksum                mysql_config               mysqlshow
lz4_decompress              mysql_config_editor        mysqlslap
myisamchk                   mysqld                     mysql_ssl_rsa_setup
myisam_ftdump               mysqld_multi               mysqltest
myisamlog                   mysqld_safe                mysqltest_embedded
myisampack                  mysqldump                  mysql_tzinfo_to_sql
my_print_defaults           mysqldumpslow              mysql_upgrade
mysql                       mysql_embedded             mysqlxtest
mysqladmin                  mysqlimport                perror
mysqlbinlog                 mysql_install_db           replace
mysqlcheck                  mysql_plugin               resolveip
mysql_client_test           mysqlpump                  resolve_stack_dump
mysql_client_test_embedded  mysql_secure_installation  zlib_decompress
[root@server6 bin]# cd

这里写图片描述

[root@server6 ~]# vim .bash_profile  生成服务启动脚本
[root@server6 ~]# source .bash_
.bash_history  .bash_logout   .bash_profile  
[root@server6 ~]# source .bash_profile  检测语法

这里写图片描述

[root@server6 mysql]# mysqld --initialize --user=mysql 初始化,这个是初始化密码
root@localhost: 2=G7f5.ddIZ=
[root@server6 mysql]# ls
bin      data  include  man         README  support-files
COPYING  docs  lib      mysql-test  share
[root@server6 mysql]# cd data/
[root@server6 data]# ls
auto.cnf        ibdata1      ib_logfile1  performance_schema
ib_buffer_pool  ib_logfile0  mysql        sys
[root@server6 data]# /etc/init.d/mysqld start 可以开启服务
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server6.err'.
. SUCCESS! 
[root@server6 data]# /etc/init.d/mysqld stop  可以停止服务
Shutting down MySQL.. SUCCESS! 
[root@server6 data]# chkconfig --list mysqld
service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')

这里写图片描述

[root@server6 mysql]# chown mysql data/ -R  仅仅更改data目录的用户为mysql
[root@server6 mysql]# ll
total 60
drwxr-xr-x  2 root  mysql  4096 Aug  5 10:25 bin
-rw-r--r--  1 root  mysql 17987 Nov 28  2016 COPYING
drwxr-x---  5 mysql root   4096 Aug  5 11:19 data
drwxr-xr-x  2 root  mysql  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root  mysql  4096 Aug  5 10:25 in
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值