How to create DBFS file system

   DBFS是oracle Exadata提供的一种的集群文件系统,他是通过创建一个表空间,并将该表空间通过一系列操作,挂载成为文件系统,为Exadata各个节点提供文件系统服务。
   DBFS一般都是在客户初次部署的时候,由oracle远程工程师通过固定的脚本,自动化部署全部的操作系统数据库的同时,将其建立。
   这里说到的就是,在之前客户没有规划DBFS文件系统,但是后期打算手动添加的方法。
  我的OS oracle linux

1.创建fuse用户组,并将oracle添加到这个组内。(注:dcli -g ~/dbs_group -l表示后面的命令式在~/dbs_group中列出的全部服务器上执行)

 
 
  1. (root)# dcli -g ~/dbs_group -l root usermod -a -G fuse oracle 

2.创建/etc/fuse.conf file并添加 user_allow_other. 赋予相应的权限到这个文件.

 
 
  1. (root)# dcli -g ~/dbs_group -l root "echo user_allow_other > /etc/fuse.conf" 
  2. (root)# dcli -g ~/dbs_group -l root chmod 644 /etc/fuse.conf 

3.在所有的服务器上创建一个空的目录,用来作为DBFS文件系统的挂载点。

 
 
  1. (root)# dcli -g ~/dbs_group -l root mkdir /dbfs_direct 

  更改目录的属组,确保oracle可以正常访问与修改.

 
 
  1. (root)# dcli -g ~/dbs_group -l root chown oracle:dba /dbfs_direct 

4.To pick up the additional group (fuse) membership for the oracle user on Linux or the workaround above on Solaris, Clusterware must be restarted. For example, to restart Clusterware on all nodes at the same time (non-rolling), you can use the following commands as root:

 
 
  1. (root)# dcli -g ~/dbs_group -l root /u01/app/11.2.0/grid/bin/crsctl stop crs 
  2. (root)# dcli -g ~/dbs_group -l root /u01/app/11.2.0/grid/bin/crsctl start crs 
  3.  
  4. Note that the "crsctl stop cluster -all" syntax may not be used as it leaves ohasd running and Solaris database hosts require it to be restarted for the workaround to take effect. 

5.创建一个数据库表空间,作为DBFS文件系统的存储空间. 如何创建表空间,请参考 Note 1191144.1
创建一个表空间(表空间名dbfsts)为将来存储文件使用,可以根据你的需求创建:大小,是否扩展和bigfile or small file等,完全随意

 
 
  1. SQL> sqlplus / as sysdba 
  2. SQL> create bigfile tablespace dbfsts datafile '+DBFS_DG' size 32g autoextend on next 8g maxsize 300g NOLOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE  SEGMENT SPACE MANAGEMENT AUTO ; 

6.创建用户,该用户是后续管理DBFS使用的

 
 
  1. SQL> create user dbfs_user identified by dbfs_passwd default tablespace dbfsts quota unlimited on dbfsts; 
  2. SQL> grant create session, create table, create view, create procedure, dbfs_role to dbfs_user; 

7.通过调用 dbfs_create_filesystem.sql 脚本,创建文件系统

 
 
  1. (oracle)$ cd $ORACLE_HOME/rdbms/admin 
  2. (oracle)$ sqlplus dbfs_user/dbfs_passwd 
  3. SQL> start dbfs_create_filesystem dbfsts FS1 
  4.  
  5. This script takes two arguments: 
  6. dbfsts: tablespace for the DBFS database objects    (注:该参数输入之前创建的表空间名) 
  7. FS1: filesystem name, this can be any string and will appear as a directory under the mount point (注:这个是在后续挂载完成之后,出现在挂件点下的文件夹名称) 
  8. ---脚本分析--- 
  9. 查看 dbfs_create_filesystem 脚本 
  10. $ cd $ORACLE_HOME 
  11. $ ls dbfs* 
  12. dbfs_create_filesystem_advanced.sql  dbfs_create_filesystem.sql  dbfs_drop_filesystem.sql 
  13. $more  dbfs_create_filesystem.sql 
  14. ================= 
  15. define ts_name      = &1 
  16. define fs_name      = &2 
  17. @@dbfs_create_filesystem_advanced.sql &ts_name &fs_name nocompress nodeduplicate noencrypt non-partition 
  18. undefine ts_name 
  19. undefine fs_name 
  20. =================== 
  21.  
  22. $ more  dbfs_create_filesystem_advanced.sql 
  23. 这个脚本主要是赋值,通过一个procedure来执行dbms_dbfs_sfs.createFilesystem包,创建一个文件系统 
  24. dbms_dbfs_sfs 的用法及定义,请参看如下链接 
  25. http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_dbfs_sfs.htm#ARPLS72180 
  26. The DBMS_DBFS_SFS package provides an interface to operate a SecureFile-based store (SFS) for the content interface described in the DBMS_DBFS_CONTENT package. 
  27.  
  28. 可以通过如下命令去确认是否已经安装这个package 
  29. SQL>select OBJECT_NAME from all_objects t where object_type like 'PACKAGE%' and object_name like 'DBMS_DBFS_SFS%'; 
  30. OBJECT_NAME 
  31. ------------------------------ 
  32. DBMS_DBFS_SFS 
  33. DBMS_DBFS_SFS 
  34. DBMS_DBFS_SFS_ADMIN 
  35. DBMS_DBFS_SFS_ADMIN 
  36. ---脚本分析--- 

---至此,已经完成DBFS文件系统的安装,下面是对DBFS的挂载和管理---

有两种方式来挂载之前创建的表空间为DBFS
第一种方法是通过安装rpm包,使用dbfs_client命令来实现DBFS的挂载,但是不能使用wallet的功能(注意这里的wallet不是数据库中的wallet,它只是保存 dbfs_user/dbfs_passwd 的一个加密文件)
第二种方法是使用 Oracle Wallet来存储密码和使用mount命令

8. The second option is to use the Oracle Wallet to store the password and make use of the mount command. The wallet directory ($HOME/dbfs/wallet in the example here) may be any oracle-writable directory (creating a new, empty directory is recommended). All commands in this section should be run by the oracle user unless otherwise noted.)

 
 
  1. On Linux DB nodes, set the library path on all nodes using the commands that follow (substitute proper RDBMS ORACLE_HOMEs): 
  2. (root)# dcli -g dbs_group -l root mkdir -p /usr/local/lib 
  3. (root)# dcli -g dbs_group -l root ln -s /u01/app/oracle/product/11.2.0/dbhome_1/lib/libnnz11.so /usr/local/lib/libnnz11.so 
  4. (root)# dcli -g dbs_group -l root ln -s /u01/app/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so.11.1 /usr/local/lib/libclntsh.so.11.1 
  5. (root)# dcli -g dbs_group -l root ln -s /lib64/libfuse.so.2 /usr/local/lib/libfuse.so.2 
  6. (root)# dcli -g dbs_group -l root 'echo /usr/local/lib >> /etc/ld.so.conf.d/usr_local_lib.conf' 
  7. (root)# dcli -g dbs_group -l root ldconfig 

