CentOS7.9编译安装PostgreSQL

目录

安装编译安装所需环境

安装PostgreSQL所需依赖

编译安装

配置环境

配置环境变量

登录数据库


本文是以CentOS7.9.2009版本的操作系统为基础采用编译安装的方式安装16.3版本的PostgreSQL。

安装编译安装所需环境

yum -y install gcc gcc-* make

安装PostgreSQL所需依赖

yum -y install libicu libicu-devel readline-devel zlib zlib-devel 

编译安装

可以从该地址下载软件包https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz

# 解压源码包
tar zxvf postgresql-16.3.tar.gz

# 切换目录
cd postgresql-16.3

# --prefix指定安装目录
./configure --prefix=/usr/local/pgsql

# 编译以及安装
make && make install

配置环境

# 创建用户
adduser postgres

# 创建数据存储目录
mkdir /usr/local/pgsql/data

# 更改数据存储目录的归属用户
chown postgres /usr/local/pgsql/data

配置环境变量

cat >> /etc/profile << 'EOF'
# 配置共享库
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH

# 配置命令可搜索路径
PATH=/usr/local/pgsql/bin:$PATH
export PATH
EOF

# 刷新环境变量
source /etc/profile

登录数据库

注意:不要使用root用户登录,切换到postgres这个用户

# 切换用户
su - postgres

# 初始化数据库 -D 指定数据存储目录
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

# 启动数据库
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

# 登录数据库
/usr/local/pgsql/bin/psql


[root@bogon postgresql-16.3]# su - postgres
[postgres@bogon ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/New_York
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

[postgres@bogon ~]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started
[postgres@bogon ~]$ /usr/local/pgsql/bin/psql 
psql (16.3)
Type "help" for help.

postgres=# 

  • 11
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是centos7.9编译安装nginx的步骤: 1. 安装编译nginx所需的依赖库: ``` yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxslt libxslt-devel gd gd-devel perl perl-devel perl-ExtUtils-Embed ``` 2. 下载nginx源码包: 可以到官网(https://nginx.org/en/download.html)下载最新的稳定版nginx源码包。 3. 解压源码包: ``` tar zxvf nginx-xxx.tar.gz ``` 4. 进入nginx源码目录,执行以下命令进行编译安装: ``` ./configure --with-http_stub_status_module --with-http_ssl_module make && make install ``` 其中,--prefix参数指定nginx安装目录,--with-http_stub_status_module参数启用状态页模块,--with-http_ssl_module参数启用SSL加密支持。 5. 配置nginx: 进入/usr/local/nginx/conf目录,编辑nginx.conf文件,进行配置。这里给出一个简单的配置文件示例: ``` user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } server { listen 443 ssl; server_name localhost; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } } ``` 其中,listen参数指定监听端口,server_name参数指定域名,root参数指定网站根目录,ssl_certificate和ssl_certificate_key参数指定SSL证书和私钥文件路径。 6. 启动nginx: 进入/usr/local/nginx/sbin目录,执行以下命令启动nginx: ``` ./nginx ``` 7. 检查nginx是否启动成功: 执行以下命令查看nginx进程是否存在: ``` ps -ef | grep nginx ``` 执行以下命令检查nginx监听的端口是否打开: ``` netstat -tlnp | grep nginx ``` 如果输出类似以下内容,则说明nginx已经成功安装并启动: ``` tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN xxxx/nginx tcp 0 0 :::443 :::* LISTEN xxxx/nginx ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值