一.编译安装Nginx

1.关闭防火墙

systemctl stop firewalldsystemctl disable firewalldsetenforce 0

2.安装依赖包

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

3.创建运行用户

nginx 服务程序默认 以 nobody 身份运行,建议为其创建专门的用户账户,以便更准确的控制访问权限

useradd -M -s /sbin/nologin nginx

4.解压软件包并编译安装

#切换至/optcd /opt #解压nginx文件tar zxvf nginx-1.12.0.tar.gz#切换目录cd nginx-1.12.0/​#检测环境并安装功能./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_module​#安装make-j4 && make install

5.软连接使nginx可以补全

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

6.添加nginx系统服务

#创建.service文件vim /lib/systemd/system/nginx.service #文件内容[Unit]Description=nginxAfter=network.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target​ ##磁盘上的ngin服务更改,运行'systemctl daemon-reload'重新加载单元。systemctl daemon-reload systemctl start nginx

二.编译安装mysql服务

1.安装依赖环境

yum -y install \ncurses \ncurses-devel \bison \cmake

2.创建运行用户

 useradd -s /sbin/nologinmysql

3.解压软件包并安装编译

#切换至/optcd /opt/ #解压下载好的压缩包tar -zxf mysql-boost-5.7.20.tar.gz#切换至解压后的目录cd 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​#安装(时间较久make-j4 && make install #############################注释#############################-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \#指定mysql的安装路径-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \#指定mysql进程监听套接字文件(数据库连接文件)的存储路径-DSYSCONFDIR=/etc \#指定配置文件的存储路径-DSYSTEMD_PID_DIR=/usr/local/mysql \#指定进程文件的存储路径-DDEFAULT_CHARSET=utf8\#指定默认使用的字符集编码,如utf8-DDEFAULT_COLLATION=utf8_general_ci \#指定默认使用的字符集校对规则-DWITH_INNOBASE_STORAGE_ENGINE=1 \#安装INNOBASE存储引擎-DWITH_ARCHIVE_STORAGE_ENGINE=1 \#安装ARCHIVE存储引擎-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \#安装BLACKHOLE存储引擎-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \#安装FEDERATED存储引擎-DMYSQL_DATADIR=/usr/local/mysql/data \#指定数据库文件的存储路径-DWITH_BOOST=boost \#指定boost的路径,-DWITH_SYSTEMD=1#生成便于systemctl管理的文件

4.数据库目录进行权限调整

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

5.修改配置文件

#进入配置文件,把内容全删掉,然后加入以下内容vim /etc/my.cnf​[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock​[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock​[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-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​

6.设置环境变量

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

7.初始化数据库

#切换至指定目录cd /usr/local/mysql/​#初始化数据库bin/mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/data​#拷贝文件cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

8.检测数据库开启自启、关闭状态

9.设置mysql密码

ln -s /usr/local/mysql/bin/mysqladmin /usr/bin#找不到mysqladmin该命令时做一个软链接 mysqladmin -uroot -p password "abc123"# 命令 -u 用户 -p 旧密码(默认为空) password 新密码

此处可能出现输入命令mysql或mysqladmin会发现提示命令不存在

这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。

首先得知道mysql命令或mysqladmin命令的完整路径,

比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:

ln -s /usr/local/mysql/bin/mysql /usr/bin

比如mysqladmin的路径是:/usr/local/mysql/bin/mysqladmin,我们则可以这样执行命令:

ln -s /usr/local/mysql/bin/mysqladmin /usr/bin

10.登录数据库

mysql -u root -p #登入数据库验证是否成功quit#退出数据库

三.安装PHP

1.安装环境依赖包

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

2.编译安装

#切换至/opt目录cd /opt/#解压文件tar -jxf php-7.1.10.tar.bz2 #切换至解压后的目录cd 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​#安装make -j4 && make install

3.修改PHP配置文件

PHP三个配置文件:

php.ini 核心配置文件

php-fpm.conf 进程服务配置文件

www.conf 扩展配置文件

(1)修改php.ini 核心配置文件
#复制cp php.ini-development /usr/local/php/lib/php.ini #进入核心配置文件vim /usr/local/php/lib/php.ini #注意格式(空格)修改第1170行和939行(去掉注释1170 mysqli.default_socket = /usr/local/mysql/mysql.sock939 date.timezone = Asia/Shanghai​#验证安装的模块/usr/local/php/bin/php -m

(2)修改php-fpm.conf 进程服务配置文件
#配置及优化FPM模块cd /usr/local/php/etc/cpphp-fpm.conf.default php-fpm.confcd /usr/local/php/etc/php-fpm.d/cp www.conf.default www.conf​#进入目录cd /usr/local/php/etc/#进入进程服务配置文件 vim php-fpm.confpid = run/php-fpm.pid#将这一行注释去掉(第17行​#创建/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini​#查看结果ps aux | grep -c "php-fpm" 

4.配置nginx支持PHP功能

#进入nginx主配置文件vim /usr/local/nginx/conf/nginx.conf ​#65到71行 取消注释,修改location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;#将/scripts修改为nginx的工作目录includefastcgi_params;}​

5.创建并验证PHP测试页

#创建网页文件vim /usr/local/nginx/html/index.php​

四.部署Discuz!论坛

1.测试数据库工作

#登入数据库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;​quit #修改原测试页内容vim /usr/local/nginx/html/index.php Success!!";else echo "Fail!!";?> #重启服务systemctl restart nginx​

2.部署完整过程

#切换至/opt解压论坛压缩包cd /optunzip Discuz_X3.4_SC_UTF8.zip​#切换至解压后的文件cd dir_SC_UTF8/​#拷贝文件至数据cp -r upload/ /usr/local/nginx/html/bbs/​#切换至数据库文件cd /usr/local/nginx/html/bbs/​#授权chown -R root:nginx ./config/chown -R root:nginx ./data/chown -R root:nginx ./uc_client/chown -R root:nginx ./uc_server/​chmod -R 777 ./config/chmod -R 777 ./data/chmod -R 777 ./uc_client/chmod -R 777 ./uc_server/

3.网页测试

http://192.168.227.101/bbs/install/index.php#安装 http://192.168.227.101/bbs/index.php#可以直接去论坛首页#####################数据库信息######################### 数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号数据库名字:bbs数据库用户名:bbsuser数据库密码:admin123管理员账号:admin管理员密码:admin123

五.安装wordpress博客

#创建数据库mysql -u root -pcreate database wordpress;grant all privileges on wordpress.* to 'wordpress'@'%' identified by 'abc123';grant all privileges on *.* to 'root'@'%' identified by 'abc123';flush privileges;quit #解压软件包cd /optunzip wordpress-4.9.4-zh_CN.zip #授权mkdir /usr/local/nginx/html/wordpresscp -r wordpress/*/usr/local/nginx/html/wordpresschown -R nginx:nginx /usr/local/nginx/html/wordpress/chmod 777 wordpress/ #网页访问192.168.79.210/wordpress/wp-admin/setup-config.php http://192.168.79.210/wordpress/wp-admin/index.php

六.yum安装LNMP架构(简要过程参考)

//准备工作systemctl stop firewalldsetenfore 0 //安装 nginxvim /etc/yum.repos.d/nginx.repo[nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1yum install nginx -y nginx -v systemctl start nginxsystemctl enable nginx//安装 mysql 5.7 (mariadb)yum remove mariadb* -y wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmyum -y install mysql57-community-release-el7-10.noarch.rpmsed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repoyum -y install mysql-community-server或wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpmrpm -ivh mysql57-community-release-el7-11.noarch.rpmsed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repoyum -y install mysql-server systemctl start mysqld.servicesystemctl enable mysqld.service grep "password" /var/log/mysqld.log#在日志文件中找出root用户的初始密码2021-07-31T07:55:00.366359Z 1 [Note] A temporary password is generated for root@localhost: ga7%<d<0*jD& grep "password" /var/log/mysqld.log | awk '{print $NF}' //登录 mysqlmysql -uroot -pEnter password: #输入初始密码 ga7%<d<0*jD& ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123'; #密码设置要求有 大小写字母、数字和符号 组合 grant all privileges on *.* to root@"%" identified by "Admin@123" with grant option;flush privileges; yum -y remove mysql57-community-release-el7-10.noarch #为了防止每次yum操作都会自动更新,卸载这个软件//安装 php7.2rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-redissystemctl start php-fpmsystemctl enable php-fpmphp -v//配置 nginx 支持 PHP 解析cd /etc/nginx/conf.dvim default.conf......location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME/usr/share/nginx/html$fastcgi_script_name;#将 /scripts 修改为nginx的工作目录includefastcgi_params;} systemctl restart nginx cd /usr/share/nginx/htmlvim index.phpSuccess!!";else echo "Fail!!";?> 浏览器访问:http://192.168.79.210/index.php