天天看點

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中列出的全部伺服器上執行)

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

2.建立/etc/fuse.conf file并添加 user_allow_other. 賦予相應的權限到這個檔案.

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

(root)# dcli -g ~/dbs_group -l root chmod 644 /etc/fuse.conf 

3.在所有的伺服器上建立一個空的目錄,用來作為DBFS檔案系統的挂載點。

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

  更改目錄的屬組,確定oracle可以正常通路與修改.

(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:

(root)# dcli -g ~/dbs_group -l root /u01/app/11.2.0/grid/bin/crsctl stop crs 

(root)# dcli -g ~/dbs_group -l root /u01/app/11.2.0/grid/bin/crsctl start crs 

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等,完全随意

SQL> sqlplus / as sysdba 

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使用的

SQL> create user dbfs_user identified by dbfs_passwd default tablespace dbfsts quota unlimited on dbfsts; 

SQL> grant create session, create table, create view, create procedure, dbfs_role to dbfs_user; 

7.通過調用 dbfs_create_filesystem.sql 腳本,建立檔案系統

(oracle)$ cd $ORACLE_HOME/rdbms/admin 

(oracle)$ sqlplus dbfs_user/dbfs_passwd 

SQL> start dbfs_create_filesystem dbfsts FS1 

This script takes two arguments: 

dbfsts: tablespace for the DBFS database objects    (注:該參數輸入之前建立的表空間名) 

FS1: filesystem name, this can be any string and will appear as a directory under the mount point (注:這個是在後續挂載完成之後,出現在挂件點下的檔案夾名稱) 

---腳本分析--- 

檢視 dbfs_create_filesystem 腳本 

$ cd $ORACLE_HOME 

$ ls dbfs* 

dbfs_create_filesystem_advanced.sql  dbfs_create_filesystem.sql  dbfs_drop_filesystem.sql 

$more  dbfs_create_filesystem.sql 

================= 

define ts_name      = &1 

define fs_name      = &2 

@@dbfs_create_filesystem_advanced.sql &ts_name &fs_name nocompress nodeduplicate noencrypt non-partition 

undefine ts_name 

undefine fs_name 

=================== 

$ more  dbfs_create_filesystem_advanced.sql 

這個腳本主要是指派,通過一個procedure來執行dbms_dbfs_sfs.createFilesystem包,建立一個檔案系統 

dbms_dbfs_sfs 的用法及定義,請參看如下連結 

http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_dbfs_sfs.htm#ARPLS72180 

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. 

可以通過如下指令去确認是否已經安裝這個package 

SQL>select OBJECT_NAME from all_objects t where object_type like 'PACKAGE%' and object_name like 'DBMS_DBFS_SFS%'; 

OBJECT_NAME 

------------------------------ 

DBMS_DBFS_SFS 

DBMS_DBFS_SFS_ADMIN 

---至此,已經完成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.)

On Linux DB nodes, set the library path on all nodes using the commands that follow (substitute proper RDBMS ORACLE_HOMEs): 

(root)# dcli -g dbs_group -l root mkdir -p /usr/local/lib 

