目录
1、linux环境准备
1、关闭selinux
setenforce 0
cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2、关闭防火墙(不关闭防火墙就开放端口 80 、9000、3066)
systemctl stop firewalld.service
systemctl disable firewalld.service
2、nginx搭建
https://blog.youkuaiyun.com/weixin_47647077/article/details/119543825
3、mysql搭建
https://blog.youkuaiyun.com/weixin_47647077/article/details/117965667
4、php搭建
4.1、环境搭建
1、php依赖环境(基础库)
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install -y freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
yum -y install sqlite-devel
yum install oniguruma-devel -y
查看安装结果:
rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
libiconv-devel这个包可能安装不上下载下载安装:
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar -zxf libiconv-1.16.tar.gz
cd libiconv-1.16/
./configure --prefix=/usr/local/libiconv
make
make install
安装:libmcrypt-devel、mhash、mcrypt(属于php相关扩展库)(需要epel源)
yum install -y libmcrypt-devel
yum install -y mhash
yum install -y mcrypt
查看安装结果:
rpm -aq mcrypt libmcrypt-devel mhash
4.2、php安装
1、官网下载https://www.php.net/downloads
2、解压
tar -zxf php-7.4.22.tar.gz -C /opt/
3、安装
cd /opt/php-7.4.22/
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql/ \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
make
make install
4.3、配置启动
1、配置更改
cp -r /opt/php-7.4.22/php.ini-production /usr/local/php/lib/php.ini
cd /usr/local/php/etc
cp -r php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp -r www.conf.default www.conf
2、启动
/usr/local/php/sbin/php-fpm
3、查看
ps aux|grep php
5、配置nginx链接php和php链接mysql
5.1、主配置文件
cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include conf.d/*.conf;
}
5.2、wordpress.conf配置文件
cat conf.d/wordpress.conf
server {
listen 8080;
server_name localhost;
location / {
root html/blog/wordpress/;
index index.php index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
include fscgi.conf;
include my-proxy.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
5.3、fscgi.conf配置
cat fscgi.conf
# 缓冲区配置
fastcgi_buffering on; # 默认启用缓冲区
fastcgi_buffers 8 64k; # 若响应数据大小小于512KB,则会分配8个64KB缓冲区为其缓
# 冲;若大于512KB,则超出的部分会存储到临时文件中
fastcgi_buffer_size 64k; # 读取FastCGI服务器响应数据第一部分的缓冲区大小为64KB,
# 通常包含响应头信息
fastcgi_busy_buffers_size 128K; # 繁忙时向客户端发送响应的缓冲区大小为128KB
fastcgi_limit_rate 0; # 默认不做限制
fastcgi_max_temp_file_size 1024M; # 临时文件中大小为1024MB
fastcgi_temp_file_write_size 64k; # 每次写入临时文件的数据大小为64KB
# fastcgi_temp_path使用默认配置
# 请求处理
fastcgi_request_buffering on; # 默认启用读取整个请求体到缓冲区后再向FastCGI服务器发送请求
fastcgi_pass_request_body on; # 默认将客户端请求体传递给FastCGI服务器
fastcgi_pass_request_headers on; # 默认将客户端请求头传递给FastCGI服务器
# FastCGI连接配置
fastcgi_connect_timeout 60s; # 默认Nginx与FastCGI服务器建立连接的超时时间为60s
fastcgi_keep_conn on; # 启用保持连接
fastcgi_ignore_client_abort on; # 当客户端关闭连接时,同时关闭与FastCGI服务器的连接
fastcgi_read_timeout 60s; # 默认连续两个从FastCGI服务器接收数据的读操作之间的间隔
# 时间为60s
fastcgi_send_timeout 60s; # 默认连续两个发送到FastCGI服务器的写操作之间的间隔时间
# 为60s
fastcgi_socket_keepalive on; # FastCGI的连接启用so-keepalive socket选项
# 响应处理
fastcgi_force_ranges on ; # 强制启用byte-range请求支持
fastcgi_hide_header X-Powered-By; # 隐藏PHP版本字段
# fastcgi_pass_header无必须传递的特殊头字段属性
fastcgi_ignore_headers X-Accel-Redirect X-Accel-Expires X-Accel-Limit-Rate X-Accel-Buffering X-Accel-Charset Expires Cache-Control Set-Cookie Vary;
# 禁止Nginx处理从FastCGI获取响应的头属性字段
# 异常处理
fastcgi_intercept_errors on; # 在FastCGI响应数据中响应码大于等于300时重定向给Nginx
fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_403 http_404 http_429; # 当出现指定的条件时,将用户请求传递给upstream
# 中的下一个服务器
fastcgi_next_upstream_timeout 0; # 不限制将用户请求传递给upstream中的下一个
# 服务器的超时时间
fastcgi_next_upstream_tries 0; # 不限制将用户请求传递给upstream中的下一个
# 服务器的尝试次数
5.4、my-proxy.conf配置
cat my-proxy.conf
#基本的代理参数
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
5.5、nginx链接php测试脚本
cat /usr/local/nginx/html/blog/wordpress/nginx-php.php
<?php
phpinfo();
?>
网页访问
http://192.168.0.3:8080/nginx-php.php
5.6、php链接mysql测试脚本
cat /usr/local/nginx/html/blog/wordpress/php-mysql.php
<?php
$link_id=mysqli_connect('192.168.0.3','lnmp','123456') or mysql_error();
if($link_id){
echo "ok";
}
else{
echo mysql_error();
}
?>
网页访问:
http://192.168.0.3:8080/php-mysql.php
6、部署wordpress
6.1、下载
wget https://cn.wordpress.org/wordpress-5.7.2-zh_CN.tar.gz
tar -zxf wordpress-5.7.2-zh_CN.tar.gz -C /opt
cp -r /opt/wordpress/* /usr/local/nginx/html/blog/wordpress
6.2、配置数据库
1、创建数据库
CREATE DATABASE `wordpress`;
2、创建用户及授权
grant all on wordpress.* to wordpress@'192.168.0.%' identified by '123456';
grant all on wordpress.* to wordpress@'localhost' identified by '123456';
3、刷新权限
flush privileges;
网页访问:
这个图忘接了用别人的大体是这样的
往下就就简单了和注册账号类似
7、改跨主机连mysql
1、再找应该主机配好网络
配置mysql
https://blog.youkuaiyun.com/weixin_47647077/article/details/117965667
2、在原来的服务器上备份mysql(备份服务器my.cnf要配置 log-bin=mysql-bin )
全备:
mysqldump -uroot -p -A -R -E --triggers --master-data=2 --single-transaction --set-gtid-purged=OFF >/data/backup/full.sql
只备对应的库:
mysqldump -uroot -p -B wordpress --set-gtid-purged=OFF >./wordpress.sql
3、在准备好的数据库服务器写入
mysql -uroot -p < full.sql
mysql -uroot -p < wordpress.sql
后面那个需要查询授权管理:
grant all on wordpress.* to wordpress@'192.168.0.%' identified by '123456';
7.1、改配置文件
cat /usr/local/nginx/html/blog/wordrpress/wp-config.php|grep DB_HOST
改这行ip改成对应的新mysql服务器的IP
define( 'DB_HOST', '192.168.0.4' );
原来的mysql可以关闭了
从新访问
http://192.168.0.3:8080/
8、远程挂载nfs服务器
8.1、服务端配置
1、安装服务端nfs
yum -y install nfs-utils rpcbind
systemctl start rpcbind.service
systemctl enable rpcbind.service
systemctl start nfs
systemctl enable nfs
2、配置和客户一样的用户和id
groupadd -g 304 www
useradd -u 304 www -g 304
3、配置nfs远程挂载目录
cat /etc/exports
/data/wordpress 192.168.0.0/24(rw,sync,all_squash,anonuid=304,anongid=304)
4、目录权限
chown www.www /data/wordpress
5、查看共享
exportfs -rv
exporting 192.168.0.0/24:/data/wordpress
6、发布共享
showmount -e
Export list for mysql05:
/data/wordpress 192.168.0.0/24
8.2、客户端配置
1、安装
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind
2、查看共享目录
showmount -e 192.168.0.5
3、挂载(挂载前一定要把里面的文件移出来否则会覆盖)
mount 192.168.0.5: /data/wordpress /usr/local/nginx/html/blog/wordpress/wp-content/uploads
这个uploads是wordpress的资源加载目录
4、df -h 查看
5、写入配置
vim /etc/fstab
192.168.0.5:/data/wordpress /usr/local/nginx/html/blog/wordpress/wp-content/uploads nfs defaults,_netdev 0 0