Can't connect to MySQL server foreman 1.15 with external RDS mysql database

Hi, im running into this issue with foreman 1.15 and an external rds mysql database

the installation from a fresh new ami:

foreman-installer \
  --foreman-db-type=mysql \
  --foreman-db-host=host.us-west-2.rds.amazonaws.com \
  --foreman-db-database=foreman \
  --foreman-db-username=foreman \
  --foreman-db-password=password

I can telnet the db host from the server port 3306 and connect with the same credentials from /etc/foreman/database.yaml from the command line using the mysql command.

The instalation does create the tables inside the database, so the connection can be possible from the host.

after that::

Web application could not be started

Can't connect to MySQL server on 'engineering.ctkb3rwlea2h.us-west-2.rds.amazonaws.com' (13) (Mysql2::Error)   /opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `connect'   /opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `initialize'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'   /opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'   /opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'   /opt/theforeman/tfm/root/usr/share/gems/gems/ancestry-2.2.1/lib/ancestry/has_ancestry.rb:46:in `has_ancestry'   /usr/share/foreman/app/models/concerns/nested_ancestry_common.rb:7:in `block in <module:NestedAncestryCommon>'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `class_eval'   /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `append_features'   /usr/share/foreman/app/models/taxonomy.rb:5:in `include'
  /usr/share/foreman/app/models/taxonomy.rb:5:in `<class:Taxonomy>'   /usr/share/foreman/app/models/taxonomy.rb:1:in `<top (required)>'   /opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'   /opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/ker
Seeing the facts, that the connection seems to work from scripts but not from the service,
I would recommend trying `setenforce 0` for start to rule out SELinux could be the case here

-- Ivan

čt 23. 11. 2017 v 20:57 odesílatel <anovotny@bookingbug.com> napsal:

···
Hi, im running into this issue with foreman 1.15 and an external rds mysql
database

the installation from a fresh new ami:

foreman-installer \
--foreman-db-type=mysql \
--foreman-db-host=host.us-west-2.rds.amazonaws.com \
--foreman-db-database=foreman \
--foreman-db-username=foreman \
--foreman-db-password=password

I can telnet the db host from the server port 3306 and connect with the
same credentials from /etc/foreman/database.yaml from the command line
using the mysql command.

The instalation does create the tables inside the database, so the
connection can be possible from the host.

after that::

Web application could not be started

Can't connect to MySQL server on 'engineering.ctkb3rwlea2h.us-west-2.rds.amazonaws.com' (13) (Mysql2::Error)
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `connect'
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `initialize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'
/opt/theforeman/tfm/root/usr/share/gems/gems/ancestry-2.2.1/lib/ancestry/has_ancestry.rb:46:in `has_ancestry'
/usr/share/foreman/app/models/concerns/nested_ancestry_common.rb:7:in `block in <module:NestedAncestryCommon>'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `class_eval'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `append_features'
/usr/share/foreman/app/models/taxonomy.rb:5:in `include'
/usr/share/foreman/app/models/taxonomy.rb:5:in `<class:Taxonomy>'
/usr/share/foreman/app/models/taxonomy.rb:1:in `<top (required)>'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/ker

--
You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

That was it, thanks.


··· On Friday, 24 November 2017 07:08:20 UTC, Ivan Necas wrote:

Seeing the facts, that the connection seems to work from scripts but not
from the service,
I would recommend trying `setenforce 0` for start to rule out SELinux
could be the case here

-- Ivan

čt 23. 11. 2017 v 20:57 odesílatel <anov...@bookingbug.com <javascript:>>
napsal:

Hi, im running into this issue with foreman 1.15 and an external rds
mysql database

the installation from a fresh new ami:

foreman-installer \
--foreman-db-type=mysql \
--foreman-db-host=host.us-west-2.rds.amazonaws.com \
--foreman-db-database=foreman \
--foreman-db-username=foreman \
--foreman-db-password=password

I can telnet the db host from the server port 3306 and connect with the
same credentials from /etc/foreman/database.yaml from the command line
using the mysql command.

The instalation does create the tables inside the database, so the
connection can be possible from the host.

after that::

Web application could not be started

