文章目录
实验准备
- 一台rhel6.5的虚拟机(因为MysqL编译安装需要空间比较大,所以配置最好为内存2g,硬盘20g)
- 硬盘如果已经是10g,需要扩容的,参考lvm的逻辑卷扩展。
Nginx模块
Nginx的源码编译
- (1)官网下载源码包并解压
[root@LNMPserver1 ~]# tar zxf Nginx-1.17.0.tar.gz
[root@LNMPserver1 ~]# ls
Nginx-1.17.0 Nginx-1.17.0.tar.gz
- (2)关闭debug日志,否则生产环境中会产生很多debug日志,比较占内存。
[root@LNMPserver1 Nginx-1.17.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@LNMPserver1 Nginx-1.17.0]# cd auto/cc
[root@LNMPserver1 cc]# ls
acc bcc ccc clang conf gcc icc msvc name owc sunc
[root@LNMPserver1 cc]# vim gcc
- (3)安装编译所需要的相关依赖性的包
yum install -y pcre-devel zlib-devel gcc openssl-devel
- (4)检测系统的环境,生成Makefile。
./configure --prefix=/usr/local/lnmp/Nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
出现下面情况说明成功,否则需要根据提示安装相关依赖的包。
@H_404_93@
- (5)编译和安装
[root@LNMPserver1 Nginx-1.17.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@LNMPserver1 Nginx-1.17.0]# make && make install
Nginx相关配置
[root@LNMPserver1 Nginx-1.17.0]# cd /usr/local/lnmp/Nginx/
[root@LNMPserver1 Nginx]# ls
conf html logs sbin
[root@LNMPserver1 Nginx]# cd conf/
[root@LNMPserver1 conf]# ls
fastcgi.conf koi-win scgi_params
fastcgi.conf.default mime.types scgi_params.default
fastcgi_params mime.types.default uwsgi_params
fastcgi_params.default Nginx.conf uwsgi_params.default
koi-utf Nginx.conf.default win-utf
[root@LNMPserver1 conf]# vim Nginx.conf
ln -s /usr/local/lnmp/Nginx/sbin/Nginx /usr/local/sbin/
[root@LNMPserver1 conf]# Nginx -t
Nginx: the configuration file /usr/local/lnmp/Nginx/conf/Nginx.conf Syntax is ok
Nginx: configuration file /usr/local/lnmp/Nginx/conf/Nginx.conf test is successful
[root@LNMPserver1 conf]# Nginx
[root@LNMPserver1 conf]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5068/Nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 886/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 962/master
tcp 0 0 :::22 :::* LISTEN 886/sshd
tcp 0 0 ::1:25 :::* LISTEN 962/master
- (4)浏览器查看是否可用
MysqL模块
MysqL的编译和安装
- (1)官网下载MysqL源码包解压
[root@LNMPserver1 ~]# tar zxf MysqL-boost-5.7.17.tar.gz
[root@LNMPserver1 ~]# ls
libmcrypt-2.5.8-9.el6.x86_64.rpm MysqL-boost-5.7.17.tar.gz PHP-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm Nginx-1.17.0 PHP-5.6.35.tar.bz2
MysqL-5.7.17 Nginx-1.17.0.tar.gz
[root@LNMPserver1 ~]# cd MysqL-5.7.17/
[root@LNMPserver1 MysqL-5.7.17]# ls
boost configure.cmake INSTALL man README support-files
BUILD copYING libbinlogevents MysqL-test regex testclients
client dbug libbinlogstandalone mysys scripts unittest
cmake Docs libevent mysys_ssl sql VERSION
CMakeLists.txt Doxyfile-perfschema libMysqL packaging sql-common vio
cmd-line-utils extra libMysqLd plugin storage win
config.h.cmake include libservices rapid strings zlib
- (2)安装源码编译检测工具cmake
我们这里从pkg.org下载了一个2.8版本的cmake包
yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
- (3)安装编译的依赖包
yum install -y ncurses-devel gcc gcc-c++ bison
- (4)使用cmake进行环境检测
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/
注意:cmake检测过后可能会保留缓存文件,会影响下一次检测,所以需要rm -rf CMakeCache.txt
同时,编译过一次,记得make clean
清楚缓存。
- (5)编译&&安装
make && make install
这个过程可能会比较长,大家耐心等待即可。
MysqL配置
- (1)将MysqL的启动脚本复制到系统启动服务的脚本目录中,并给执行权限。
[root@LNMPserver1 MysqL-5.7.17]# cd support-files/
[root@LNMPserver1 support-files]# ls
build-tags dtrace MysqLd_multi.server MysqL.server.sh
CMakeFiles MacOSX MysqLd_multi.server.sh MysqL.server-sys5.sh
cmake_install.cmake magic MysqL-log-rotate plugins.files
CMakeLists.txt Makefile MysqL-log-rotate.sh
compiler_warnings.supp my-default.cnf MysqL.m4
CTestTestfile.cmake my-default.cnf.sh MysqL.server
[root@LNMPserver1 support-files]# cp MysqL.server /etc/init.d/MysqLd
[root@LNMPserver1 support-files]# chmod +x /etc/init.d/MysqLd
[root@LNMPserver1 etc]# cp my.cnf my.cnf.bak
[root@LNMPserver1 MysqL-5.7.17]# cd support-files/
[root@LNMPserver1 support-files]# ls
build-tags dtrace MysqLd_multi.server MysqL.server.sh
CMakeFiles MacOSX MysqLd_multi.server.sh MysqL.server-sys5.sh
cmake_install.cmake magic MysqL-log-rotate plugins.files
CMakeLists.txt Makefile MysqL-log-rotate.sh
compiler_warnings.supp my-default.cnf MysqL.m4
CTestTestfile.cmake my-default.cnf.sh MysqL.server
[root@LNMPserver1 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
vim /etc/my.cnf
[root@LNMPserver1 support-files]# groupadd -g 27 MysqL
[root@LNMPserver1 support-files]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/MysqL/data -s /sbin/nologin MysqL
[root@LNMPserver1 MysqL-5.7.17]# cd /usr/local/lnmp/MysqL/
[root@LNMPserver1 MysqL]# ls
bin copYING docs include lib man MysqL-test README share support-files
[root@LNMPserver1 MysqL]# mkdir data
[root@LNMPserver1 MysqL]# ll
total 60
drwxr-xr-x 2 root root 4096 Jul 26 16:40 bin
-rw-r--r-- 1 root root 17987 Nov 28 2016 copYING
drwxr-xr-x 2 root root 4096 Jul 26 16:51 data
drwxr-xr-x 2 root root 4096 Jul 26 16:40 docs
drwxr-xr-x 3 root root 4096 Jul 26 16:40 include
drwxr-xr-x 4 root root 4096 Jul 26 16:40 lib
drwxr-xr-x 4 root root 4096 Jul 26 16:40 man
drwxr-xr-x 10 root root 4096 Jul 26 16:41 MysqL-test
-rw-r--r-- 1 root root 2478 Nov 28 2016 README
drwxr-xr-x 28 root root 4096 Jul 26 16:41 share
drwxr-xr-x 2 root root 4096 Jul 26 16:41 support-files
[root@LNMPserver1 MysqL]# chgrp -R MysqL /usr/local/lnmp/MysqL/
[root@LNMPserver1 MysqL]# chown -R MysqL /usr/local/lnmp/MysqL/data/
[root@LNMPserver1 MysqL]# ll
total 60
drwxr-xr-x 2 root MysqL 4096 Jul 26 16:40 bin
-rw-r--r-- 1 root MysqL 17987 Nov 28 2016 copYING
drwxr-xr-x 2 MysqL MysqL 4096 Jul 26 16:51 data
drwxr-xr-x 2 root MysqL 4096 Jul 26 16:40 docs
drwxr-xr-x 3 root MysqL 4096 Jul 26 16:40 include
drwxr-xr-x 4 root MysqL 4096 Jul 26 16:40 lib
drwxr-xr-x 4 root MysqL 4096 Jul 26 16:40 man
drwxr-xr-x 10 root MysqL 4096 Jul 26 16:41 MysqL-test
-rw-r--r-- 1 root MysqL 2478 Nov 28 2016 README
drwxr-xr-x 28 root MysqL 4096 Jul 26 16:41 share
drwxr-xr-x 2 root MysqL 4096 Jul 26 16:41 support-files
[root@LNMPserver1 MysqL]# vim ~/.bash_profile
[root@LNMPserver1 MysqL]# source ~/.bash_profile
[root@LNMPserver1 MysqL]# MysqL
MysqL MysqLd_multi MysqL_secure_installation
MysqLadmin MysqLd_safe MysqLshow
MysqLbinlog MysqLdump MysqLslap
MysqLcheck MysqLdumpslow MysqL_ssl_rsa_setup
MysqL_client_test MysqL_embedded MysqLtest
MysqL_client_test_embedded mysqlimport MysqLtest_embedded
MysqL_config MysqL_install_db MysqL_tzinfo_to_sql
MysqL_config_editor MysqL_plugin MysqL_upgrade
MysqLd MysqLpump MysqLxtest
MysqLd --user=MysqL --initialize
# 命令执行后最后一行会有初始密码:
2019-07-26T08:55:52.192099Z 1 [Note] A temporary password is generated for root@localhost: dVvYXr!0p/Fi
注意:如果初始化出现问题,则进入data数据的目录下将已经生成的东西删掉,再次执行即可
[root@LNMPserver1 MysqL]# /etc/init.d/MysqLd start
Starting MysqL.Logging to '/usr/local/lnmp/MysqL/data/LNMPserver1.err'.
SUCCESS!
[root@LNMPserver1 MysqL]# MysqL_secure_installation
[root@LNMPserver1 MysqL]# MysqL -uroot -predhat
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 6
Server version: 5.7.17 Source distribution
copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MysqL> show databases;
+--------------------+
| Database |
+--------------------+
| @R_551_4045@ion_schema |
| MysqL |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
PHP模块
PHP的编译和安装
- (1)官网下载PHP源码包解压
[root@LNMPserver1 ~]# tar jxf PHP-5.6.35.tar.bz2
[root@LNMPserver1 ~]# ls
Nginx-1.17.0 Nginx-1.17.0.tar.gz PHP-5.6.35 PHP-5.6.35.tar.bz2
[root@LNMPserver1 ~]# cd PHP-5.6.35
- (2)安装编译时所需的依赖性
yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm -y
# 这两个包需要去官网上下载,比如pkg.org等。
yum install -y libxml2-devel
yum install -y libcurl-devel openssl-devel
yum install -y libjpeg-turbo-1.2.1-1.el6.x86_64
yum install -y 2:libpng-1.2.49-1.el6_2.x86_64
yum install -y freetype-devel
yum install -y gmp-devel-4.3.1-7.el6_2.2.x86_64
yum install -y net-snmp-devel
./configure --prefix=/usr/local/lnmp/PHP --with-config-file-path=/usr/local/lnmp/PHP/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext --with-pear --enable-MysqLnd --with-MysqL=MysqLnd --with-MysqLi=MysqLnd --with-pdo-MysqL=MysqLnd --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=Nginx --with-fpm-group=Nginx --with-mcrypt --with-mhash
检测成功:
- (4)编译&&安装
make && make install
PHP相关配置
useradd Nginx
[root@LNMPserver1 PHP-5.6.35]# cd /usr/local/lnmp/PHP/
[root@LNMPserver1 PHP]# ls
bin etc include lib PHP sbin var
[root@LNMPserver1 PHP]# cd etc/
[root@LNMPserver1 etc]# ls
pear.conf PHP-fpm.conf.default
[root@LNMPserver1 etc]# cp PHP-fpm.conf.default PHP-fpm.conf
vim PHP-fpm.conf
[root@LNMPserver1 fpm]# ls
config.m4 init.d.PHP-fpm Makefile.frag PHP-fpm.8.in PHP-fpm.service status.html.in
CREDITS init.d.PHP-fpm.in PHP-fpm PHP-fpm.conf PHP-fpm.service.in tests
fpm LICENSE PHP-fpm.8 PHP-fpm.conf.in status.html www.conf.in
[root@LNMPserver1 fpm]# pwd
/root/PHP-5.6.35/sapi/fpm
[root@LNMPserver1 fpm]# cp init.d.PHP-fpm /etc/init.d/PHP-fpm
[root@LNMPserver1 fpm]# chmod +x /etc/init.d/PHP-fpm
- (5)开启服务,并查看其端口,默认为9000
[root@LNMPserver1 fpm]# /etc/init.d/PHP-fpm start
Starting PHP-fpm done
[root@LNMPserver1 fpm]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5068/Nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5089/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 962/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9462/PHP-fpm
tcp 0 0 :::22 :::* LISTEN 5089/sshd
tcp 0 0 ::1:25 :::* LISTEN 962/master
验证测试
[root@LNMPserver1 html]# vim index.PHP
[root@LNMPserver1 html]# cat index.PHP
<?PHP
PHPinfo()
?>
- 浏览器查看,至此,我们的LNMP架构搭建成功!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。