So I have changed the postgresql.conf file to this:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
Then I changed the pg_hba.conf to host all all 127.0.0.1/32 and host all all 2601:643:8402:f900:1045:d5ae:1d3b:19d1
But I when I enter show listen_addresses; It still only lists local host. What do I need to fix in order to access my databases over a local network?
After changing those files you need to restart the database.
Related
I have PostgreSQL running on Ubuntu Server and I want to make remote connection with PostgreSQL running on port 5432.
I've checked if I can ping the public IP of ubuntu server from my machine and that works fine.
Next I've changed two files on ubuntu server first I've changed postgresql.conf which looks as below
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
Next I've added two lines in pg_hba.conf as below
host all all 0.0.0.0/0 trust
host all all ::/0 trust
Finally I checked if firewall is running by running sudo ufw verbose which outputted inactive.
As per my understanding I've allowed PostgreSQL to accept remote connection and firewall is also not present hence nothing is blocking. Still I get the following error.
psycopg2.OperationalError: connection to server at "XXX.XXX.XXX.XXX", port 5432 failed: Connection timed out (0x0000274C/10060)
Is the server running on that host and accepting TCP/IP connections?
How can I fix this error?
Edit
Although I can ping and ssh to the Ubuntu server using public IP but can not telnet.
I checked if port 5432 is open using this link but it turned out to be closed.
I just purchased a domain from GoDaddy, let's call it example.com. I set it up on GoDaddy to where it forwards people to my home IP Address where my Raspberry Pi hosts my website using Apache2. How can I properly set it up so that it shows example.com in the address bar rather than my home IP address?
Here is my .conf file for my website:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
If you visited the site via IP address prior to porting and setting a DNS record. You may need to clear your browser and DNS cache. This is how to flush Windows DNS via command line:
ipconfig /flushdns
Note that you MAY have to run cmd as admin.
I am running local development server in a Vagrant box and trying to open it in Chrome(host machine). But it fails to open in the host machine. Using the curl on localhost:7000 in the guest machine returns the HTML content. This is my Vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provision :shell, path: "setup_dev_env.sh"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 7080, host: 7080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 7000, host: 7000, host_ip: "127.0.0.1"
config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "4096"
end
end
Command to run the server(guest machine):
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py PATH_TO_app.yaml --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db
You need to add the following when running your command (https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command)
--host=...
The host address to use for the server. You may need to set this to be able to access the development server from another computer on
your network. An address of 0.0.0.0 allows both localhost access and
IP or hostname access. Default is localhost.
In your case as running in vagrant, you need to make sure its bound to 0.0.0.0
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py \
PATH_TO_app.yaml \
--host=0.0.0.0 --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db
I have some severe problems with connecting from DBVisualizer (8.0.9) to a PostgreSQL server which is running in the same LAN. DBVis is Java-based thus uses JDBC for connection. Connecting from PGAdmin works like a charm - only DBVis connection via JDBC isn't. And I need that to be solved!
Specs:
My PC: Ubuntu 12.04 LTS (64Bit), IP: 192.168.110.193
Server OS: Suse LINUX Enterprise Server 11, IP: 192.168.110.12
Postgresql server version: 9.1
Java VM: Java HotSpot(TM) 64-Bit Server VM
Java Version: 1.6.0_33
Java Vendor: Sun Microsystems Inc.
OS Name: Linux
OS Arch: amd64
OS Version: 3.2.0-25-generic
When starting a connection, I'm getting a "Connecting..." message and after ~5 minutes of waiting the following error message appears in the connection window:
"An error occurred while establishing the connection:
Long Message:
The connection attempt failed.
Details:
Type: org.postgresql.util.PSQLException
SQL State: 08001"
In the debug console I get:
12:04:57 [DEBUG pool-2-thread-8 D.ā] RootConnection: Driver.acceptsURL("jdbc:postgresql://192.168.110.12:5432/MYDATABASE")
12:04:57 [DEBUG pool-2-thread-8 D.ā] RootConnection: Driver.connect("jdbc:postgresql://192.168.110.12:5432/MYDATABASE", {user=******, password=******})
12:24:58 [DEBUG pool-2-thread-8 D.ā] RootConnection: EXCEPTION -> org.postgresql.util.PSQLException: The connection attempt failed.
The debugging information of the JDBC driver is also provided:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:150)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection.java:30)
at org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.onseven.dbvis.d.B.D.ā(Z:1548)
at com.onseven.dbvis.d.B.F$A.call(Z:278)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
For convenience the relevant part of the server's pg_hba.conf:
#"local" is for Unix domain socket connections only
local all all peer
#IPv4 local connections:
host all all 192.168.110.0/24 md5
#IPv6 local connections:
host all all ::1/128 md5
And the relevant parts of the postgresql.conf:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
#port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = '' # (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - Security and Authentication -
#authentication_timeout = 1min # 1s-600s
#ssl = off # (change requires restart)
#ssl_ciphers = 'ALL:!ADH:!LOW:!EXP:!MD5:#STRENGTH' # allowed SSL ciphers
# (change requires restart)
#ssl_renegotiation_limit = 512MB # amount of data between renegotiations
#password_encryption = on
#db_user_namespace = off
# Kerberos and GSSAPI
#krb_server_keyfile = ''
#krb_srvname = 'postgres' # (Kerberos only)
#krb_caseins_users = off
# - TCP Keepalives -
# see "man 7 tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
# 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
The connection is running now but unfortunately I cannot exactly tell the steps that led to the solution. Anyway, I will try to sketch them:
I installed an old version of DBVisualizer (7.1.5) and was able to successfully establish a connection to the db server. Then I went straight back to the 8.0.9
version of DBVis and tested the connection again. Unexpectedly, the connection also worked here, even though I didn't change configurations - neither in my DBVis 8.0.9 installation nor on the DB server. That's it. Maybe someone has some some more clues on that issue.
The error code 08001 is a generic error code telling that the JDBC driver could not connect to the database. The reason for this could be many.
You should enter the IP address or DNS name of the server where the database runs as the Database Server and the Database Port it listens to for TCP/IP connections, by default 5432.
After you have entered this, please use the Ping Server button to see if you can reach that server and port. If you get an error message, you have either entered incorrect Database Server or Port values, there is a firewall that blocks the connection, or the PostgreSQL server is not configured to access connections from your PC. If Ping Server says everything is fine but you still cannot connect, the problem is most likely with the login credentials for the user account you specify.
I use centOS server. I want to configure apache to listen on port 8079.
I added LISTEN 8079 directive in httpd.conf.
I opened port 8079 in iptables and restarted iptables. I even stopped iptables service.
"netstat -nal | grep 8079" shows "tcp 0 0 :::8079 :::* LISTEN"
If I try to access http://localhost:8079 or http://myserver.com:8079 from that machine, I can access that page. BUT from any other machine I am not able to access the site on any port other than 80. On port 80, it works. On port 8079 it does not.
What else do I need to configure?
In /etc/apache2/ports.conf, change the port as
Listen 8079
Then go to /etc/apache2/sites-enabled/000-default.conf
And change the first line as
<VirtualHost *: 8079>
Now restart
sudo service apache2 restart
Apache will now listen on port 8079 and redirect to /var/www/html
Open httpd.conf file in your text editor.
Find this line:
Listen 80
and change it
Listen 8079
After change, save it and restart apache.
It was a firewall issue. There was a hardware firewall that was blocking access to almost all ports. (Turning off software firewall / SELinux bla bla had no effect)
Then I scanned the open ports and used the port that was open.
If you are facing the same problem, Run the following command
sudo nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000
It will scan for all the open ports on your system. Any port that is open can be accessed from outside.
Ref.: http://www.go2linux.org/which_service_or_program_is_listening_on_port
If you need apache Listen port other than 80, you should add next file under ubuntu
"/etc/apache2/ports.conf"
the list of Listen ports
Listen 80
Listen 81
Listen 82
After you have to go on your Virtual hosts conf file and define next
<VirtualHost *:80>
#...v host 1
</VirtualHost>
<VirtualHost *:81>
#...host 2
</VirtualHost>
<VirtualHost *:82>
#...host 3
</VirtualHost>
This is working for me on Centos
First: in file /etc/httpd/conf/httpd.conf
add
Listen 8079
after
Listen 80
This till your server to listen to the port 8079
Second: go to your virtual host for ex. /etc/httpd/conf.d/vhost.conf
and add this code below
<VirtualHost *:8079>
DocumentRoot /var/www/html/api_folder
ServerName example.com
ServerAlias www.example.com
ServerAdmin root#example.com
ErrorLog logs/www.example.com-error_log
CustomLog logs/www.example.com-access_log common
</VirtualHost>
This mean when you go to your www.example.com:8079 redirect to
/var/www/html/api_folder
But you need first to restart the service
sudo service httpd restart
If you are using Apache on Windows:
Check the name of the Apache service with Win+R+services.msc+Enter (if it's not ApacheX.Y, it should have the name of the software you are using with apache, e.g.: "wampapache64");
Start a command prompt as Administrator (using Win+R+cmd+Enter is not enough);
Change to Apache's directory, e.g.: cd c:\wamp\bin\apache\apache2.4.9\bin;
Check if the config file is OK with: httpd.exe -n "YourServiceName" -t (replace the service name by the one you found on step 1);
Make sure that the service is stopped: httpd.exe -k stop -n "YourServiceName"
Start it with: httpd.exe -k start -n "YourServiceName"
If it starts alright, the problem is no longer there, but if you get:
AH00072: make_sock: could not bind to address IP:PORT_NUMBER
AH00451: no listening sockets available, shutting down
If the port number is not the one you wanted to use, then open the Apache config file (e.g. C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf open with a code editor or wordpad, but not notepad - it does not read new lines properly) and replace the number on the line that starts with Listen with the number of the port you want, save it and repeat step 6. If it is the one you wanted to use, then continue:
Check the PID of the process that is using that port with Win+R+resmon+Enter, click on Network tab and then on Ports subtab;
Kill it with: taskkill /pid NUMBER /f (/f forces it);
Recheck resmon to confirm that the port is free now and repeat step 6.
This ensures that Apache's service was started properly, the configuration on virtual hosts config file as sarul mentioned (e.g.: C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf) is necessary if you are setting your files path in there and changing the port as well. If you change it again, remember to restart the service: httpd.exe -k restart -n "YourServiceName".
For FC22 server
cd /etc/httpd/conf
edit httpd.conf [enter]
Change:
Listen 80
to:
Listen whatevernumber
Save the file
systemctl restart httpd.service [enter]
if required, open whatevernumber in your router / firewall
Run this command if your ufw(Uncomplicatd Firewall) is enabled .
Add for Example port 8080
$ sudo ufw allow 8080/tcp
And you can check the status by running
$ sudo ufw status
For more info check :
https://linuxhint.com/ubuntu_allow_port_firewall