I'm writing a Rails application that needs to connect to an Oracle database inside a company firewall. Thus, i need to connect to their VPN or at least use a static IP address to make all my connections.
I've tried Proximo and QuotaGuard without success. I make all required configs, but no matter what i do, the firewall says i'm trying to connect through my actual IP, instead of the static one.
After a couple of days trying, and a big help from the QuotaGuard guys, i solved it:
QuotaGuard works by overriding DNS lookup so my server connections goes to my local machine, where a process will redirect all traffic to my remote server, that will connect through the right IP.
But it seems like oracle drivers don't see this DNS changes, so it will make all the requests to the final server, who blocks my connection. All i did was point my database connection info to 127.0.0.1, so the qgtunnel app could send it to the final server.
It's working like a charm now.
So, my final setup was like:
.qgtunnel file
[qgtunnel.0]
accept = "127.0.0.1:3333"
connect = "HOST_ADDRESS:3333"
encrypted = false
transparent = true
config/oracle_db.yml file
default: &default
encoding: utf8
adapter: oracle_enhanced
host: 127.0.0.1
port: 3333
database: database
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASS'] %>
development:
<<: *default
test:
<<: *default
production:
<<: *default
Procfile file
web: bin/qgtunnel bundle exec puma -C config/puma.rb
Related
I already set up SLL certificate like here:
export DATABASE_URL="mysql2://leder:password#pfhpdb.cyo1f7mucyku.eu-central-1.rds.amazonaws.com/pfhpdb?sslca=config/amazon-rds-ca-cert.pem"
when running my heroku rails 5 app w/ production environment and DB I get the following error:
ActionView::Template::Error (Can't connect to MySQL server on 'pfhpdb.cyo1f7mucyku.eu-central-1.rds.amazonaws.com' (101 "Network is unreachable")):
My database.yml is as follows:
production:
adapter: mysql2
encoding: utf8
host: pfhpdb.cyo1f7mucyku.eu-central-1.rds.amazonaws.com
database: pfhpdb
pool: 5
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
Comment: same error when connecting to RDS w/ SQuirreL - class java.net.SocketException: Network is unreachable (connect failed)!
UPDATE 20200503:
as of this post:
Mariadb connection client: Access denied for user (using password: NO) on mysql 8.0
I cannot login w/ password in MariaDB and cannot change DB table access b/c I cannot login w/ password in MariaDB. I am shut off from my DB...
Please check security group of your RDS instance; probably you have not opened the port. Also, please try this to see if port is open or not.
$ telnet cyo1f7mucyku.eu-central-1.rds.amazonaws.com 3306
In the end the authentication error went away by resetting the AWS RDS DB administrator password in the console settings of RDS.
When I deploy my app on aws beanstalk using eb deploy it gives an error
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
.ebextensions/postgres.config:
packages:
yum:
postgresql93-devel: []
config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
production:
<<: *default
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
I had the exact same issue.
The problem is that you have to connect your database to the application through the environment variables.
First you need to create an RDS instance to connect to. This link shows you how: https://aws.amazon.com/getting-started/tutorials/create-connect-postgresql-db/?nc1=h_ls
Then, after the instance is created, you need to go to the RDS Service page, and choose instance in the left menu. Choose the instance you created in the list and proceed to the section called "Connect". Those are the values you put inside those environment variables, with the HOSTNAME value being the endpoint.
Hope it helped, worked for me!
I had a similar problem, but in my case the RDS connection was timing out. The solution was add the security group of my EC2 instance to the "inbound" section of the RDS security group.
To do this go to EC2 page and search for "Security Groups", there you can find your RDS and EC2 security groups, click in the RDS security group and add the EC2 security group.
I would like to deploy my application via Dokku to a VPS.
Putting together the dokku-postgres documentation and the relative, scarce internet documentation on the matter (one at GitHub), it seems necessary to configure database.yml to use the url environment variable url: <%= ENV['DATABASE_URL'] %>
Since I could not find any other sources of information, I wonder how database.yml should be configured, and how Rails will connect to the postgres service created with Dokku.
For instance, taken for granted that linking url to the DATABASE_URL variable is necessary, will this be enough to establish a connection between my Rails application and the postgres service or would it be still necessary to use a username and a password? In the latter case, what username and password am I expected to use?
Below is how at present my database.yml looks like.
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: asarluhi
development:
<<: *default
database: fireworks_app_development
test:
<<: *default
database: fireworks_app_test
production:
<<: *default
database: fireworks_app_production
pool: 25
username: fireworks_app
password: <%= ENV['FIREWORKS_APP_DATABASE_PASSWORD'] %>
This file was created as it is (apart from a higher pool size for production) when I created the application. How would you suggest to edit the production section?
The dokku-postgres documentation states that the following (and nothing else) will be set on the linked application by default:
DATABASE_URL=postgres://postgres:SOME_PASSWORD#dokku-postgres-lolipop:5432/lolipop
In place of the lollipop postgres service example, I would use fireworks_app_production to match the name of the database in database.yml
Are username and password still necessary after pointing url to the DATABASE_URL variable? Am I expected to add or remove anything else?
You don't need to worry about the database.yml with dokku, just upload your app to the server, let's use "fireworks" as the name for example on this.
when you upload the first time the app, this is created automatically so you don't need to create it.
then you install the postgres plugin and run
# that will create the container for the database
$ dokku postgres:create fireworks
# and then you link both, the app with the database
$ dokku postgres:link fireworks fireworks
you don't have to worry about anything else, with that dokku will connect this
then you just have to run db:migrate and everything is ready to work!
So, I'm fairly new to dealing with databases, and it makes sense to me when the database is on the local machine. But, how would I deal with a database that is far away/in a different computer? How is the connection set-up? How would I be able to tell Ruby to go toy with that database? I think SQLite is required to be on the local machine, but what about PostgreSQL or MySQL? I'm positive large projects require this sort of set-up with databases somewhere else and whatnot.
Also, this means teams should be able to all interact with the same database, correct?
I've tried finding articles and reading about it, but I can't seem to find any information about this.
In ruby on rails, we have a config/database.yml file where we can do database connectivity.
To connect to the remote system's database do:
1 - Give permission to your system to access the database of remote system
Grant all on databasename.* to username#ipaddress of your system identified by password
2 - Update the database.yml file
development:
adapter: mysql
database: databasename
username: username
password: password
host: ip of remote system
Configuring database.yml for your rails app
development:
adapter: mysql
database: development_database
username: root
password: [password]
host: localhost
test:
adapter: mysql
database: test_database
username: root
password: [password]
host: localhost
production:
adapter: mysql
database: production_database
username: root
password: [password]
host: localhost
Don't forget that these databases are not just files that the local program accesses -- they are servers in their own right, and the local program submits requests (select, insert etc) to them for the database server to process and return a result.
This also explains why multiple teams can access the same database -- the database server processes are just communicating with multiple programs at the same time (and the resolution of which program sees which data when they are all accessing and changing the same tables is one of the reasons why databases are so complex).
So the location of the database is only relevant in that it can take longer to send requests to, and retrieve results from, it over the network.
basically I have a mongodb instance running and working on ec2. On the side I have a rails 3.2 app with mongoid as orm working on local. What I want to do next is try to connect my rails app to the mongodb instance using mongoid. Also, intending to host my rails app on Dotcloud later
Ran the code rails g mongoid:config to generate the mongoid.yml file with the following code:
development:
host: localhost
database: mongotest_development
test:
host: localhost
database: mongotest_test
set these environment variables on your prod server
production:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
From here onwards, I don't think I have a clear picture of how all this is going to work. But I did some trial and error. Firstly I wanted to try connecting to the mongodb instance on development, so I commented out the mongoid.yml defaults and added the following:
development:
host: <public dns of the mongodb instance>
port: 27017
# username:
# password:
database: <I ssh into the instance and created a database>
I commented the username and password out partly because I am not sure what to put, and partly because when I inspect the mongod.conf file on ec2, I saw that by default :auth is false, so I assume authentication is not required. So I ran rails console and got the following error:
Failed to connect to a master node at <public dns of the mongodb instance>:27017 (Mongo::ConnectionFailure)
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:589:in `setup'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:114:in `initialize'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:165:in `new'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:165:in `from_uri'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config/database.rb:86:in `master'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config/database.rb:19:in `configure'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config.rb:290:in `configure_databases'
....
At this point, I am kind of confused. I kept asking myself, do I need the username and password to connect to mongodb ? I kind of 80% sure that I need them but I am not sure where to find them or rather not sure what am I connecting to, the mongodb ec2 instance or the mongodb database. How should I go about doing that ? Should I open port 27017 and 28017 on the instance ? Do I need to add config to database.yml (I highly doubt I need to since there is already mongoid.yml but just want to confirm)
I have been looking at a list of documentation and tutorial:
http://mongoid.org/docs/installation/configuration.html
http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-AbouttheKeyFile
MongoDB and Mongoid in production - looks like what I looking for, but not sure, going to try it.
http://craiccomputing.blogspot.com/2011/02/authentication-in-mongo-and-mongoid.html
Appreciate any advice from anyone here.
Ok finally found the problem. In the mongodb.conf file, there is a setting which called
bind_ip = 127.0.0.1
I was blind to not notice this, it means that the server can only be access locally and not externally, hence the fail connection error. A quick fix would be to change it to
bind_ip = 0.0.0.0
and it works. But thanks for the advice guys.
It is most likely a firewall issue. Check to see if the security group for your ec2 instance has the default mongodb port 27017 open.
This article will give you the gist of how it works if you haven't done something like that before:
http://cloud-computing.learningtree.com/2010/09/24/understanding-amazon-ec2-security-groups-and-firewalls/