Rocky 9 非root用户源码安装postgresql
在Rocky 9操作系统上,作为非root用户通过源代码安装PostgreSQL,你需要遵循以下步骤:
- 安装依赖项
- 下载PostgreSQL源代码
- 编译并安装PostgreSQL
- 初始化数据库
- 配置PostgreSQL服务
以下是具体的命令:
# 1. 安装依赖项
sudo dnf install -y gcc gcc-c++ make zlib-devel openssl-devel readline-devel libxml2-devel libxslt-devel python-devel tcl-devel bzip2-devel
# 2. 创建PostgreSQL用户和组
sudo groupadd -r postgres
sudo useradd -r -g postgres -d /var/lib/postgres -s /bin/bash postgres
# 3. 下载PostgreSQL源代码
# 访问 https://www.postgresql.org/ 获取最新版本链接
wget https://ftp.postgresql.org/pub/source/v13.6/postgresql-13.6.tar.gz
tar zxvf postgresql-13.6.tar.gz
cd postgresql-13.6
# 4. 编译安装
./configure --prefix=/usr/local/pgsql --enable-locale --enable-utf8 --with-icu --with-openssl --with-python --with-tcl --without-ldap
make
sudo make install
# 5. 设置环境变量
echo 'export PATH=/usr/local/pgsql/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# 6. 初始化数据库
sudo mkdir /usr/local/pgsql/data
sudo chown postgres:postgres /usr/local/pgsql/data
sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
# 7. 启动PostgreSQL服务
sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
# 8. 登录PostgreSQL
/usr/local/pgsql/bin/psql -U postgres
# 注意:确保你的系统安全,不要在生产环境中使用来源不明的源代码安装数据库。始终从可信来源获取官方支持的软件包。
确保你有足够的权限执行这些命令,并且在执行前检查每个步骤,特别是下载源代码的版本是否与你的系统兼容。如果你是在生产环境中操作,请考虑使用系统包管理器或官方的二进制包,并按照官方文档进行操作。
评论已关闭