9. Create a new TNS_ADMIN directory ($HOME/dbfs/tnsadmin) for exclusive use by the DBFS mount script.

 
 
  1. (oracle)$ dcli -g dbs_group -l oracle mkdir -p $HOME/dbfs/tnsadmin 
  2.  
  3. Create the $HOME/dbfs/tnsadmin/tnsnames.ora file with the following contents on the first node. This example presumes that the name of the DBFS repository database is fsdb and the instance on the first node is named fsdb1. If your RDBMS ORACLE_HOME is not /u01/app/oracle/product/11.2.0/dbhome_1, then change the PROGRAM and ENVS settings accordingly). 
  4.  
  5. fsdb.local = 
  6.   (DESCRIPTION = 
  7.       (ADDRESS = 
  8.         (PROTOCOL=BEQ
  9.         (PROGRAM=/u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle)                                       <<<<<<注意修改这个路径 
  10.         (ARGV0=oraclefsdb1
  11.         (ARGS='(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=BEQ)))'
  12.         (ENVS='ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1,ORACLE_SID=fsdb1'<<<<<<注意修改实例名 
  13.       ) 
  14.   (CONNECT_DATA=(SID=fsdb1))                                                                                                             <<<<<<注意修改实例名 
  15.  
  16. On other nodes, create similar entries (all using the name "fsdb.local") and change all occurrences of fsdb1 to the appropriate instance name to match the instance name running on the node where that tnsnames.ora file resides. The tnsnames.ora file on each node will be slightly different so that each tnsnames.ora file references the instance running locally on that node. 

10. On each node, create the $HOME/dbfs/tnsadmin/sqlnet.ora file with the same contents on each node after making the proper substitution for <HOMEDIR_PATH_HERE>:

 
 
  1. WALLET_LOCATION = 
  2.   (SOURCE=(METHOD=FILE
  3.           (METHOD_DATA=(DIRECTORY=<HOMEDIR_PATH_HERE>/dbfs/wallet))   <<<<<< 注意,这里要使用全路径,不能使用变量 
  4.   ) 
  5. SQLNET.WALLET_OVERRIDE = TRUE 
  6.  
  7. Ensure you substitute the correct path for the DIRECTORY attribute. You may not use variables in this path - it must be a literal full path. 
  8.  
  9. Copy the file to all nodes using dcli: 
  10. (oracle)$ dcli -g ~/dbs_group -l oracle -d $HOME/dbfs/tnsadmin -f $HOME/dbfs/tnsadmin/sqlnet.ora 

11. Create a wallet directory on one database server as the oracle user. For example:

 
 
  1. (oracle)$ mkdir -p $HOME/dbfs/wallet 
  2.  
  3. Create an empty auto-login wallet: 
  4.  
  5. (oracle)$ mkstore -wrl $HOME/dbfs/wallet -create 
  6.  
  7. Add the necessary credentials to the wallet. The credentials can be specific for the connect string used as shown here: 
  8.  
  9. (oracle)$ mkstore -wrl $HOME/dbfs/wallet -createCredential fsdb.local dbfs_user dbfs_passwd 
  10.  
  11. Copy the wallet files to all database nodes. 
  12.  
  13. (oracle)$ dcli -g ~/dbs_group -l oracle mkdir -p $HOME/dbfs/wallet 
  14. (oracle)$ dcli -g ~/dbs_group -l oracle -d $HOME/dbfs/wallet -f $HOME/dbfs/wallet/ewallet.p12 
  15. (oracle)$ dcli -g ~/dbs_group -l oracle -d $HOME/dbfs/wallet -f $HOME/dbfs/wallet/cwallet.sso 

12. Ensure that the TNS entry specified above (fsdb.local in the example) is defined and working properly (checking with "TNS_ADMIN=/home/oracle/dbfs/tnsadmin tnsping fsdb.local" is a good test).

 
 
  1. (oracle)$ dcli -g ~/dbs_group -l oracle "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; TNS_ADMIN=$HOME/dbfs/tnsadmin /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnsping fsdb.local | grep OK" 
  2. dm01db01: OK (20 msec) 
  3. dm01db02: OK (30 msec)  

下载脚本 mount-dbfs.sh 到一个DB节点上的临时位置   (如 /tmp/mount-dbfs.sh). 运行 dos2unix防止文件格式不兼容。

 
 
  1. For Linux, run this: 
  2. (root)# dos2unix /tmp/mount-dbfs.sh  

mount-dbfs.sh 脚本是后续挂载DBFS文件系统的时候都要调用的,其中涉及一下参数,需要根据实际环境进行设置

 
 
  1. 主要是以下参数需要设置 
  2. DBNAME 
  3. MOUNT_POINT 
  4. DBFS_USER 
  5. ORACLE_HOME (should be the RDBMS ORACLE_HOME directory) 
  6. LOGGER_FACILITY (used by syslog to log the messages/output from this script) 
  7. MOUNT_OPTIONS 
  8. DBFS_PASSWD (used only if WALLET=false)                                    <<<<<如果 WALLET=true,这个设置与否都无所谓,当调用的时候会去查看wallert文件 
  9. DBFS_PWDFILE_BASE (used only if WALET=false
  10. WALLET (must be true or false)                                                           <<<<<如果 WALLET=true,会使用 DBFS_PASSWD 去连接并挂载DBFS 
  11. TNS_ADMIN (used only if WALLET=true
  12. DBFS_LOCAL_TNSALIAS  

13. 修改后将文件拷贝到每个服务器的适当目录下,这里就使用GI_HOME/crs/script,并使用root设置相应的权限

 
 
  1. (root)# dcli -g ~/dbs_group -l root -d /u01/app/11.2.0/grid/crs/script -f /tmp/mount-dbfs.sh 
  2. (root)# dcli -g ~/dbs_group -l root chown oracle:dba /u01/app/11.2.0/grid/crs/script/mount-dbfs.sh 
  3. (root)# dcli -g ~/dbs_group -l root chmod 750 /u01/app/11.2.0/grid/crs/script/mount-dbfs.sh  

14. 通过以下脚本,来实现将DBFS作为一种资源注册到CRS,以使用CRS来管理DBFS。使用数据库的owner(既oracle)来执行以下脚本,根据实际情况适当修改ORACLE_HOME(其为grid home) 和DBNAME(数据库名),还可以注册多个DBFS文件系统到CRS,不过这里就不讲了,有机会再更新。

 
 
  1. ---注:这个脚本只要在一个节点执行就可以了 
  2.  
  3. ##### start script add-dbfs-resource.sh 
  4. #!/bin/bash 
  5. ACTION_SCRIPT=/u01/app/11.2.0/grid/crs/script/mount-dbfs.sh 
  6. RESNAME=dbfs_mount 
  7. DBNAME=fsdb 
  8. DBNAMEL=`echo $DBNAME | tr A-Z a-z` 
  9. ORACLE_HOME=/u01/app/11.2.0/grid 
  10. PATH=$ORACLE_HOME/bin:$PATH 
  11. export PATH ORACLE_HOME 
  12. crsctl add resource $RESNAME \ 
  13.   -type local_resource \ 
  14.   -attr "ACTION_SCRIPT=$ACTION_SCRIPT, \ 
  15.          CHECK_INTERVAL=30,RESTART_ATTEMPTS=10, \ 
  16.          START_DEPENDENCIES='hard(ora.$DBNAMEL.db)pullup(ora.$DBNAMEL.db)',\ 
  17.          STOP_DEPENDENCIES='hard(ora.$DBNAMEL.db)',\ 
  18.          SCRIPT_TIMEOUT=300
  19. ##### end script add-dbfs-resource.sh 
  20. Then run this as the Grid Infrastructure owner (typically oracle) on one database server only: 
  21. (oracle)$ sh ./add-dbfs-resource.sh  

15.通过Oracle Clusterware来管理 DBFS挂载与卸载

资源注册成功后,可以通过crsctl  stat res dbfs_mount  来查看到 dbfs_mount 资源,其所有的节点状态是 OFFLINE:

 
 
  1. (oracle)$ <GI_HOME>/bin/crsctl stat res dbfs_mount -t 
  2. -------------------------------------------------------------------------------- 
  3. NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
  4. -------------------------------------------------------------------------------- 
  5. Local Resources 
  6. -------------------------------------------------------------------------------- 
  7. dbfs_mount 
  8.                OFFLINE OFFLINE      dscbac05                                     
  9.                OFFLINE OFFLINE      dscbac06   

                    
17.执行crsctl start resource dbfs_mount,将会挂载DBFS到全部的节点:

 
 
  1. (oracle)$ <GI_HOME>/bin/crsctl start resource dbfs_mount 
  2. CRS-2672: Attempting to start 'dbfs_mount' on 'dscbac05' 
  3. CRS-2672: Attempting to start 'dbfs_mount' on 'dscbac06' 
  4. CRS-2676: Start of 'dbfs_mount' on 'dscbac06' succeeded 
  5. CRS-2676: Start of 'dbfs_mount' on 'dscbac05' succeeded 
  6. (oracle)$ <GI_HOME>/bin/crsctl stat res dbfs_mount -t 
  7. -------------------------------------------------------------------------------- 
  8. NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
  9. -------------------------------------------------------------------------------- 
  10. Local Resources 
  11. -------------------------------------------------------------------------------- 
  12. dbfs_mount 
  13.                ONLINE  ONLINE       dscbac05                                     
  14.                ONLINE  ONLINE       dscbac06   

        
18.挂载成功后,你可以通过df -h查看到DBFS文件系统的信息 Also, the default startup for this resource is "restore" which means that if it is online before Clusterware is stopped, it will attempt to come online after Clusterware is restarted. For example:

 
 
  1. (oracle)$ df -h /dbfs_direct 
  2. Filesystem            Size  Used   Avail Use% Mounted on 
  3. dbfs                      1.5M   40K  1.4M   3% /dbfs_direct 
  4. To unmount DBFS on all nodes, run this as the oracle user: 
  5. (oracle)$ <GI_HOME>/bin/crsctl stop res dbfs_mount  

19.DBFS配置过程中,遇到一段插曲
通过crsctl显示状态是online,但是文件系统不能被访问,当访问的时候,会遇到df: `/dbfs_direct': Input/output error错误,后来应用patch 13340960,问题解决。

 
 
  1. [oracle@dm03db01 tmp]$ /u01/app/11.2.0.3/grid/bin/crsctl stat res dbfs_mount -t 
  2. -------------------------------------------------------------------------------- 
  3. NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
  4. -------------------------------------------------------------------------------- 
  5. Local Resources 
  6. -------------------------------------------------------------------------------- 
  7. dbfs_mount 
  8.                ONLINE  ONLINE       dm03db01                                     
  9.                ONLINE  ONLINE       dm03db02                                     
  10.                ONLINE  ONLINE       dm03db03                                     
  11.                ONLINE  ONLINE       dm03db04                
  12.  
  13. [oracle@dm03db01 tmp]$ /u01/app/11.2.0.3/grid/crs/script/mount-dbfs.sh status 
  14. Checking status now 
  15. Check -- ONLINE 
  16.  
  17. [oracle@dm03db01 tmp]$ cd /dbfs_direct 
  18. -bash: cd: /dbfs_direct: Input/output error 
  19. [oracle@dm03db01 tmp]$ df -h /dbfs_direct 
  20. df: `/dbfs_direct': Input/output error  

详情请参考oracle官方文档:
Configuring DBFS on Oracle Database Machine (Doc ID 1054431.1)
Accessing Dbfs Using Oracle Wallet Fails With Input/output error (Doc ID 1358194.1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值