From 1b51f163156a8d4c53555f9415ff161bcba7b06d Mon Sep 17 00:00:00 2001 From: ictlyh Date: Mon, 23 Nov 2015 23:30:24 +0800 Subject: [PATCH] Translated sources/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md --- ...eSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md | 319 ------------------ ...eSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md | 317 +++++++++++++++++ 2 files changed, 317 insertions(+), 319 deletions(-) delete mode 100644 sources/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md create mode 100644 translated/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md diff --git a/sources/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md b/sources/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md deleted file mode 100644 index de05f067b5..0000000000 --- a/sources/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md +++ /dev/null @@ -1,319 +0,0 @@ -ictlyh Translating -Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10 -================================================================================ -![](http://1426826955.rsc.cdn77.org/wp-content/uploads/2014/05/postgresql.png) - -### Introduction ### - -[PostgreSQL][1] is a powerful, open-source object-relational database system. It runs under all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS, Solaris, Tru64), and Windows OS. - -Here is what **Mark Shuttleworth**, the founder of **Ubuntu**, says about PostgreSQL. - -> Postgres is a truly awesome database. When we started working on Launchpad I wasn’t sure if it would be up to the job. I was so wrong. It’s been robust, fast, and professional in every regard. -> -> — Mark Shuttleworth. - -In this handy tutorial, let us see how to install PostgreSQL 9.4 on Ubuntu 15.10 server. - -### Install PostgreSQL ### - -PostgreSQL is available in the default repositories. So enter the following command from the Terminal to install it. - - sudo apt-get install postgresql postgresql-contrib - -If you’re looking for other versions, add the PostgreSQL repository, and install it as shown below. - -The **PostgreSQL apt repository** supports LTS versions of Ubuntu (10.04, 12.04 and 14.04) on amd64 and i386 architectures as well as select non-LTS versions(14.10). While not fully supported, the packages often work on other non-LTS versions as well, by using the closest LTS version available. - -#### On Ubuntu 14.10 systems: #### - -Create the file **/etc/apt/sources.list.d/pgdg.list**; - - sudo vi /etc/apt/sources.list.d/pgdg.list - -Add a line for the repository: - - deb http://apt.postgresql.org/pub/repos/apt/ utopic-pgdg main - -**Note**: The above repository will only work on Ubuntu 14.10. It is not updated yet to Ubuntu 15.04 and 15.10. - -**On Ubuntu 14.04**, add the following line: - - deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main - -**On Ubuntu 12.04**, add the following line: - - deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main - -Import the repository signing key: - - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc - ----------- - - sudo apt-key add - - -Update the package lists: - - sudo apt-get update - -Then install the required version. - - sudo apt-get install postgresql-9.4 - -### Accessing PostgreSQL command prompt ### - -The default database name and database user are “**postgres**”. Switch to postgres user to perform postgresql related operations: - - sudo -u postgres psql postgres - -#### Sample Output: #### - - psql (9.4.5) - Type "help" for help. - postgres=# - -To exit from posgresql prompt, type **\q** in the **psql** prompt return back to the Terminal. - -### Set “postgres” user password ### - -Login to postgresql prompt, - - sudo -u postgres psql postgres - -.. and set postgres password with following command: - - postgres=# \password postgres - Enter new password: - Enter it again: - postgres=# \q - -To install PostgreSQL Adminpack, enter the command in postgresql prompt: - - sudo -u postgres psql postgres - ----------- - - postgres=# CREATE EXTENSION adminpack; - CREATE EXTENSION - -Type **\q** in the **psql** prompt to exit from posgresql prompt, and return back to the Terminal. - -### Create New User and Database ### - -For example, let us create a new user called “**senthil**” with password “**ubuntu**”, and database called “**mydb**”. - - sudo -u postgres createuser -D -A -P senthil - ----------- - - sudo -u postgres createdb -O senthil mydb - -### Delete Users and Databases ### - -To delete the database, switch to postgres user: - - sudo -u postgres psql postgres - -Enter command: - - $ drop database - -To delete a user, enter the following command: - - $ drop user - -### Configure PostgreSQL-MD5 Authentication ### - -**MD5 authentication** requires the client to supply an MD5-encrypted password for authentication. To do that, edit **/etc/postgresql/9.4/main/pg_hba.conf** file: - - sudo vi /etc/postgresql/9.4/main/pg_hba.conf - -Add or Modify the lines as shown below - - [...] - # TYPE DATABASE USER ADDRESS METHOD - # "local" is for Unix domain socket connections only - local all all md5 - # IPv4 local connections: - host all all 127.0.0.1/32 md5 - host all all 192.168.1.0/24 md5 - # IPv6 local connections: - host all all ::1/128 md5 - [...] - -Here, 192.168.1.0/24 is my local network IP address. Replace this value with your own address. - -Restart postgresql service to apply the changes: - - sudo systemctl restart postgresql - -Or, - - sudo service postgresql restart - -### Configure PostgreSQL-Configure TCP/IP ### - -By default, TCP/IP connection is disabled, so that the users from another computers can’t access postgresql. To allow to connect users from another computers, Edit file **/etc/postgresql/9.4/main/postgresql.conf:** - - sudo vi /etc/postgresql/9.4/main/postgresql.conf - -Find the lines: - - [...] - #listen_addresses = 'localhost' - [...] - #port = 5432 - [...] - -Uncomment both lines, and set the IP address of your postgresql server or set ‘*’ to listen from all clients as shown below. You should be careful to make postgreSQL to be accessible from all remote clients. - - [...] - listen_addresses = '*' - [...] - port = 5432 - [...] - -Restart postgresql service to save changes: - - sudo systemctl restart postgresql - -Or, - - sudo service postgresql restart - -### Manage PostgreSQL with phpPgAdmin ### - -[**phpPgAdmin**][2] is a web-based administration utility written in PHP for managing PosgreSQL. - -phpPgAdmin is available in default repositories. So, Install phpPgAdmin using command: - - sudo apt-get install phppgadmin - -By default, you can access phppgadmin using **http://localhost/phppgadmin** from your local system’s web browser. - -To access remote systems, do the following. -On Ubuntu 15.10 systems: - -Edit file **/etc/apache2/conf-available/phppgadmin.conf**, - - sudo vi /etc/apache2/conf-available/phppgadmin.conf - -Find the line **Require local** and comment it by adding a **#** in front of the line. - - #Require local - -And add the following line: - - allow from all - -Save and exit the file. - -Then, restart apache service. - - sudo systemctl restart apache2 - -On Ubuntu 14.10 and previous versions: - -Edit file **/etc/apache2/conf.d/phppgadmin**: - - sudo nano /etc/apache2/conf.d/phppgadmin - -Comment the following line: - - [...] - #allow from 127.0.0.0/255.0.0.0 ::1/128 - -Uncomment the following line to make phppgadmin from all systems. - - allow from all - -Edit **/etc/apache2/apache2.conf**: - - sudo vi /etc/apache2/apache2.conf - -Add the following line: - - Include /etc/apache2/conf.d/phppgadmin - -Then, restart apache service. - - sudo service apache2 restart - -### Configure phpPgAdmin ### - -Edit file **/etc/phppgadmin/config.inc.php**, and do the following changes. Most of these options are self-explanatory. Read them carefully to know why do you change these values. - - sudo nano /etc/phppgadmin/config.inc.php - -Find the following line: - - $conf['servers'][0]['host'] = ''; - -Change it as shown below: - - $conf['servers'][0]['host'] = 'localhost'; - -And find the line: - - $conf['extra_login_security'] = true; - -Change the value to **false**. - - $conf['extra_login_security'] = false; - -Find the line: - - $conf['owned_only'] = false; - -Set the value as **true**. - - $conf['owned_only'] = true; - -Save and close the file. Restart postgresql service and Apache services. - - sudo systemctl restart postgresql - ----------- - - sudo systemctl restart apache2 - -Or, - - sudo service postgresql restart - - sudo service apache2 restart - -Now open your browser and navigate to **http://ip-address/phppgadmin**. You will see the following screen. - -![phpPgAdmin – Google Chrome_001](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_001.jpg) - -Login with users that you’ve created earlier. I already have created a user called “**senthil**” with password “**ubuntu**” before, so I log in with user “senthil”. - -![phpPgAdmin – Google Chrome_002](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_002.jpg) - -Now, you will be able to access the phppgadmin dashboard. - -![phpPgAdmin – Google Chrome_003](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_003.jpg) - -Log in with postgres user: - -![phpPgAdmin – Google Chrome_004](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_004.jpg) - -That’s it. Now you’ll able to create, delete and alter databases graphically using phppgadmin. - -Cheers! - --------------------------------------------------------------------------------- - -via: http://www.unixmen.com/install-postgresql-9-4-and-phppgadmin-on-ubuntu-15-10/ - -作者:[SK][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.twitter.com/ostechnix -[1]:http://www.postgresql.org/ -[2]:http://phppgadmin.sourceforge.net/doku.php \ No newline at end of file diff --git a/translated/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md b/translated/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md new file mode 100644 index 0000000000..7fd4414127 --- /dev/null +++ b/translated/tech/20151117 Install PostgreSQL 9.4 And phpPgAdmin On Ubuntu 15.10.md @@ -0,0 +1,317 @@ +在 Ubuntu 15.10 上安装 PostgreSQL 9.4 和 phpPgAdmin +================================================================================ +![](http://1426826955.rsc.cdn77.org/wp-content/uploads/2014/05/postgresql.png) + +### 简介 ### + +[PostgreSQL][1] 是一款强大的,开源对象关系型数据库系统。它支持所有的主流操作系统,包括 Linux、Unix(AIX、BSD、HP-UX,SGI IRIX、Mac OS、Solaris、Tru64) 以及 Windows 操作系统。 + +下面是 **Ubuntu** 发起者 **Mark Shuttleworth** 对 PostgreSQL 的一段评价。 + +> PostgreSQL 真的是一款很好的数据库系统。刚开始我们使用它的时候,并不确定它能否胜任工作。但我错的太离谱了。它很强壮、快速,在各个方面都很专业。 +> +> — Mark Shuttleworth. + +在这篇简短的指南中,让我们来看看如何在 Ubuntu 15.10 服务器中安装 PostgreSQL 9.4。 + +### 安装 PostgreSQL ### + +默认仓库中就有可用的 PostgreSQL。在终端中输入下面的命令安装它。 + + sudo apt-get install postgresql postgresql-contrib + +如果你需要其它的版本,按照下面那样先添加 PostgreSQL 仓库然后再安装。 + +**PostgreSQL apt 仓库** 支持 amd64 和 i386 架构的 Ubuntu 长期支持版(10.04、12.04 和 14.04),以及非长期支持版(14.04)。对于其它非长期支持版,该软件包虽然不能完全支持,但使用和 LTS 版本近似的也能正常工作。 + +#### Ubuntu 14.10 系统: #### + +新建文件**/etc/apt/sources.list.d/pgdg.list**; + + sudo vi /etc/apt/sources.list.d/pgdg.list + +用下面一行添加仓库: + + deb http://apt.postgresql.org/pub/repos/apt/ utopic-pgdg main + +**注意**: 上面的库只能用于 Ubuntu 14.10。还没有升级到 Ubuntu 15.04 和 15.10。 + +**Ubuntu 14.04**,添加下面一行: + + deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main + +**Ubuntu 12.04**,添加下面一行: + + deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main + +导入库签名密钥: + + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc + +---------- + + sudo apt-key add - + +更新软件包列表: + + sudo apt-get update + +然后安装需要的版本。 + + sudo apt-get install postgresql-9.4 + +### 访问 PostgreSQL 命令窗口 ### + +默认的数据库名称和数据库用户名称都是 “**postgres**”。切换到 postgres 用户进行 postgresql 相关的操作: + + sudo -u postgres psql postgres + +#### 事例输出: #### + + psql (9.4.5) + Type "help" for help. + postgres=# + +要退出 postgresql 窗口,在 **psql** 窗口输入 **\q** 退出到终端。 + +### 设置 “postgres” 用户密码 ### + +登录到 postgresql 窗口, + + sudo -u postgres psql postgres + +用下面的命令为用户 postgres 设置密码: + + postgres=# \password postgres + Enter new password: + Enter it again: + postgres=# \q + +要安装 PostgreSQL Adminpack,在 postgresql 窗口输入下面的命令: + + sudo -u postgres psql postgres + +---------- + + postgres=# CREATE EXTENSION adminpack; + CREATE EXTENSION + +在 **psql** 窗口输入 **\q** 从 postgresql 窗口退回到终端。 + +### 创建新用户和数据库 ### + +例如,让我们创建一个新的用户,名为 “**senthil**”,密码是 “**ubuntu**”,以及名为 “**mydb**” 的数据库。 + + sudo -u postgres createuser -D -A -P senthil + +---------- + + sudo -u postgres createdb -O senthil mydb + +### 删除用户和数据库 ### + +要删除数据库,首先切换到 postgres 用户: + + sudo -u postgres psql postgres + +输入命令: + + $ drop database + +要删除一个用户,输入下面的命令: + + $ drop user + +### 配置 PostgreSQL-MD5 验证 ### + +**MD5 验证** 要求用户提供一个 MD5 加密的密码用于认证。首先编辑 **/etc/postgresql/9.4/main/pg_hba.conf** 文件: + + sudo vi /etc/postgresql/9.4/main/pg_hba.conf + +按照下面所示添加或修改行 + + [...] + # TYPE DATABASE USER ADDRESS METHOD + # "local" is for Unix domain socket connections only + local all all md5 + # IPv4 local connections: + host all all 127.0.0.1/32 md5 + host all all 192.168.1.0/24 md5 + # IPv6 local connections: + host all all ::1/128 md5 + [...] + +其中, 192.168.1.0/24 是我的本地网络 IP 地址。用你自己的地址替换。 + +重启 postgresql 服务以使更改生效: + + sudo systemctl restart postgresql + +或者, + + sudo service postgresql restart + +### 配置 PostgreSQL TCP/IP 配置 ### + +默认情况下,没有启用 TCP/IP 连接,因此其它计算机的用户不能访问 postgresql。为了允许其它计算机的用户访问,编辑文件 **/etc/postgresql/9.4/main/postgresql.conf:** + + sudo vi /etc/postgresql/9.4/main/postgresql.conf + +找到下面一行: + + [...] + #listen_addresses = 'localhost' + [...] + #port = 5432 + [...] + +取消改行的注释,然后设置你 postgresql 服务器的 IP 地址,或者设置为 ‘*’ 监听所有用户。你应该谨慎设置所有远程用户都可以访问 PostgreSQL。 + + [...] + listen_addresses = '*' + [...] + port = 5432 + [...] + +重启 postgresql 服务保存更改: + + sudo systemctl restart postgresql + +或者, + + sudo service postgresql restart + +### 用 phpPgAdmin 管理 PostgreSQL ### + +[**phpPgAdmin**][2] 是基于 web 用 PHP 写的 PostgreSQL 管理工具。 + +默认仓库中有可用的 phpPgAdmin。用下面的命令安装 phpPgAdmin: + + sudo apt-get install phppgadmin + +默认情况下,你可以在本地系统的 web 浏览器用 **http://localhost/phppgadmin** 访问 phppgadmin。 + +要访问远程系统,在 Ubuntu 15.10 上做如下操作: + +编辑文件 **/etc/apache2/conf-available/phppgadmin.conf**, + + sudo vi /etc/apache2/conf-available/phppgadmin.conf + +找到 **Require local** 的一行在这行前面添加 **#** 注释掉它。 + + #Require local + +添加下面的一行: + + allow from all + +保存并退出文件。 + +然后重启 apache 服务。 + + sudo systemctl restart apache2 + +对于 Ubuntu 14.10 及之前版本: + +编辑 **/etc/apache2/conf.d/phppgadmin**: + + sudo nano /etc/apache2/conf.d/phppgadmin + +注释掉下面一行: + + [...] + #allow from 127.0.0.0/255.0.0.0 ::1/128 + +取消下面一行的注释使所有系统都可以访问 phppgadmin。 + + allow from all + +编辑 **/etc/apache2/apache2.conf**: + + sudo vi /etc/apache2/apache2.conf + +添加下面一行: + + Include /etc/apache2/conf.d/phppgadmin + +然后重启 apache 服务。 + + sudo service apache2 restart + +### 配置 phpPgAdmin ### + +编辑文件 **/etc/phppgadmin/config.inc.php**, 做以下更改。下面大部分选项都带有解释。认真阅读以便了解为什么要更改这些值。 + + sudo nano /etc/phppgadmin/config.inc.php + +找到下面一行: + + $conf['servers'][0]['host'] = ''; + +按照下面这样更改: + + $conf['servers'][0]['host'] = 'localhost'; + +找到这一行: + + $conf['extra_login_security'] = true; + +更改值为 **false**。 + + $conf['extra_login_security'] = false; + +找到这一行: + + $conf['owned_only'] = false; + +更改值为 **true**。 + + $conf['owned_only'] = true; + +保存并关闭文件。重启 postgresql 服务和 Apache 服务。 + + sudo systemctl restart postgresql + +---------- + + sudo systemctl restart apache2 + +或者, + + sudo service postgresql restart + + sudo service apache2 restart + +现在打开你的浏览器并导航到 **http://ip-address/phppgadmin**。你会看到以下截图。 + +![phpPgAdmin – Google Chrome_001](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_001.jpg) + +用你之前创建的用户登录。我之前已经创建了一个名为 “**senthil**” 的用户,密码是 “**ubuntu**”,因此我以 “senthil” 用户登录。 + +![phpPgAdmin – Google Chrome_002](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_002.jpg) + +然后你就可以访问 phppgadmin 面板了。 + +![phpPgAdmin – Google Chrome_003](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_003.jpg) + +用 postgres 用户登录: + +![phpPgAdmin – Google Chrome_004](http://1426826955.rsc.cdn77.org/wp-content/uploads/2015/11/phpPgAdmin-Google-Chrome_004.jpg) + +就是这样。现在你可以用 phppgadmin 可视化创建、删除或者更改数据库了。 + +加油! + +-------------------------------------------------------------------------------- + +via: http://www.unixmen.com/install-postgresql-9-4-and-phppgadmin-on-ubuntu-15-10/ + +作者:[SK][a] +译者:[ictlyh](http://mutouxiaogui.cn/blog/) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.twitter.com/ostechnix +[1]:http://www.postgresql.org/ +[2]:http://phppgadmin.sourceforge.net/doku.php \ No newline at end of file