在CentOS7中安装Apache和PostgreSQL
动机
在一个CentOS系统中构筑网络服务器环境。
Web容器选择Apache;数据库选择PostgreSQL。
环境
一、配置网络
- 确保
Automatically connect选项被选中。
- 重启网络服务,获取IP地址。
shell
1
|
sudo systemctl restart network
|
二、安装SSH服务
shell
1
|
sudo yum install -y openssh openssh-server openssh-clients openssl-libs
|
shell
1
|
sudo systemctl enable sshd.service
|
shell
1
|
sudo systemctl start sshd.service
|
三、通过PuTTY连接服务器
- 从PuTTY官网下载并安装最新版客户端。
- 在PuTTY客户端输入服务器IP,点击“Open”。
四、安装Apache
shell
1
|
sudo yum install -y httpd
|
shell
1
|
sudo systemctl enable httpd .service
|
shell
1
|
sudo systemctl start httpd .service
|
shell
1
|
sudo firewall-cmd --add-port 80/tcp
|
五、安装PostgreSQL 9.6
shell
1
|
sudo yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
|
shell
1
|
sudo yum install -y postgresql96-server postgresql96-contrib
|
shell
1
|
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
|
shell
1
|
sudo systemctl enable postgresql-9.6.service
|
shell
1
|
sudo systemctl start postgresql-9.6.service
|
shell
1
|
sudo nano /var/lib/pgsql/9.6/data/postgresql.conf
|
修改#listen_addresses = 'localhost'为listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
shell
1
|
sudo nano /var/lib/pgsql/9.6/data/pg_hba.conf
|
修改如下内容,信任指定服务器连接
shell
1
2
3
|
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
|
这里的0.0.0.0/0意思是相信所有IP,也可以指定IP,例如:192.168.0.5/32
CentOS 防火墙中内置了PostgreSQL服务,我们只需以服务方式将PostgreSQL服务开放即可。
开放postgresql服务
shell
1
|
sudo firewall-cmd --add-service=postgresql --permanent
|
重载防火墙
shell
1
|
sudo firewall-cmd --reload
|
shell
1
|
sudo systemctl restart postgresql-9.6.service
|
comments powered by