Can't connect to MySQL server on 'engineering.ctkb3rwlea2h.us-west-2.rds.amazonaws.com' (13) (Mysql2::Error)
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `connect'
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `initialize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'
/opt/theforeman/tfm/root/usr/share/gems/gems/ancestry-2.2.1/lib/ancestry/has_ancestry.rb:46:in `has_ancestry'
/usr/share/foreman/app/models/concerns/nested_ancestry_common.rb:7:in `block in <module:NestedAncestryCommon>'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `class_eval'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `append_features'
/usr/share/foreman/app/models/taxonomy.rb:5:in `include'
/usr/share/foreman/app/models/taxonomy.rb:5:in `<class:Taxonomy>'
/usr/share/foreman/app/models/taxonomy.rb:1:in `<top (required)>'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/ker

--
You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-user...@googlegroups.com <javascript:>.
To post to this group, send email to forema...@googlegroups.com
<javascript:>.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Nice! Make sure you enable selinux again and do it properly, I’d be supprised if there wasn’t any relevant booleans to get it working.

There really is no reason to run anything with selinux disabled :-)

··· On Fri, 24 Nov 2017 at 10:01, <anovotny@bookingbug.com> wrote:

That was it, thanks.

On Friday, 24 November 2017 07:08:20 UTC, Ivan Necas wrote:

Seeing the facts, that the connection seems to work from scripts but not
from the service,
I would recommend trying `setenforce 0` for start to rule out SELinux
could be the case here

-- Ivan

čt 23. 11. 2017 v 20:57 odesílatel <anov...@bookingbug.com> napsal:

Hi, im running into this issue with foreman 1.15 and an external rds
mysql database

the installation from a fresh new ami:

foreman-installer \
--foreman-db-type=mysql \
--foreman-db-host=host.us-west-2.rds.amazonaws.com \
--foreman-db-database=foreman \
--foreman-db-username=foreman \
--foreman-db-password=password

I can telnet the db host from the server port 3306 and connect with the
same credentials from /etc/foreman/database.yaml from the command line
using the mysql command.

The instalation does create the tables inside the database, so the
connection can be possible from the host.

after that::

Web application could not be started

Can't connect to MySQL server on 'engineering.ctkb3rwlea2h.us-west-2.rds.amazonaws.com' (13) (Mysql2::Error)
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `connect'
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `initialize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'
/opt/theforeman/tfm/root/usr/share/gems/gems/ancestry-2.2.1/lib/ancestry/has_ancestry.rb:46:in `has_ancestry'
/usr/share/foreman/app/models/concerns/nested_ancestry_common.rb:7:in `block in <module:NestedAncestryCommon>'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `class_eval'
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/concern.rb:120:in `append_features'
/usr/share/foreman/app/models/taxonomy.rb:5:in `include'
/usr/share/foreman/app/models/taxonomy.rb:5:in `<class:Taxonomy>'
/usr/share/foreman/app/models/taxonomy.rb:1:in `<top (required)>'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/ker

--
You received this message because you are subscribed to the Google
Groups "Foreman users" group.

To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-user...@googlegroups.com.
To post to this group, send email to forema...@googlegroups.com.

Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

I am getting the same kind of error for mysql. But able to connect external node of mysql . We are using mysql database as a external node. Selinux is also disabled

Mysql2::Error: Can’t connect to MySQL server on ‘sjforemandb.example.com’ (111)
/opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in connect' /opt/theforeman/tfm/root/usr/share/gems/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in initialize’
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in new' /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in mysql2_connection’
[root@sjforeman02 ~]# telnet sjforemandb 3306
Trying 172.18.19.131…
Connected to sjforemandb.
Escape character is ‘^]’.
J
5.7.w,U z<&Eo%7[a0mysql_native_passwordConnection closed by foreign host.
[root@sjforeman02 ~]# getenforce
Disabled
[root@sjforeman02 ~]#

Could you please help what could be wrong.

Hello,
This is a 3 year old thread, chances are low you’ll get any responses. Additionally, MySQL is no longer supported by Foreman since 2.0 which was released about a year ago.
You should look into migrating your data to PostgreSQL (see Foreman :: Manual for instructions) and upgrade your Foreman instance to a supported version (2.3.1 or 2.2.2 at the time of writing).
p.s. I took the liberty of scrubbing your domain name from the post.