NFS
NFS(Network File System)即网络文件系统,是类Unix系统支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。
部署NFS服务
安装nfs-utils rpcbind
1 | ~]# yum install -y nfs-utils rpcbind |
2 | ~]# systemctl start rpcbind |
3 | ~]# systemctl start nfs |
4 | ~]#netstat -ntlp |
5 | ... |
6 | tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - |
7 | ... |
8 | 2049是监听端口,但不是服务端口,nfs的服务由rpc(远程过程调用)完成。 |
配置文件
1 | ~]# cat /etc/exports |
2 | /data2 10.211.55.35(rw,sync) |
3 | /mysqldata 10.211.55.35(rw,sync) |
这里的配置选项简单说明下:
配置格式:/path/to/somedir ip(export opt1,opt2…)
常用的选项:
- rw 读写
- root_squash 压缩root用户权限,默认
- no_root_squash 不压缩root用户权限
- all_squash 压缩所有用户权限
- anonuld and anongid 衍射指定用户
- ro 只读
exportfs -rv 输出共享目录文件
客户端配置
目的:部署Discuz论坛应用
挂载nfs到客户端:
1 | ~]# showmount -e 10.211.55.24 |
2 | Export list for 10.211.55.24: |
3 | /mysqldata 10.211.55.35 |
4 | /data2 10.211.55.35 |
5 | |
6 | 还有一点,我们默认压缩root用户权限,挂载过来的root权限的目录文件我们无权修改,所以我们还需要在服务器端修改掉/data2和/mysqldata的属主和属组。 |
7 | ~]# mount -t nfs 10.211.55.24:/data2 /www |
8 | ~]# mount -t nfs 10.211.55.24:/mysqldata /mysqldata |
9 | ~]# ll -d /www /mysqldata |
10 | drwxr-xr-x. 6 mysql mysql 4096 Mar 23 20:06 /mysqldata |
11 | drwxr-xr-x. 5 apache apache 92 Mar 23 20:04 /www |
12 | ~]# df -h |
13 | Filesystem Size Used Avail Use% Mounted on |
14 | /dev/mapper/vg_node1-lv_root |
15 | 50G 6.3G 41G 14% / |
16 | tmpfs 497M 0 497M 0% /dev/shm |
17 | /dev/sda1 477M 28M 425M 7% /boot |
18 | /dev/mapper/vg_node1-lv_home |
19 | 12G 30M 11G 1% /home |
20 | 10.211.55.24:/data2 42G 6.4G 35G 16% /www |
21 | 10.211.55.24:/mysqldata |
22 | 42G 6.4G 35G 16% /mysqldata |
我们还需要做的就是创建用户,应为nfs服务的用户是更具uid和gid进行衍射的,所以我们需要创键客户端和服务器端都一样的uid和gid的用户,主要创建apache和mysql用户,就不演示了。
部署mariadb
1 | 下载mariadb二进制安装包,初始化mariadb,数据目录为/mysqldata,而root权限被压缩成nfsnobody是无权写入/mysqldata目录的,所以我们到mysql用户下执行: |
2 | ~]# su - mysql |
3 | ~]# cd /usr/local/mariadb/scripts |
4 | ~]# ./mysql_install_db --basedir=/usr/local/mariadb --datadir=/mysqldata --user=mysql |
5 | ~]# cp ../support-files/mysql.server /etc/init.d/mysqld |
6 | |
7 | 启动服务我们还是得使用mysql用户起,但是会报一个错误,原因是/var/lock/subsys/锁文件目录mysql是无法写入的,所以我们得改下启动文件 |
8 | ~]# cat /etc/ini.d/mysqld |
9 | lockdir='/mysqldata' |
10 | 这样启动就没有报错了 |
11 | |
12 | ~]# ps aux | grep mysql |
13 | mysql 28686 0.0 0.1 11440 1560 pts/0 S Mar23 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --datadir=/mysqldata --pid-file=/mysqldata/www.magedu.com.pid |
14 | mysql 28808 0.0 6.6 1269244 67312 pts/0 Sl Mar23 0:03 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb --datadir=/mysqldata --plugin-dir=/usr/local/mariadb/lib/plugin --log-error=/mysqldata/www.magedu.com.err --pid-file=/mysqldata/www.magedu.com.pid --socket=/tmp/mysql.sock --port=3306 |
15 | root 29338 0.0 0.0 103312 880 pts/0 S+ 00:34 0:00 grep mysql |
16 | |
17 | ~]mysql |
18 | Welcome to the MySQL monitor. Commands end with ; or \g. |
19 | Your MySQL connection id is 25 |
20 | Server version: 5.5.5-10.1.22-MariaDB Source distribution |
21 | |
22 | Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
23 | |
24 | Oracle is a registered trademark of Oracle Corporation and/or its |
25 | affiliates. Other names may be trademarks of their respective |
26 | owners. |
27 | |
28 | Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. |
29 | |
30 | mysql> create database ultrax; |
31 | |
32 | mysql> grant all on ultra.* to jusene@'127.0.0.1' identified by 'jusene'; |
Discuz需要数据库和连接mysql的用户密码,这里提早准备好。
部署httpd
首先测试下httpd能访问/www上的文件,httpd配置能访问php文件就省了:
一样root用户在/www上是没权限操作的:
1 | ~]# su - apache |
2 | ~]# cd /www |
3 | ~]# unzip Discuz_X3.3_SC_UTF8.zip |
测试部署安装
基于nfs的部署方式就可以使用了,10.211.55.24提供数据存储空间,10.211.55.35只负责程序的执行。