一.运行环境
192.168.32.132 Server-Web linux Web
192.168.32.133 Server-NFS-DNS linux NFS/DNS
基础配置
1.配置主机名+静态ip
2.开启防火墙并配置
3.部分开启selinux并配置
4.服务器之间通过阿里云进行时间同步
5.服务器之间实现ssh免密登录
业务需求
1.Server-web主机配置Web服务,通过域名www.opelab.com可以访问到自己建的博客网站
2.Server-NFS-DNS主机配置NFS服务,将博客网站资源共享给Server-web主机,同时配置DNS服务
二.准备工作(基本配置)
2.1.修改主机名同时进行host映射
[root@Server ~]#hostnamectl set-hostname Server-web
[root@node ~ ]#hostnamectl set-hostname Server-NFS-DNS
在两个主机中进行host映射
#vim /etc/hosts
#reboot
2.2.配置静态ip
[root@Server-NFS-DNS ~]# nmcli c mod ens32 ipv4.method manual ipv4.address 192.168.32.133/24 ipv4.gateway 192.168.32.2 ipv4.dns 114.114.114.114
[root@Server-NFS-DNS ~]# nmcli c reload
[root@Server-NFS-DNS ~]# nmcli c up ens32[root@Server-web ~]# nmcli c mod ens32 ipv4.method manual ipv4.address 192.168.32.132/24 ipv4.gateway 192.168.32.2 ipv4.dns 192.168.32.133
[root@Server-web ~]# nmcli c reload
[root@Server-web ~]# nmcli c up ens32#查看DNS:[root@Server-NFS-DNS ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
2.3.防火墙和selinux设置
#开启防火墙,两个主机都操作
systemctl start firewalld
systemctl enable firewalld#开启selinux,Server-web端关闭,Server-NFS-DNS端开启
关闭:setenforce 0
开启:setenforce 1#若是开启失败,则:
[root@Server-NFS-DNS ~]#yum install selinux-policy selinux-policy-targeted -y
[root@Server-NFS-DNS ~]#vim /etc/seliux/config
SELINUX=permissive
[root@Server-NFS-DNS ~]#touch /.autorelabel
[root@Server-NFS-DNS ~]#reboot
2.4.进行阿里云时间同步
#两台主机都操作
#yum install chrony -y
#vim /etc/chrony.conf
server ntp.aliyun.com iburst
#systemctl restart chronyd
#chronyc sources -v
#timedatectl status
2.5.ssh免密登录
[root@Server-NFS-DNS ~]# ssh-keygen -t rsa
[root@Server-NFS-DNS ~]# ssh-copy-id 192.168.32.132[root@Server-web ~]# ssh-keygen -t rsa
[root@Server-web ~]# ssh-copy-id 192.168.32.133
三.环境搭建
1.Server-web端环境搭建设置
[root@Server-web ~]#yum install nginx mariadb-server php* -y
2.Server-NFS-DNS端的环境搭建设置
博客压缩包下载链接: Release Archive | WordPress.org China 简体中文
[root@Server-NFS-DNS ~]# cd /
[root@Server-NFS-DNS ~]# unzip wordpress-6.1-zh_CN.zip
四.NFS服务搭建
1.将服务端的/wordpress目录共享给客户端192.168.32.1-web)
[root@Server-NFS-DNS ~]# yum install rpcbind -y
[root@Server-NFS-DNS ~]# yum install nfs-utils -y
[root@Server-NFS-DNS ~]# vim /etc/exports
/wordpress 192.168.32.132(rw,sync,all_squash)
#设置权限
[root@Server-NFS-DNS ~]# chmod -Rf 777 /wordpress
#防火墙放行及启动
[root@Server-NFS-DNS ~]# firewall-cmd --permanent --zone public --add-service=mountd
[root@Server-NFS-DNS ~]# firewall-cmd --permanent --zone public --add-service=rpc-bind
[root@Server-NFS-DNS ~]# firewall-cmd --permanent --zone public --add-service=nfs
[root@Server-NFS-DNS ~]# firewall-cmd --reload
[root@Server-NFS-DNS ~]# systemctl start rpcbind
[root@Server-NFS-DNS ~]# systemctl start nfs-utils
#设置zseliux的上下文文件
[root@Server-NFS-DNS ~]# ls -Z /usr/share/nginx/html
[root@Server-NFS-DNS ~]# chcon -t httpd_sys_content_t /wordpress -Rv
R代表递归修改目录,v表示显示修改提示
2.远程目录的挂载
#临时挂载
[root@Server-web ~]# yum install nfs-utils -y
[root@Server-web ~]# showmount -e 192.168.32.133
[root@Server-web ~]# mkdir -pv /wp
[root@Server-web ~]# mount -t nfs 192.168.32.133:/wordpress /wp
[root@Server-web ~]# cd /wp
[root@Server-web ~]# ll
若是想开机自动挂载,可以先查看分区的uuid,
#blkid
编辑开机自动挂载文件:
#vim /etc/fstab
UUID=6b1c1143-4556-46b9-9d44-0a60c993825e / xfs defaults 0 0
五.nginx服务搭建
[root@Server-web ~]# firewall-cmd --permanent --zone public --add-service=http
[root@Server-web ~]# firewall-cmd --permanent --zone public --add-port=80/tcp
[root@Server-web ~]# firewall-cmd --reload
[root@Server-web ~]# vim /etc/ngx/nginx.conf
[root@Server-web ~]#systemctl restart nginx
六.数据库创建和修改wordpress配置文件
启动数据库:systemctl start mariadb
[root@Server-web ~]#mysql>create database wordpress; >create user 'test1'@'localhost' identified by '1234';>grant all on wordpress.* to 'test1'@'localhost'; #授权>exit
修改wordpress 配置文件
[root@Server-web ~]#cd /wp
[root@Server-web wp]#cp wp-config-sample.php wp-config.php
[root@Server-web wp]#vim wp-config.php
systemctl restart mariadb
systemctl restart nginx
七.使用IP地址进行测试
八.DNS服务搭建
[root@Server-NFS-DNS ~]# yum install bind -y
[root@Server-NFS-DNS ~]# firewall-cmd --permanent --zone pulic --add-servce=dns
[root@Server-NFS-DNS ~]# firewall-cmd --reload
[root@Server-NFS-DNS ~]# systemctl start named
[root@Server-NFS-DNS ~]# vim /etc/named.conf
[root@Server-NFS-DNS ~]# vim /etc/named.rfc1912.zones
[root@Server-NFS-DNS ~]# cd /var/named
[root@Server-NFS-DNS ~]# cp -a named.localhost openlab.com
[root@Server-NFS-DNS named]# vim openlab.com
[root@Server-NFS-DNS ~]# systemctl restart named
九.使用域名进行测试
如果想要在windows系统上测试,需要手动更改dns为192.168.32.133