LNMP的安装
一.原理
1.LNMP架构解读
LNMP平台就是Linux、Ngnix、MySQL、PHP的组合架构,需要Linux服务器、MySQL数据库、PHP解析环境
2.MySQL安装配置
为了与Nginx、PHP环境保持一致,此处选择采码编译的方式安装MySQL组件
MySQL部署的方法
编译安装MySQL
优化调整
初始化数据库
启动MySQL服务并设置root数据库账号的密码
3.PHP解析环境的安装
配置网页动静分离,解析PHP,有两种方法可以选择 。
使用PHP的FPM模块
将访问PHP页面的Web请求转交给Apache服务器去处理
较新版本的PHP已经自带FPM模块,对PHP解析实例进行管理、优化解析效率
FastCGI将Http|Server和动态脚本语言分离开
Nginx专门处理静态请求,转发动态请求
PHP-FPM专门解析PHP动态请求
单服务器的LNMP架构通常使用FPM方式来解析PHP
编译安装PHP
编译选项时添加“-enable-fpm”以启用此模块安装后的调整
主要是配置文件的建立与相应命令工具的路径优化
安装ZendGuardLoader(提高PHP解析效率),并进行加
载配置
二.安装步骤
安装nginx
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
cd /opt
tar zxvf nginx-1.120.tar.gz -C /opt
编译安装
[root@localhost opt]# cd nginx-1.12.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.12.0]# ss -natp|grep 80
[root@localhost nginx-1.12.0]# nginx
[root@localhost nginx-1.12.0]# ss -natp|grep 80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=4442,fd=6),("nginx",pid=4441,fd=6))
[root@localhost nginx-1.12.0]# kill -3 4441
[root@localhost opt]# cd /etc/init.d/
[root@localhost init.d]# vim nginx
#!/bin/bash
#chkconfig: 35 99 20
#descripton:Nginx Service Control Script
cmd="/usr/local/nginx/sbin/nginx"
pid="/usr/local/nginx/logs/nginx.pid"
case $1 in
start)
$cmd
;;
stop)
kill -3 `cat $pid`
;;
restart)
$0 stop
$0 start
;;
reload)
kill -1 `cat $pid`
;;
*)
echo "please input start,stop,reload,restart:"
exit 0
;;
esac
exit 1
[root@localhost init.d]# chmod +x nginx
[root@localhost init.d]# chkconfig --add nginx
安装数据库
[root@localhost opt]# tar zxf mysql-boost-5.7.20.tar.gz -C /opt
安装依赖环境包
[root@localhost ~]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake
[root@localhost ~]# useradd -s /sbin/nologin mysql
[root@localhost opt]# cd mysql-5.7.20/
[root@localhost mysql-5.7.20]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# make && make install
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# cd /opt/mysql-5.7.20
[root@localhost mysql-5.7.20]# cd /etc
[root@localhost etc]# ls| grep my
my.cnf
my.cnf.d
[root@localhost etc]# cp my.cnf my.cnf.default
[root@localhost etc]# ls| grep my
my.cnf
my.cnf.d
my.cnf.default
[root@localhost etc]# vim my.cnf 清空里面的内容然后黏贴下面的内容
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
设置环境变量
[root@localhost etc]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost etc]# echo 'export PATH' >> /etc/profile
[root@localhost etc]# source /etc/profile
[root@localhost etc]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost mysql]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-11-09 10:29:48 CST; 9s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 24961 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 24939 ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 24964 (mysqld)
CGroup: /system.slice/mysqld.service
└─24964 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.316914Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.317280Z 0 [Note] IPv6 is available.
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.317302Z 0 [Note] - '::' resolves to '::';
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.317317Z 0 [Note] Server socket created on IP: '::'.
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.323027Z 0 [Note] Event Scheduler: Loaded 0 events
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.323198Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: Version: '5.7.20' socket: '/usr/local/mysql/mysql.sock' port: 3306 Source distribution
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.323204Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using t...this check.
Nov 09 10:29:48 localhost.localdomain mysqld[24961]: 2021-11-09T02:29:48.323207Z 0 [Note] Beginning of list of non-natively partitioned tables
Nov 09 10:29:48 localhost.localdomain systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost mysql]# netstat -anpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 24964/mysqld
设置密码,初始是空密码
[root@localhost mysql]# mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
登录数据库
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, 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>
安装php
安装环境
[root@localhost opt]# yum -y install \
> libjpeg \
> libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 \
> libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
编译安装
[root@localhost opt]# tar xjvf php-7.1.10.tar.bz2
[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]# make && make install
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
改成
-----------配置及优化FPM模块--------
[root@localhost ~]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# cd /usr/local/php/etc/
[root@localhost etc]# vi php-fpm.conf
启动此行 取消;
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost etc]# netstat -anpt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 32547/php-fpm: mast
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@localhost etc]# ps aux | grep -c "php-fpm"
4
--------以下是让nginx支持PHP功能--------
[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf
69行改这样
[root@localhost etc]# vi /usr/local/nginx/html/index.php
[root@localhost etc]# service nginx start
在网页测试“http://192.168.133.75/index.php”
--------下面测试数据库工作是否正常-----
mysql -u root -p
CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
########以下安装论坛##########
[root@localhost ~]# cd /opt
[root@localhost opt]# unzip Discuz_X3.4_SC_UTF8.zip
[root@localhost opt]# cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/
网页调试
打开网页http://192.168.133.75/bbs/install/index.php
这里点我同意
这里点下一步
数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:admin123
管理员账号:admin
管理员密码:admin123 自己设定
更多推荐
所有评论(0)