简体   繁体   中英

Distributed Rails App - how to configure?

I have a rather straight-forward Rails app that runs on puma. On a single node - it's great and works exactly how I want it to.

What I've been having a very hard time finding - I'm being asked to deploy this app across two nodes. If you connect to one node and do a transaction that effects the database - that change should also reflect on the other node. I cannot find any straightforward way to do this/I do not know how to.

Right now - my situation is the app is deployed on two nodes - I zipped it up, unzipped it, bundle install, rails s. Works fine on either node - but the two nodes are completely independent and have their own mysql databases . I'd want to unify them such that action on one node reflects on the other node. Sort of... some relationship between the two nodes such that they are able to talk to one another.

What are common tools or ways to accomplish this with Rails? My preference is to integrate as few software systems/install as few gems as possible - but of course, if it works, I must consider it.

As a simple setup, you can run your database on a single server. Let's call that server database.application.rails . Once you have that single server running your database and DNS or host entries pointing to it you'll need to update the Rails config/database.yml file to point to that single database as such:

production:
  adapter: mysql2
  host: database.application.rails
  username: <%= ENV["DB_USER_NAME"] %>
  password: <%= ENV["DB_PASSWORD"] %>
  database: application_prod

The above configuration also assumes you have the username and password stored as environment variables - a best practice instead of storing them in the code base.

Now when you start your rails application you'll want to use bundle exec rails s -e production .

This is not exactly a high-availability setup since you're manually starting the servers and don't have a single web server in front of the puma servers.

For a more sophisticated deployment, use capistrano to deploy the application and configure nginx to point to both your back end puma servers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM