自学内容网 自学内容网

分布式安装LNMP

目录

搭建LNMP架构

安装mysql

1.上传mysql软件包,关闭防火墙和核心防护

2.安装环境依赖包,桌面安装可能有自带的数据库除

3.配置软件模块

4.编译及安装

5.创建mysql用户

6.修改mysql 配置文件

7.更改mysql安装目录和配置文件的属主属组

8.设置路径环境变量

9.初始化数据库

10.添加mysqld系统服务

11.修改mysql 的登录密码

12.授权远程登录

安装nginx

1.上传nginx软件包,关闭防火墙和核心防护

2.安装环境依赖包

3.创建运行用户、组

4.配置软件模块

5.安装编译

6.让系统识别nginx的操作命令

7.设置syetemctl管理服务

安装php

1.上传php软件包,关闭防火墙和核心防护

2.安装GD库和GD库关联程序,用来处理和生成图片

3.配置软件模块

4.编译安装

5、路径优化

6、调整PHP配置文件

7、启动php-fpmcd /opt/php-7.1.10/sapi/fpm

8、配置 Nginx 支持 PHP 解析(nginx机器)

9、共享nginx网页目录

在LNMP架构下安装论坛


准备三台虚拟机分别用来安装nginx,mysql和php

搭建LNMP架构

安装mysql
1.上传mysql软件包,关闭防火墙和核心防护

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2.安装环境依赖包,桌面安装可能有自带的数据库除

删除mariadb数据库
yum remove mariadb* -y
安装依赖环境
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake openssl-devel

3.配置软件模块

先解压软件包
tar -xf  mysql-boost-5.7.44.tar.gz

配置软件模块
cd mysql-5.7.44
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_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

4.编译及安装

make -j 2 && make install

5.创建mysql用户

useradd -M -s /sbin/nologin  mysql

6.修改mysql 配置文件

vim /etc/my.cnf    

[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysql]
port = 3306
socket = /usr/local/mysql/mysql.sock
auto-rehash

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8mb4
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=4096
default-storage-engine=INNODB
max_allowed_packet=32M
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

7.更改mysql安装目录和配置文件的属主属组

useradd -M -s /sbin/nologin mysql

chown -R mysql:mysql /usr/local/mysql/

chown mysql:mysql /etc/my.cnf

8.设置路径环境变量

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile    
source /etc/profile

9.初始化数据库

./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

10.添加mysqld系统服务

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload(刷新识别)
systemctl start mysqld.service(开启服务)
systemctl enable mysqld(开机自启动)

netstat -anpt | grep 3306(查看端口)

11.修改mysql 的登录密码

mysqladmin -u root password "admin123"

12.授权远程登录

cd /usr/local/mysql/bin/

mysql -u root -padmin123
grant all privileges on *.* to 'root'@'%' identified by 'admin123';
quit

安装nginx
1.上传nginx软件包,关闭防火墙和核心防护

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2.安装环境依赖包

yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make

3.创建运行用户、组

useradd -M -s /sbin/nologin nginx

4.配置软件模块

tar xf nginx-1.26.2.tar.gz

cd nginx-1.26.2/ 

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

5.安装编译

make && make install

6.让系统识别nginx的操作命令

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

7.设置syetemctl管理服务

vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

chmod 754 /lib/systemd/system/nginx.service

systemctl start nginx.service
systemctl enable nginx.service

netstat -lntp | grep nginx

安装php
1.上传php软件包,关闭防火墙和核心防护

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2.安装GD库和GD库关联程序,用来处理和生成图片

yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

3.配置软件模块

tar xf php-7.1.10.tar.bz2

./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

4.编译安装

make && make install

5、路径优化

ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/

6、调整PHP配置文件

cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini

vim /usr/local/php/lib/php.ini

date.timezone = Asia/Shanghai

cd /usr/local/php/etc/

cp  php-fpm.conf.default php-fpm.conf

vim php-fpm.conf

pid = run/php-fpm.pid

cd /usr/local/php/etc/php-fpm.d/

user = nginx
group = nginx

listen = 192.168.110.50:9000

listen.allowed_clients = 192.168.110.60

useradd -M -s /sbin/nologin  nginx

7、启动php-fpmcd /opt/php-7.1.10/sapi/fpm

cp /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini

cp php-fpm.service /usr/lib/systemd/system/php-fpm.service

systemctl restart php-fpm.service

netstat -lntp | grep php

8、配置 Nginx 支持 PHP 解析(nginx机器)

vim /usr/local/nginx/conf/nginx.conf

nginx -t

systemctl restart nginx.service

9、共享nginx网页目录

安装nfs

yum -y install rpcbind nfs-utils(php和nginx安装)

vim /etc/exports(nginx机器)

/usr/local/nginx/html 192.168.110.50(rw,sync)

systemctl enable --now rpcbind nfs

showmount -e 192.168.110.60(php机器)

挂载

mkdir -p /usr/local/nginx/html

mount 192.168.110.60:/usr/local/nginx/html /usr/local/mginx/html

vim /usr/local/nginx/conf/nginx.conf(nginx机器)

systemctl restart nginx.service

创建测试页面

网页访问

测试mysql能否联通

创建测试页面

网页访问

在LNMP架构下安装论坛

上传软件包(在nginx机器上)

解压

unzip Discuz_X3.4_SC_UTF8.zip

cd dir_SC_UTF8

cp -r upload/ /usr/local/nginx/html/discuz

chown -R nginx discuz

创建数据库

mysql -u root -padmin123

创建数据库discuz

create database discuz;

grant all on discuz.* to 'discuz'@'%'identified by'admin123';

flush privileges;

quit

浏览器访问

http://192.168.110.60/discuz

完成


原文地址:https://blog.csdn.net/m0_67475830/article/details/142440632

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!