[20170705]理解linux su命令.txt--//我一般在維護時經常使用root用戶登錄,然後su - oracle 轉到其他用戶操作--//一般都加入 - 參數.這個已經成了條件反射...^_^.# man su Change the effective user id and grou ...
[20170705]理解linux su命令.txt
--//我一般在維護時經常使用root用戶登錄,然後su - oracle 轉到其他用戶操作
--//一般都加入 - 參數.這個已經成了條件反射...^_^.
# man su
Change the effective user id and group id to that of USER.
-, -l, --login
make the shell a login shell
--//也就是使用login裡面的shell,設置好對應的環境.
--//如果執行沒有-,也就是僅僅run a shell with substitute user and group IDs,不替換裡面的環境變數或者相關參數.
1.測試1:
--//當前以root用戶登錄:
# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
# echo $ORACLE_HOME
# export aaa=test
# echo $aaa
test
# su - oracle
$ id
uid=1001(oracle) gid=1001(oinstall) groups=101(fuse),1001(oinstall),1002(dba),1003(racoper),1004(asmdba)
$ echo $aaa
--//無顯示.
$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0.4/dbhome_1
2.如果執行不加參數 - 呢?
$ echo $ORACLE_HOME
--//環境變數ORACLE_HOME沒有設置,而root設置的環境變數aaa呢?
$ echo $aaa
test
--//可以發現可以顯示環境變數aaa.
3.這樣看來應該很少使用-參數.
--//實際上rac的管理oracle引入許多東西,建立grid用戶.通過一些特殊例子來說明問題:
--//以grid用戶登錄:
[grid@dm01dbadm02 ~ ]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 3852
Available space (kbytes) : 258268
ID : 2101855892
Device/File Name : +DBFS_DG
Device/File integrity check succeeded
Device/File not configured
Device/File not configured
Device/File not configured
Device/File not configured
Cluster registry integrity check succeeded
Logical corruption check bypassed due to non-privileged user
--//OK.如果你加入參數:
$ ocrcheck -local
PROTL-602: Failed to retrieve data from the local registry
PROCL-26: Error while accessing the physical storage Operating System error [Permission denied] [13]
--//跟蹤看看:
$ strace -f -o /tmp/b1.txt ocrcheck -local
PROTL-602: Failed to retrieve data from the local registry
PROCL-26: Error while accessing the physical storage Operating System error [Permission denied] [13]
$ grep 'Permission denied' /tmp/b1.txt
14849 open("/u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr", O_RDONLY|O_SYNC) = -1 EACCES (Permission denied)
--//要打開文件/u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr.
$ ls -l /u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr
-rw------- 1 root oinstall 272756736 2017-07-05 09:45:15 /u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr
--//註意看用戶,組是root,oinstall,grid用戶根本沒有許可權打開這個文件.
--//要解決這個問題一些dba採用把root用戶裡面加入grid的許多環境變數.以root用戶執行,不過這樣我認為不是很好!!
--//實際上很簡單的方法就是切換到root用戶執行,註意這個時候不能加入- 參數,因為這樣grid的環境參數就丟失了,實際上這樣就以
--//root用戶執行,而使用的環境還是grid用戶的.
$ su root
Password:
# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
# echo $PATH
/usr/local/bin:/bin:/usr/bin:/u01/app/11.2.0.4/grid/bin:.:/u01/app/11.2.0.4/grid/bin
# echo $ORACLE_HOME
/u01/app/11.2.0.4/grid
--//你可以發現grid的環境參數還在.這個使用以root用戶執行如下:
# ocrcheck -local
Status of Oracle Local Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2800
Available space (kbytes) : 259320
ID : 1632195400
Device/File Name : /u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr
Device/File integrity check succeeded
Local registry integrity check succeeded
Logical corruption check succeeded
--//當然還可以以另外的方式,就是使用sudo命令. sudo ocrcheck -local
--//註意要修改/etc/sudoers,加入:
grid ALL=(ALL) ALL
$ sudo ocrcheck -local
[sudo] password for grid:
Status of Oracle Local Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2800
Available space (kbytes) : 259320
ID : 1632195400
Device/File Name : /u01/app/11.2.0.4/grid/cdata/dm01dbadm02.olr
Device/File integrity check succeeded
Local registry integrity check succeeded
Logical corruption check succeeded