(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 

(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 

(root)# dcli -g dbs_group -l root ln -s /lib64/libfuse.so.2 /usr/local/lib/libfuse.so.2 

(root)# dcli -g dbs_group -l root 'echo /usr/local/lib >> /etc/ld.so.conf.d/usr_local_lib.conf' 

(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.

(oracle)$ dcli -g dbs_group -l oracle mkdir -p $HOME/dbfs/tnsadmin 

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). 

fsdb.local = 

  (DESCRIPTION = 

      (ADDRESS = 

        (PROTOCOL=BEQ) 

        (PROGRAM=/u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle)                                       <<<<<<注意修改這個路徑 

        (ARGV0=oraclefsdb1) 

        (ARGS='(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=BEQ)))') 

        (ENVS='ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1,ORACLE_SID=fsdb1') <<<<<<注意修改執行個體名 

      ) 

  (CONNECT_DATA=(SID=fsdb1))                                                                                                             <<<<<<注意修改執行個體名 

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>:

WALLET_LOCATION = 

  (SOURCE=(METHOD=FILE) 

          (METHOD_DATA=(DIRECTORY=<HOMEDIR_PATH_HERE>/dbfs/wallet))   <<<<<< 注意,這裡要使用全路徑,不能使用變量 

  ) 

SQLNET.WALLET_OVERRIDE = TRUE 

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. 

Copy the file to all nodes using dcli: 

(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:

(oracle)$ mkdir -p $HOME/dbfs/wallet 

Create an empty auto-login wallet: 

(oracle)$ mkstore -wrl $HOME/dbfs/wallet -create 

Add the necessary credentials to the wallet. The credentials can be specific for the connect string used as shown here: 

(oracle)$ mkstore -wrl $HOME/dbfs/wallet -createCredential fsdb.local dbfs_user dbfs_passwd 

Copy the wallet files to all database nodes. 

(oracle)$ dcli -g ~/dbs_group -l oracle mkdir -p $HOME/dbfs/wallet 

(oracle)$ dcli -g ~/dbs_group -l oracle -d $HOME/dbfs/wallet -f $HOME/dbfs/wallet/ewallet.p12 

(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).

(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" 

dm01db01: OK (20 msec) 

dm01db02: OK (30 msec)  

下載下傳腳本 mount-dbfs.sh 到一個DB節點上的臨時位置   (如 /tmp/mount-dbfs.sh). 運作 dos2unix防止檔案格式不相容。

For Linux, run this: 

(root)# dos2unix /tmp/mount-dbfs.sh  

mount-dbfs.sh 腳本是後續挂載DBFS檔案系統的時候都要調用的,其中涉及一下參數,需要根據實際環境進行設定

主要是以下參數需要設定 

DBNAME 

MOUNT_POINT 

DBFS_USER 

ORACLE_HOME (should be the RDBMS ORACLE_HOME directory) 

LOGGER_FACILITY (used by syslog to log the messages/output from this script) 

MOUNT_OPTIONS 

DBFS_PASSWD (used only if WALLET=false)                                    <<<<<如果 WALLET=true,這個設定與否都無所謂,當調用的時候會去檢視wallert檔案 

DBFS_PWDFILE_BASE (used only if WALET=false) 

WALLET (must be true or false)                                                           <<<<<如果 WALLET=true,會使用 DBFS_PASSWD 去連接配接并挂載DBFS 

TNS_ADMIN (used only if WALLET=true) 

DBFS_LOCAL_TNSALIAS  

13. 修改後将檔案拷貝到每個伺服器的适當目錄下,這裡就使用GI_HOME/crs/script,并使用root設定相應的權限

(root)# dcli -g ~/dbs_group -l root -d /u01/app/11.2.0/grid/crs/script -f /tmp/mount-dbfs.sh 

(root)# dcli -g ~/dbs_group -l root chown oracle:dba /u01/app/11.2.0/grid/crs/script/mount-dbfs.sh 

(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,不過這裡就不講了,有機會再更新。

---注:這個腳本隻要在一個節點執行就可以了 

##### start script add-dbfs-resource.sh 

#!/bin/bash 

ACTION_SCRIPT=/u01/app/11.2.0/grid/crs/script/mount-dbfs.sh 

RESNAME=dbfs_mount 

DBNAME=fsdb 

DBNAMEL=`echo $DBNAME | tr A-Z a-z` 

ORACLE_HOME=/u01/app/11.2.0/grid 

PATH=$ORACLE_HOME/bin:$PATH 

export PATH ORACLE_HOME 

crsctl add resource $RESNAME \ 

  -type local_resource \ 

  -attr "ACTION_SCRIPT=$ACTION_SCRIPT, \ 

         CHECK_INTERVAL=30,RESTART_ATTEMPTS=10, \ 

         START_DEPENDENCIES='hard(ora.$DBNAMEL.db)pullup(ora.$DBNAMEL.db)',\ 

         STOP_DEPENDENCIES='hard(ora.$DBNAMEL.db)',\ 

         SCRIPT_TIMEOUT=300" 

##### end script add-dbfs-resource.sh 

Then run this as the Grid Infrastructure owner (typically oracle) on one database server only: 

(oracle)$ sh ./add-dbfs-resource.sh  

15.通過Oracle Clusterware來管理 DBFS挂載與解除安裝

資源注冊成功後,可以通過crsctl  stat res dbfs_mount  來檢視到 dbfs_mount 資源,其所有的節點狀态是 OFFLINE:

(oracle)$ <GI_HOME>/bin/crsctl stat res dbfs_mount -t 

-------------------------------------------------------------------------------- 

NAME           TARGET  STATE        SERVER                   STATE_DETAILS       

Local Resources 

dbfs_mount 

               OFFLINE OFFLINE      dscbac05                                     

               OFFLINE OFFLINE      dscbac06   

17.執行crsctl start resource dbfs_mount,将會挂載DBFS到全部的節點:

(oracle)$ <GI_HOME>/bin/crsctl start resource dbfs_mount 

CRS-2672: Attempting to start 'dbfs_mount' on 'dscbac05' 

CRS-2672: Attempting to start 'dbfs_mount' on 'dscbac06' 

CRS-2676: Start of 'dbfs_mount' on 'dscbac06' succeeded 

CRS-2676: Start of 'dbfs_mount' on 'dscbac05' succeeded 

               ONLINE  ONLINE       dscbac05                                     

               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:

(oracle)$ df -h /dbfs_direct 

Filesystem            Size  Used   Avail Use% Mounted on 

dbfs                      1.5M   40K  1.4M   3% /dbfs_direct 

To unmount DBFS on all nodes, run this as the oracle user: 

(oracle)$ <GI_HOME>/bin/crsctl stop res dbfs_mount  

19.DBFS配置過程中,遇到一段插曲 

通過crsctl顯示狀态是online,但是檔案系統不能被通路,當通路的時候,會遇到df: `/dbfs_direct': Input/output error錯誤,後來應用patch 13340960,問題解決。

[oracle@dm03db01 tmp]$ /u01/app/11.2.0.3/grid/bin/crsctl stat res dbfs_mount -t 

               ONLINE  ONLINE       dm03db01                                     

               ONLINE  ONLINE       dm03db02                                     

               ONLINE  ONLINE       dm03db03                                     

               ONLINE  ONLINE       dm03db04                

[oracle@dm03db01 tmp]$ /u01/app/11.2.0.3/grid/crs/script/mount-dbfs.sh status 

Checking status now 

Check -- ONLINE 

[oracle@dm03db01 tmp]$ cd /dbfs_direct 

-bash: cd: /dbfs_direct: Input/output error 

[oracle@dm03db01 tmp]$ df -h /dbfs_direct 

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)

本文轉自 hsbxxl 51CTO部落格,原文連結:http://blog.51cto.com/hsbxxl/1026547,如需轉載請自行聯系原作者