搭建nfs服务器见:
修改想挂载的文件:vim /etc/exports
添加挂在目录
/home/share *(rw,no_root_squash)
重新加载:
exportfs -rv
其他机器访问测试:换个机子查看,会看到挂载路径
showmount -e 172.26.144.159
在其他机器youxi2上挂载NFS:
mkdir /home/html
获取挂载:
mount -t nfs 172.26.144.159:/home/share /home/html
我是搭建在/home/share
在home/share下创建yaml文件 nfs-client.yaml
内容格式:
nfs:
server: "172.26.144.159" # This is the server IP address. Replace it with your own.
path: "/home/share" # Replace the exported directory with your own.
storageClass:
defaultClass: false
在kubesphere设置挂载:addons
持久化存储配置 - 安装 NFS Client - 《KubeSphere v3.1 使用手册》 - 书栈网 · BookStack
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: master, address: 172.26.144.159, internalAddress: 172.26.144.159, user: root, password: Tb123456}
- {name: node01, address: 172.26.144.160, internalAddress: 172.26.144.160, user: root, password: Tb123456}
- {name: node02, address: 172.26.144.158, internalAddress: 172.26.144.158, user: root, password: Tb123456}
roleGroups:
etcd:
- master
master:
- master
worker:
- node01
- node02
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: 6443
kubernetes:
version: v1.20.4
imageRepo: kubesphere
clusterName: cluster.local
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
registry:
registryMirrors: []
insecureRegistries: []
addons:
- name: nfs-client
namespace: kube-system
sources:
chart:
name: nfs-client-provisioner
repo: https://charts.kubesphere.io/main
valuesFile: /home/share/nfs-client.yaml
---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
name: ks-installer
namespace: kubesphere-system
labels:
version: v3.1.0
spec:
persistence:
storageClass: ""
authentication:
jwtSecret: ""
zone: ""
local_registry: ""
etcd:
monitoring: false
endpointIps: localhost
port: 2379
tlsEnable: true
common:
redis:
enabled: false
redisVolumSize: 2Gi
openldap:
enabled: false
openldapVolumeSize: 2Gi
minioVolumeSize: 20Gi
monitoring:
endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
es:
elasticsearchMasterVolumeSize: 4Gi
elasticsearchDataVolumeSize: 20Gi
logMaxAge: 7
elkPrefix: logstash
basicAuth:
enabled: false
username: ""
password: ""
externalElasticsearchUrl: ""
externalElasticsearchPort: ""
console:
enableMultiLogin: true
port: 30880
alerting:
enabled: false
# thanosruler:
# replicas: 1
# resources: {}
auditing:
enabled: false
devops:
enabled: false
jenkinsMemoryLim: 2Gi
jenkinsMemoryReq: 1500Mi
jenkinsVolumeSize: 8Gi
jenkinsJavaOpts_Xms: 512m
jenkinsJavaOpts_Xmx: 512m
jenkinsJavaOpts_MaxRAM: 2g
events:
enabled: false
ruler:
enabled: true
replicas: 2
logging:
enabled: false
logsidecar:
enabled: true
replicas: 2
metrics_server:
enabled: false
monitoring:
storageClass: ""
prometheusMemoryRequest: 400Mi
prometheusVolumeSize: 20Gi
multicluster:
clusterRole: none
network:
networkpolicy:
enabled: false
ippool:
type: none
topology:
type: none
notification:
enabled: false
openpitrix:
store:
enabled: false
servicemesh:
enabled: false
kubeedge:
enabled: false
cloudCore:
nodeSelector: {"node-role.kubernetes.io/worker": ""}
tolerations: []
cloudhubPort: "10000"
cloudhubQuicPort: "10001"
cloudhubHttpsPort: "10002"
cloudstreamPort: "10003"
tunnelPort: "10004"
cloudHub:
advertiseAddress:
- ""
nodeLimit: "100"
service:
cloudhubNodePort: "30000"
cloudhubQuicNodePort: "30001"
cloudhubHttpsNodePort: "30002"
cloudstreamNodePort: "30003"
tunnelNodePort: "30004"
edgeWatcher:
nodeSelector: {"node-role.kubernetes.io/worker": ""}
tolerations: []
edgeWatcherAgent:
nodeSelector: {"node-role.kubernetes.io/worker": ""}
tolerations: []
NFS即网络文件系统,允许与他人共享目录和文件。
(1).实验环境
NFS服务器youxi1 192.168.1.6
测试主机youxi2 192.168.1.7
NFS是C/S模式,监听2049端口。
(2).实验
1)在NFS服务器youxi1上安装NFS
1
[root@youxi1 ~]# yum -y install rpcbind nfs-utils
2)启动NFS,并开机自启
1
2
3
4
5
6
7
8
9
[root@youxi1 ~]# systemctl start rpcbind
[root@youxi1 ~]# systemctl enable rpcbind
[root@youxi1 ~]# systemctl start nfs-server //NFS依赖rpcbind进行通讯,所以要先启动rpcbind
[root@youxi1 ~]# systemctl enable nfs-server
[root@youxi1 ~]# netstat -antup | grep 2049
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp6 0 0 :::2049 :::* LISTEN -
udp 0 0 0.0.0.0:2049 0.0.0.0:* -
udp6 0 0 :::2049 :::* -
3)测试主机youxi2安装nfs-utils
1
[root@youxi2 ~]# yum -y install nfs-utils
4)测试主机youxi2第一次测试
1
2
[root@youxi2 ~]# showmount -e 192.168.1.6
Export list for 192.168.1.6: //提示是空的
5)修改NFS服务器的配置文件/etc/exports,将已有的/www/html/文件夹共享出去
1
2
3
4
5
6
[root@youxi1 ~]# ll -d /www/html/
drwxr-xrwx 2 root root 20 5月 19 19:37 /www/html/
[root@youxi1 ~]# vim /etc/exports
/www/html/ 192.168.1.7(rw,no_root_squash) //可以共享给指定IP(192.168.1.7),也可以共享给指定网段(192.168.1.0),还可以共享给所有IP(*).rw代表读写权限。
[root@youxi1 ~]# exportfs -rv //重新读取配置文件,而不中断服务
exporting 192.168.1.7:/www/html
/etc/exports配置文件中权限参数常用的有如下五个:
ro只读权限
rw读写权限
sync同步写入内存与磁盘当中
no_all_squash保留共享文件的UID和GID(默认)
no_root_squash使得root用户具有根目录的完全访问权限
6)测试主机youxi2第二次测试
1
2
3
[root@youxi2 ~]# showmount -e 192.168.1.6
Export list for 192.168.1.6:
/www/html 192.168.1.7
7)在测试主机youxi2上挂载NFS
1
2
3
4
[root@youxi2 ~]# mkdir /html
[root@youxi2 ~]# mount -t nfs 192.168.1.6:/www/html/ /html //这时候共享才开始正常使用
[root@youxi2 ~]# ls /html
passwd
还可以做开机挂载
1
2
[root@youxi2 ~]# vim /etc/fstab
192.168.1.6:/www/html /html nfs defaults 0 0 //添加一行
新建一个文件
1
2
3
[root@youxi2 ~]# touch /html/1.txt
[root@youxi2 ~]# ls /html/
1.txt passwd
8)NFS高并发下挂载优化常用参数(mount -o选项)
async:异步同步,此参数会提高I/O性能,但会降低数据安全(除非对性能要求很高,对数据可靠性不要求的场合。一般生产环境,不推荐使用)。
noatime:取消更新文件系统上的inode访问时间,提升I/O性能,优化I/O目的,推荐使用。
nodiratime:取消更新文件系统上的directory inode访问时间,高并发环境,推荐显式应用该选项,提高系统性能,推荐使用。
当然也可以写入/etc/fstab配置文件
1
192.168.1.6:/www/html /html nfs noatime,nodiratime 0 0