6

在CentOS7中安装Apache和PostgreSQL

 3 years ago
source link: https://blog.mute-g.com/post/linux/setup-web-server.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在一个CentOS系统中构筑网络服务器环境。
Web容器选择Apache;数据库选择PostgreSQL。

  • CentOS 7
  • PostgreSQL 9.6

一、配置网络

  • 启动图形化网络配置工具。
nmtui
  • 确保Automatically connect选项被选中。
  • 重启网络服务,获取IP地址。
sudo systemctl restart network
  • 查看当前IP。
ip addr show

二、安装SSH服务

  • 安装OpenSSH。
sudo yum install -y openssh openssh-server openssh-clients openssl-libs
  • 将SSH服务设置为开机自动启动。
sudo systemctl enable sshd.service
  • 启动SSH服务。
sudo systemctl start sshd.service

三、通过PuTTY连接服务器

  • 从PuTTY官网下载并安装最新版客户端。
  • 在PuTTY客户端输入服务器IP,点击“Open”。

四、安装Apache

  • 安装Apache。
sudo yum install -y httpd
  • 将Apache 服务设置为开机自动启动。
sudo systemctl enable httpd .service
  • 启动Apache 服务。
sudo systemctl start httpd .service
  • 向防火墙添加http端口。
sudo firewall-cmd --add-port 80/tcp

五、安装PostgreSQL 9.6

  • 添加RPM
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
  • 安装PostgreSQL 9.6
sudo yum install -y postgresql96-server postgresql96-contrib
  • 初始化数据库
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
  • 设置开机自启动
sudo systemctl enable postgresql-9.6.service
sudo systemctl start postgresql-9.6.service
  • 开启远程访问
sudo nano /var/lib/pgsql/9.6/data/postgresql.conf

修改#listen_addresses = 'localhost'listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP

  • 信任远程连接
sudo nano /var/lib/pgsql/9.6/data/pg_hba.conf

修改如下内容,信任指定服务器连接

# 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服务

sudo firewall-cmd --add-service=postgresql --permanent

重载防火墙

sudo firewall-cmd --reload
  • 重启PostgreSQL数据服务
sudo systemctl restart postgresql-9.6.service

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK