Postgresql 16开启SELINUX

平时我们习惯了,安装数据库,就关闭SELINUX,不关闭SELINUX,就不会安装数据库了,那么不关闭SELINUX,就不能安装数据库了吗?

答案是否定的。

不过,如果我们在开启SELINUX情况下安装PG,需要给PGHOME,PGDATA打安全标签。

在PG 中,SELINUX 标签不统一,$PGHOME 和$PGDATA的标签不一样,就是$PGHOME下面的各目录及文件,标签也不一样。

标签分类

具体如下:



$PGHOME/bin/postgres    标签: postgresql_exec_t
$PGHOME/bin/initdb       标签: postgresql_exec_t
$PGHOME/bin/pg_ctl       标签: initrc_exec_t
$PGHOME/bin/*               标签:    bin_t
$PGHOME/lib/*               标签: lib_t
$PGHOME/*                      标签: usr_t


$PGDATA/*        标签: postgresql_db_t


针对这种情况,我们需要对这些文件重新打标签


方法如下:
使用root用户去执行
比如:
$PGDATA=/u01/app/postgres/pgdata
$PGHOME=/u01/app/postgres/product/16.3/dbhome_1



1.设置目录标签


# semanage fcontext -a -t usr_t '/u01/app/postgres/product/16.3/dbhome_1(/.*)?'
# semanage fcontext -a -t bin_t '/u01/app/postgres/product/16.3/dbhome_1/bin
(/.*)?'
# semanage fcontext -a -t lib_t '/u01/app/postgres/product/16.3/dbhome_1/lib
(/.*)?'
# semanage fcontext -a -t postgresql_db_t '/u01/app/postgres/pgdata
(/.*)?'

2.设置单个文件的标签
# semanage fcontext -a -t postgresql_exec_t '/u01/app/postgres/product/16.3/dbhome_1/bin/postgres'
# semanage fcontext -a -t postgresql_exec_t '/u01/app/postgres/product/16.3/dbhome_1/bin/initdb'
# semanage fcontext -a -t initrc_exec_t '/u01/app/postgres/product/16.3/dbhome_1/bin/pg_ctl'

3.恢复文件安全上下文,含标签

# restorecon -FRv /u01/app/postgres/product/16.3/dbhome_1
# restorecon -FRv /u01/app/postgres/pgdata

4.验证SELINUX的安全上下文






至此,再去systemctl start PG16 不再报错





 

保持联系
----------------------------------------------------------------------------------

如果你对数据库技术感兴趣,我们还可以在微信群:水煮数据库 进行交流,主要交流日常运维中用到的数据库相关问题,包含但不限于:ORACLE,PG,MYSQL,SQLSERVER,OB,TIDB,达梦,TDSQL,OPENGAUSS,人大金仓,GBASE等等,加我微信吧:zq24803366,备注:水煮数据库, 我拉你入群。






 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值