[20170705]理解linux su命令.txt

[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

钉钉 AI 助理 钉钉 AI 助理

钉钉AI助理汇集了钉钉AI产品能力,帮助企业迈入智能新时代。

钉钉 AI 助理 21 查看详情 钉钉 AI 助理

以上就是[20170705]理解linux su命令.txt的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/288008.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月4日 19:19:15
下一篇 2025年11月4日 19:24:56

相关推荐

发表回复

登录后才能评论
关注微信