Linux PostgresQL資料庫安裝 開機自啟動 遠端連線(伺服器架設篇)
我在自己一臺老舊的DELL電腦上安裝了cent os7作為平常的開發伺服器。在平時我工作中主要使用的關係型資料庫是MySql,但是作為一個程式設計師要對技術產生好奇和愛好,PostgreQL也是十分優秀的關係資料庫,在MySql被Oracle收購後,PostgresQL的開源屬性使它有可能成為新關係型資料庫寵兒。
廢話不多講了我們直接進入安裝環節,首先我們進入官網的安裝教程頁面(PostgresQL 官方Cent os7 x86安裝教程),按人家的步驟安裝就可以了。
下面是實際安裝演示:
# 安裝PostgresQL yum源
[[email protected] thinktik]# yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
Loaded plugins: fastestmirror
pgdg-centos10-10-2.noarch.rpm | 4.6 kB 00:00:00
Examining /var/tmp/yum-root-xbOUDb/pgdg-centos10-10-2.noarch.rpm: pgdg-centos10-10-2.noarch
Marking /var/tmp/yum-root-xbOUDb/pgdg-centos10-10-2.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-centos10.noarch 0:10-2 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
=========================================================================================================
Installing:
pgdg-centos10 noarch 10-2 /pgdg-centos10-10-2.noarch 2.7 k
Transaction Summary
=========================================================================================================
Install 1 Package
Total size: 2.7 k
Installed size: 2.7 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-centos10-10-2.noarch 1/1
Verifying : pgdg-centos10-10-2.noarch 1/1
Installed:
pgdg-centos10.noarch 0:10-2
Complete!
# 安裝postgresql
[[email protected] thinktik]# yum install postgresql10
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
pgdg10 | 4.1 kB 00:00:00
(1/2): pgdg10/7/x86_64/group_gz | 245 B 00:00:03
(2/2): pgdg10/7/x86_64/primary_db | 162 kB 00:00:03
Resolving Dependencies
--> Running transaction check
---> Package postgresql10.x86_64 0:10.4-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql10-libs(x86-64) = 10.4-1PGDG.rhel7 for package: postgresql10-10.4-1PGDG.rhel7.x86_64
--> Processing Dependency: libicu for package: postgresql10-10.4-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql10-10.4-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:50.1.2-15.el7 will be installed
---> Package postgresql10-libs.x86_64 0:10.4-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
=========================================================================================================
Installing:
postgresql10 x86_64 10.4-1PGDG.rhel7 pgdg10 1.5 M
Installing for dependencies:
libicu x86_64 50.1.2-15.el7 base 6.9 M
postgresql10-libs x86_64 10.4-1PGDG.rhel7 pgdg10 354 k
Transaction Summary
=========================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 8.8 M
Installed size: 33 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): libicu-50.1.2-15.el7.x86_64.rpm | 6.9 MB 00:00:06
(2/3): postgresql10-libs-10.4-1PGDG.rhel7.x86_64.rpm | 354 kB 00:00:14
(3/3): postgresql10-10.4-1PGDG.rhel7.x86_64.rpm | 1.5 MB 00:01:18
---------------------------------------------------------------------------------------------------------
Total 115 kB/s | 8.8 MB 00:01:18
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql10-libs-10.4-1PGDG.rhel7.x86_64 1/3
Installing : libicu-50.1.2-15.el7.x86_64 2/3
Installing : postgresql10-10.4-1PGDG.rhel7.x86_64 3/3
Verifying : libicu-50.1.2-15.el7.x86_64 1/3
Verifying : postgresql10-10.4-1PGDG.rhel7.x86_64 2/3
Verifying : postgresql10-libs-10.4-1PGDG.rhel7.x86_64 3/3
Installed:
postgresql10.x86_64 0:10.4-1PGDG.rhel7
Dependency Installed:
libicu.x86_64 0:50.1.2-15.el7 postgresql10-libs.x86_64 0:10.4-1PGDG.rhel7
Complete!
# 安裝postgresql10-server(可選)
[[email protected] thinktik]# yum install postgresql10-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql10-server.x86_64 0:10.4-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
=========================================================================================================
Installing:
postgresql10-server x86_64 10.4-1PGDG.rhel7 pgdg10 4.5 M
Transaction Summary
=========================================================================================================
Install 1 Package
Total download size: 4.5 M
Installed size: 18 M
Is this ok [y/d/N]: y
Downloading packages:
postgresql10-server-10.4-1PGDG.rhel7.x86_64.rpm | 4.5 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql10-server-10.4-1PGDG.rhel7.x86_64 1/1
Verifying : postgresql10-server-10.4-1PGDG.rhel7.x86_64 1/1
Installed:
postgresql10-server.x86_64 0:10.4-1PGDG.rhel7
Complete!
# 初始化資料庫並設定自啟動
[[email protected] thinktik]# /usr/pgsql-10/bin/postgresql-10-setup initdb
Initializing database ... OK
[[email protected] thinktik]# systemctl enable postgresql-10
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-10.service to /usr/lib/systemd/system/postgresql-10.service.
[[email protected] thinktik]# systemctl start postgresql-10
[[email protected] thinktik]# ps -ef | grep postgres
postgres 19567 1 0 15:22 ? 00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
postgres 19569 19567 0 15:22 ? 00:00:00 postgres: logger process
postgres 19571 19567 0 15:22 ? 00:00:00 postgres: checkpointer process
postgres 19572 19567 0 15:22 ? 00:00:00 postgres: writer process
postgres 19573 19567 0 15:22 ? 00:00:00 postgres: wal writer process
postgres 19574 19567 0 15:22 ? 00:00:00 postgres: autovacuum launcher process
postgres 19575 19567 0 15:22 ? 00:00:00 postgres: stats collector process
postgres 19576 19567 0 15:22 ? 00:00:00 postgres: bgworker: logical replication launcher
root 19578 19343 0 15:22 pts/0 00:00:00 grep --color=auto postgres
建立使用者,建立庫並允許遠端訪問
建立使用者,建立庫
# 切換使用者
[[email protected] thinktik]# su - postgres
Last login: Wed Jul 18 14:19:01 CST 2018 on pts/2
# 登陸
-bash-4.2$ psql
psql (10.4)
Type "help" for help.
# 查詢所有的庫
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
# 查詢所有庫
postgres=# \d
Did not find any relations.
# 建立使用者
postgres=# CREATE USER dbuser WITH PASSWORD 'my_password';
CREATE ROLE
# 建立庫
postgres=# CREATE DATABASE example_db OWNER dbuser;
CREATE DATABASE
# 賦權
postgres=# GRANT ALL PRIVILEGES ON DATABASE example_db TO dbuser;
GRANT
# 退出
postgres=# \q
-bash-4.2$
設定遠端訪問
# 修改postgresql.conf,修改埠和監聽地址
[[email protected] thinktik]# vim /var/lib/pgsql/10/data/postgresql.conf
# - Connection Settings -
# 監聽所有ip地址的訪問
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
# 監聽埠1234
port = 1234 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
# 修改postgresql.conf,修改監聽地址和驗證方式為md5
[[email protected] thinktik]# vim /var/lib/pgsql/10/data/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# 加上這一行 允許所有的IP地址訪問 密碼為md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
防火牆和Selinux放行PostgresQL
# 開放postgresql服務
firewall-cmd --add-service=postgresql --permanent
# 過載防火牆
firewall-cmd –reload
# selinux允許PostgresQL改埠(如果你的linux沒有開Selinux就不必執行這句了)
semanage port -a -t postgresql_port_t -p tcp 1234
重啟生效
systemctl restart postgresql-10
# 驗證埠修改成功
[thinktik@thinkremote ~]$ psql -U dbuser-d example_db -p 1234
psql (10.4)
Type "help" for help.
# 遠端連線可以使用datagrip或者navicat等自行驗證,我就不講了
相關推薦
Linux PostgresQL資料庫安裝 開機自啟動 遠端連線(伺服器架設篇)
我在自己一臺老舊的DELL電腦上安裝了cent os7作為平常的開發伺服器。在平時我工作中主要使用的關係型資料庫是MySql,但是作為一個程式設計師要對技術產生好奇和愛好,PostgreQL也是十分優秀的關係資料庫,在MySql被Oracle收購後,Post
Linux 防火牆設定(伺服器架設篇)
CentOS 7 防火牆相關命令 更多請看(www.omob.cc) 自己的伺服器上安裝的是Cent OS7,以前Cent OS6系列中的iptables相關命令不能用了,發現Centos 7使用firewalld代替了原來的iptables。 關閉防火
postgresql在linux下的的開機自啟動服務與環境變量的配置
gpo 屬性 腳本 命令 strong 修改 post 方式 ebo 設置PostgreSQL開機自啟動 PostgreSQL的開機自啟動腳本位於PostgreSQL源碼目錄的contrib/start-scripts路徑下 linux文件即為linux系統上的啟動腳本
Linux下RabbitMQ的安裝 開機自啟動
term 缺省 south entos 分享圖片 block bit plugin tps 1.官網下載地址 下載 RabbitMQ 和 erlang。我下載的是rabbitmq-server-3.6.10-1.el7.noarch.rpm和erlang-19.0.4-
Linux下的Nginx安裝(開機自啟動)
1.在安裝Nginx前,需要確保系統安裝了g++,gcc, openssl-devel、pcre-devel和zlib-devel軟體。安裝必須軟體: [java] view plain copy print? yum -y install zlib zlib-devel openss
Linux設置nodejs開機自啟動
lan download sta 壓縮 無奈 端口 img post 程序 系統:Centos7 工具:Xshell、Xftp 由於客戶服務器從windows系統切換到了linux系統,所以原先部署在windows上的node服務端需要遷移到linux服務器上。 1、nod
Linux系統重要的開機自啟動的服務
round 技術分享 服務 啟動 lse 重要 size kconfig 我們 重要的開機自啟動的服務 1.sshd 連接Linux服務器是需要用到的服務程序 2.rsyslog 操作日誌的一種機制 系統日誌:/var/log/
嵌入式ARM平臺基於Linux配置應用程式開機自啟動(fluxbox參考)
本文轉載於 http://www.eefocus.com/toradex/blog/18-01/426601_a6317.html,特此感謝 By Toradex秦海 1). 簡介 嵌入式ARM平臺裝置採用Embedded Linux作業系統
ubus安裝+開機自啟動ubusd
安裝教程來自以下: 安裝ubus:https://segmentfault.com/a/1190000012061795 安裝json-c,libubox:https://segmentfault.com/a/1190000012017022 安裝ubus之前需要先安裝json-c,再安
linux下設定tomcat開機自啟動
linux 下tomcat開機自啟動 修改Tomcat/bin/startup.sh 為: export JAVA_HOME=/usr/java/j2sdk1.4.2_08 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_
linux下的tomcat開機自啟動(親測)
開機自啟動Tomcat: 1.修改指令碼檔案rc.local:vim /etc/rc.d/rc.local 這個指令碼是使用者自定的開機啟動程式,可以在裡面新增想在系統啟動之後執行的指令碼或者指令碼執行命令 2.新增如下內容:(jdk的安裝路徑與tomcat的路徑)
Linux下設定MongoDB開機自啟動
將MongoDB服務加入隨機啟動 vi /etc/rc.local 使用vi編輯器開啟配置檔案,並在其中加入下面一行程式碼 /usr/local/mongodb/bin/mongod -dbpath=/usr/local/mongodb/data/db --fork --port 27017 --logpa
Spring boot專案打包成jar在linux環境下設定開機自啟動【原創】
#!/bin/bash # The three branches of the scouting program,Add to auto. # chkconfig: 2345 20 80 # description: py-0.0.1-SNAPSHOT-exec.jar #
centOS上的mysql資料庫安裝&tomcat自啟動
一個java後臺離不開資料庫的支撐、那麼本文為你帶來mysql資料庫安裝的案例。 ####1,安裝jdk1.7,簡單也好用的yum命令來安裝: (1)如果沒有yum那麼先安裝上去:yum -y install wget (2)檢視可以安裝的jdk列表:yum
嵌入式ARM平臺基於Linux配置應用程式開機自啟動
By Toradex秦海 1). 簡介 嵌入式ARM平臺裝置採用Embedded Linux作業系統進行開發已經越來越成為主流,本文就著重說明在EmbeddedLinux下配置應用程式開機自啟動的方法,並就基於Qt的應用程式卡機自啟動指令碼的配置進一步說明。 本文所演示的
Linux 下如何新增開機自啟動檔案
【導讀】 Linux系統在啟動的過程中,會先啟動核心,通過核心初始化所有的裝置。在初始化完這些裝置後,會執行一個叫“rc.local”的檔案,它是進入系統前最後執行的一個檔案,主要用於定義一些需要在進入系統前,所需要啟動的指令碼程式。所以通過編輯該檔案可以實現自啟動的功能。
Linux筆記---設定程式開機自啟動
Linux系統下,如何使程式開機自啟動。可以通過修改開機啟動指令碼 /etc/init.d/rcS ,新增要啟動程式的路徑完成。 比如,核心4.1.15中/etc/init.d/rcS修改如下: #!/bin/sh # # rcS Call all S??* script
linux下配置mysql開機自啟動
命令echo "service mysqld start" >> /etc/rc.local 或者進入/etc/目錄,直接vim rc.local編輯rc.local檔案,在最後一行新增“
linux下redis設定開機自啟動
直接來步驟: 1、設定redis.conf中daemonize為yes,確保守護程序開啟。 2、編寫開機自啟動指令碼 vi /etc/init.d/redis 指令碼內容如下: # chkconfig: 2345 10 90 # description:
Linux設置tomcat開機自啟動:centos7
內容 systemctl net 成功 scrip rem ase pri tmp 1.前提是你已經安裝好了tomcat服務。2.配置Tomcat開機啟動很簡單,將Tomcat配置為系統服務並配置為開機啟動即可。首先將tomcat配置為系統服務:創建tomcat8服務文件: