Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Problems installing #35

Open
sglebs opened this issue Mar 31, 2015 · 18 comments
Open

Problems installing #35

sglebs opened this issue Mar 31, 2015 · 18 comments

Comments

@sglebs
Copy link

sglebs commented Mar 31, 2015

Hi,

I am using https://github.com/tsuru/tsuru-bootstrap.git and decided to try mysql as well. For that, I did this:

git clone [email protected]:tsuru/mysqlapi.git
tsuru app-create mysqlapi python -t namoroon
git remote add tsuru [email protected]:mysqlapi.git
git push tsuru
tsuru env-set MYSQLAPI_SHARED_SERVER=localhost -a mysqlapi
tsuru env-set DJANGO_SETTINGS_MODULE=mysqlapi.settings -a mysqlapi
crane create service.yaml
tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql: Post http://mysqlapi.com/resources: dial tcp: lookup mysqlapi.com: no such host

Makes sense, so I edited service.yaml:

crane remove mysqlapi
vi service.yaml, production: mysqlapi.192.168.46.226.nip.io
crane create service.yaml
tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql:

<title>Error 502 - Application Not Responding</title> <style> body { background-color: #fff; margin: 0px; padding-top: 280px; text-align: center; } h1 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 24px; font-weight: normal; } h2 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; color: #999; font-weight: normal; } </style>

Application Not Responding

Please try again in a few moments.

tsuru app-log --lines 5 -a mysqlapi
2015-03-31 08:18:07 -0300 [web][7a92435c6ad4]: Using worker: gevent
2015-03-31 08:18:07 -0300 [web][7a92435c6ad4]: Booting worker with pid: 186
2015-03-31 08:18:07 -0300 [web][7a92435c6ad4]: Worker exiting (pid: 186)
2015-03-31 08:18:08 -0300 [web][7a92435c6ad4]: Shutting down: Master
2015-03-31 08:18:08 -0300 [web][7a92435c6ad4]: Reason: Worker failed to boot.

No extra info in the logs. This did not help: tsuru env-set MYSQLAPI_DEBUG=1 -a mysqlapi

If I can suggest something, I'd say the documentation could be improved . It is not clear to the reader if the mysql instance is managed by mysqlapi itself, via docker instances it manages, or if I really need to pre-install a shared MySQL server and mysqlapi manages just databases in it (I suspect it is this option). But if I want a DEV environment, is it ok if I install mysql in the tsar-bootstrap VM itself? Or can I have it as a Docker? I would like to automate the database install as well.

Basically I am trying to use tsar for DEV deploys on developers machines for now (still using Heroku for LIVE). If it works, I will try STAGING next and LIVE last.

Note: I am having a similar problem with redisapi (ticket 28 there). So, it is probably something missing in the docs (assumes the person is a tsar expert).

Thanks!

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

Hi @sglebs, I believe there are some points missing in the README, sorry about that. Can you try running syncdb and then call service-add again?

% tsuru app-run -a mysqlapi -- python manage.py syncdb --noinput
% tsuru service-add mysqlapi namoroonmysql small -t namoroon

Thanks for reporting and sorry about the errors you're getting.

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Thanks, I will try that now and will get back to you.

Related question: do I need to have a global shared install of MySQL or can I also have dockerized MySQL instances just like the postgresapi service supports? If you look at https://github.com/guokr/tsuru-postgresapi you will see that I can configure it to create docker instances with PostgreSQL on-the-fly. Can I do the same here? Thanks!

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
Error: unexpected exit code: 1

Even though I did sudo vi /etc/mysql/my.cnf , bind-address = 0.0.0.0

I will have to see what could be wrong.

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

vagrant@ubuntu-14:~$ ifconfig
docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::5484:7aff:fefe:9799/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:110821 errors:0 dropped:0 overruns:0 frame:0
TX packets:114758 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:14443054 (14.4 MB) TX bytes:234518291 (234.5 MB)

tsuru env-set MYSQLAPI_SHARED_SERVER=172.17.42.1 -a mysqlapi

tsuru app-run -a mysqlapi -- python manage.py syncdb --noinput
still gives me:
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

I will try again after lunch.

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

Hi @sglebs, mysqlapi requires another MySQL database for storing metadata related to instances. You need to define the following environment variables (all of them are optional, I'm also specifying the default value):

  • MYSQLAPI_DB_NAME (default value: "mysqlapi")
  • MYSQLAPI_DB_USER (default value: "root")
  • MYSQLAPI_DB_PASSWORD (default value: "")
  • MYSQLAPI_DB_HOST (default value: "localhost")

Regarding the container support, currently mysqlapi doesn't work with Docker. It supports the following flavors:

  • shared instance: a shared MySQL instance where it creates databases
  • dedicated instance: launches and configure EC2 instances, it's still very limited
  • pre-provisioned instances: use pre-provisioned database instances

Unfortunately, it doesn't offer any kind of high availability yet (unless you use an Amazon RDS as shared instance or pre-provisioned instance).

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Hi @fsouza . I assume I just set the env vars and you guys create the database on-the-fly? Or do I need to create it manually myself from the console?

Since this is a DEV machine, I will share here the exact values I am using:

tsuru env-set MYSQLAPI_DB_NAME=mysqlapi
tsuru env-set MYSQLAPI_DB_USER=root
tsuru env-set MYSQLAPI_DB_PASSWORD=mysql
tsuru env-set MYSQLAPI_DB_HOST=172.17.42.1

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql:

<title>Error 502 - Application Not Responding</title> <style> body { background-color: #fff; margin: 0px; padding-top: 280px; text-align: center; } h1 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 24px; font-weight: normal; } h2 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; color: #999; font-weight: normal; } </style>

Application Not Responding

Please try again in a few moments.

I will try and create the mysqlapi database myself and will see if that fixes it.

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

Sorry, you need to create the database and then run the syncdb command (syncdb doesn't create the database, only the schema):

% tsuru app-run -a mysqlapi -- python manage.py syncdb --noinput

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Some progress:

tsuru app-run -a mysqlapi -- python manage.py syncdb --noinput

django.db.utils.OperationalError: (1130, "Host '172.17.0.45' is not allowed to connect to this MySQL server")
Error: unexpected exit code: 1

I have to edit the MySQL con I guess, just like Postgresapi.

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

I had to do this:

mysql -u root -h localhost -p
create database mysqlapi;
CREATE USER 'mysqlapi'@'localhost' IDENTIFIED BY 'mysql';
GRANT ALL PRIVILEGES ON . TO 'mysqlapi'@'localhost' WITH GRANT OPTION;
CREATE USER 'mysqlapi'@'%' IDENTIFIED BY 'mysql';
GRANT ALL PRIVILEGES ON . TO 'mysqlapi'@'%' WITH GRANT OPTION;

and then I got this:

tsuru app-run -a mysqlapi -- python manage.py syncdb --noinput
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table api_instance
Creating table api_provisionedinstance
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

But unfortunately when I run this:
tsuru service-add mysqlapi namoroonmysql small -t namoroon
I get this:

Error: Failed to create the instance namoroonmysql:

<title>Error 502 - Application Not Responding</title> <style> body { background-color: #fff; margin: 0px; padding-top: 280px; text-align: center; } h1 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 24px; font-weight: normal; } h2 { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; color: #999; font-weight: normal; } </style>

Application Not Responding

Please try again in a few moments.

Now I have to troubleshoot this next snag. Oh brother.

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Well, it looks like it was just being slow. Now it says:

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Access denied for user 'root'@'172.17.0.47' (using password: NO)

I can see it is caching "root" (the old value of env var MYSQLAPI_DB_USER, which was root but then I changed to be mysqlapi). Is there a way to force it to flush this cached value? Or do I have to remove the app and recreate it all over again?

Thanks!

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Well, I removed the whole app (mysqlapi) and added it all again, MYSQLAPI_DB_USER=mysqlapi but it does not seem to honor this env var:

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql: Access denied for user 'root'@'172.17.0.49' (using password: NO)

It looks like I will have to re-run my grant commands but using root. Bummer.

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Well, this did not fix it:

root:
CREATE USER 'root'@'localhost' IDENTIFIED BY 'mysql';
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION;
CREATE USER 'root'@'%' IDENTIFIED BY 'mysql';
GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql: Access denied for user 'root'@'172.17.0.49' (using password: NO)

And not even this fixed it:

CREATE USER 'root'@'172.17.0.49' IDENTIFIED BY 'mysql';
GRANT ALL PRIVILEGES ON . TO 'root'@'172.17.0.49' WITH GRANT OPTION;

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Error: Failed to create the instance namoroonmysql: Access denied for user 'root'@'172.17.0.49' (using password: NO)

I just ran out of ideas, guys. Suggestions?

Thanks!

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

Hmm, syncdb works but service-add doesn't?

Care to share the output of tsuru env-get -a mysqlapi?

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Sure (note that I switch the user env var back to root, since it seems to always print root@...):

tsuru env-get -a mysqlapi
DJANGO_SETTINGS_MODULE=mysqlapi.settings
MYSQLAPI_DB_HOST=172.17.42.1
MYSQLAPI_DB_NAME=mysqlapi
MYSQLAPI_DB_PASSWORD=mysql
MYSQLAPI_DB_USER=root
MYSQLAPI_SHARED_SERVER=172.17.42.1
TSURU_APPDIR=* (private variable)
TSURU_APPNAME=
* (private variable)
TSURU_APP_TOKEN=* (private variable)
TSURU_HOST=
* (private variable)

I have to say that this looks very suspicious in the error msg: (using password: NO)

Is it not using the password for root???

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

I see, the problem is that there are two MySQL servers:

  1. one for the metadata of the API
  2. one for the databases that you're going to create with service-add

You configured all environment variables for the first database, but you still need to configure the second access, with the following environment variable:

  • MYSQLAPI_SHARED_SERVER (which you already defined)
  • MYSQLAPI_SHARED_USER
  • MYSQLAPI_SHARED_PASSWORD

In your case, it's something like:

% tsuru env-set -a mysqlapi MYSQLAPI_SHARED_USER=root MYSQLAPI_SHARED_PASSWORD=mysql

BTW, you don't need the grant option in the first database, only the second. Sorry for the giant mess :-(

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

Wow, it worked:

tsuru service-add mysqlapi namoroonmysql small -t namoroon
Service successfully added.

crane list
+-------------+---------------+
| Services | Instances |
+-------------+---------------+
| redisapi | |
| postgresapi | |
| mysqlapi | namoroonmysql |
+-------------+---------------+

whew!

Now all I need to do is bing, I guess? :-)

Thanks for your help! Better docs would definitely help ;-)

@sglebs
Copy link
Author

sglebs commented Mar 31, 2015

fyi. binding seems to have worked too:

tsuru service-bind namoroonmysql -a core-server-staging

Instance "namoroonmysql" is now bound to the app "core-server-staging".
The following environment variables are available for use in your app:

  • MYSQL_HOST
  • MYSQL_PASSWORD
  • MYSQL_DATABASE_NAME
  • MYSQL_PORT
  • MYSQL_USER
  • TSURU_SERVICES

@fsouza
Copy link
Contributor

fsouza commented Mar 31, 2015

Yes, we definitely need to improve our docs. I will keep this issue open as another reminder for that!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants