Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/compose: Fix missing permissions #5426

Merged
merged 1 commit into from Nov 23, 2019

Conversation

chapsuk
Copy link
Contributor

@chapsuk chapsuk commented Nov 11, 2019

Hi there 👋

Thanks for the rich beginners examples set!
I'm followed the docker-compose example and caught the small fault:

# 1. wrong permissions
bash-3.2$ ./lmysql.sh 
bash: ./lmysql.sh: Permission denied

# fix it
bash-3.2$ chmod +x lmysql.sh

# 2. Example command as is
bash-3.2$ ./lmysql.sh --port=15306 --host=127.0.0.1
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

# pass CS fix it
bash-3.2$ CS=vtgate ./lmysql.sh --port=15306 --host=127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.10-Vitess
...

@sougou
Copy link
Contributor

sougou commented Nov 11, 2019

@jawabuu

@jawabuu
Copy link
Contributor

jawabuu commented Nov 11, 2019

@chapsuk , @sougou I'll verify on a fresh clone

@morgo
Copy link
Contributor

morgo commented Nov 11, 2019

I would like to make an alternative recommendation: in the get started local guide, I changed it to use a local mysql configuration file:

cat << EOF > ~/.my.cnf
[client]
host=127.0.0.1
port=15306
EOF

This helps remove 1 level of indirection, and the mysql program should already be in the PATH, so it will work everywhere.

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

@chapsuk What's your environment?
Running ./lmysql.sh without arguments will try to connect to your host MySQL server through socket so it will fail.
chmod +x lmysql.sh
should not be necessary.
Try on a fresh clone and if the issue recurs, share your output of
docker-compose ps

Port 15306 for vtgate container is exposed on your host. So
./lmysql.sh --port=15306 --host=127.0.0.1
should work if you change 127.0.0.1 to your host or docker-machine ip. 127.0.0.1 directs to container's loopback interface.

@morgo The host in our case will be variable based on user's docker ip. Also the compose example does not require or depend on mysql being available on PATH. It uses mysql available in any of the containers.

@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

@jawabuu thanks for response.

What's your environment?

docker desktop 2.1.0.4 (Docker version 19.03.4)
I'm using fresh clone and repeat the problem twice.

Running ./lmysql.sh without arguments will try to connect to your host MySQL server through socket so it will fail. chmod +x lmysql.sh should not be necessary.

The lmysql.sh script not executable and arguments does not matter in this case.
If you look to PR changes you will see mod changes
image

Port 15306 for vtgate container is exposed on your host. So
./lmysql.sh --port=15306 --host=127.0.0.1
should work if you change 127.0.0.1 to your host or docker-machine ip. 127.0.0.1 directs to container's loopback interface.

The lmysql.sh script try to connect to vtgate from vttable container by default and 127.0.0.1 will not works for any environment (docker machine ip or localhost usage).

Fresh clone example:

≻ git clone https://github.com/vitessio/vitess.git
Cloning into 'vitess'...
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 160173 (delta 4), reused 5 (delta 1), pack-reused 160151
Receiving objects: 100% (160173/160173), 103.84 MiB | 3.88 MiB/s, done.
Resolving deltas: 100% (118769/118769), done.

≻ cd vitess/examples/compose/
≻ ls -l lmysql.sh
-rw-r--r--  1 chapsuk  staff  935 Nov 12 10:29 lmysql.sh

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

@chapsuk Thanks for this.
Are you using Windows or Mac?
Point on lmysql.sh mod is noted.
Share your output of docker-compose ps

@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

Are you using Windows or Mac?

Mac

Share your output of docker-compose ps

≻ docker-compose ps
                 Name                                Command                  State                                           Ports
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
compose_consul1_1                         docker-entrypoint.sh agent ...   Up             8300/tcp, 8301/tcp, 8301/udp, 8302/tcp, 8302/udp, 0.0.0.0:8400->8400/tcp,
                                                                                          0.0.0.0:8500->8500/tcp, 0.0.0.0:8600->8600/tcp, 8600/udp
compose_consul2_1                         docker-entrypoint.sh agent ...   Up             8300/tcp, 8301/tcp, 8301/udp, 8302/tcp, 8302/udp, 8400/tcp, 8500/tcp,
                                                                                          8600/tcp, 8600/udp
compose_consul3_1                         docker-entrypoint.sh agent ...   Up             8300/tcp, 8301/tcp, 8301/udp, 8302/tcp, 8302/udp, 8400/tcp, 8500/tcp,
                                                                                          8600/tcp, 8600/udp
compose_schemaload_test_keyspace_1        sh -c /script/schemaload.sh      Up
compose_schemaload_unsharded_keyspace_1   sh -c /script/schemaload.sh      Up
compose_vtctld_1                          sh -c  $VTROOT/bin/vtctld  ...   Up             0.0.0.0:32768->15999/tcp, 0.0.0.0:15000->8080/tcp
compose_vtgate_1                          sh -c /script/run-forever. ...   Up             0.0.0.0:15306->15306/tcp, 0.0.0.0:32776->15999/tcp, 0.0.0.0:15099->8080/tcp
compose_vttablet101_1                     sh -c /script/vttablet-up. ...   Up (healthy)   0.0.0.0:32774->15999/tcp, 0.0.0.0:32777->3306/tcp, 0.0.0.0:15101->8080/tcp
compose_vttablet102_1                     sh -c /script/vttablet-up. ...   Up (healthy)   0.0.0.0:32771->15999/tcp, 0.0.0.0:32780->3306/tcp, 0.0.0.0:15102->8080/tcp
compose_vttablet201_1                     sh -c /script/vttablet-up. ...   Up (healthy)   0.0.0.0:32775->15999/tcp, 0.0.0.0:32779->3306/tcp, 0.0.0.0:15201->8080/tcp
compose_vttablet202_1                     sh -c /script/vttablet-up. ...   Up (healthy)   0.0.0.0:32769->15999/tcp, 0.0.0.0:32773->3306/tcp, 0.0.0.0:15202->8080/tcp
compose_vttablet301_1                     sh -c /script/vttablet-up. ...   Up (healthy)   0.0.0.0:32770->15999/tcp, 0.0.0.0:32778->3306/tcp, 0.0.0.0:15301->8080/tcp
compose_vtwork_1                          sh -c $VTROOT/bin/vtworker ...   Up             0.0.0.0:32772->15999/tcp, 0.0.0.0:15100->8080/tcp

Not have a problem with vtgate connection, second way works fine

≻ mysql --port=15306 --host=127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.10-Vitess MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

Does this work?
./lmysql.sh --port=15306 --host=vtgate

@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

Yes

bash-3.2$ ./lmysql.sh --port=15306 --host=vtgate
bash: ./lmysql.sh: Permission denied
bash-3.2$ chmod +x lmysql.sh
bash-3.2$ ./lmysql.sh --port=15306 --host=vtgate
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.10-Vitess
...

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

Yes

bash-3.2$ ./lmysql.sh --port=15306 --host=vtgate
bash: ./lmysql.sh: Permission denied
bash-3.2$ chmod +x lmysql.sh
bash-3.2$ ./lmysql.sh --port=15306 --host=vtgate
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.10-Vitess
...

I think I have zeroed on the issue referenced here
moby/moby#22753

By any chance would you know what your docker ip is?
Running ifconfig should display available interfaces

Test if this works
./lmysql.sh --port=15306 --host=192.168.65.1

@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

Yep, i can use my docker host ip and it works fine.
But not sure why we call vtgate from vttable container?

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

Yep, i can use my docker host ip and it works fine.
But not sure why we call vtgate from vttable container?

Excellent!!
The decision to use vttablet specifically vttablet101 as default is related mostly to startup order. vttablet101 has a stronger guarantee to be up as opposed to vtgate which is only fully functional if the rest of the containers are up.
This helps in debugging if anything goes wrong.
Connecting to vtgate through the host ip is also meant to better demonstrate to beginners the workings of vitess.
We can update the file permissions and add a note for Docker Desktop users (both Mac and Windows) specifying the host IP to use.
Would this be OK?

@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

Using external ip for internal communication between containers not a good way,
prefer this example
#5426 (comment)

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

Using external ip for internal communication between containers not a good way,
prefer this example
#5426 (comment)

This is exactly the point. We want to simulate external communication to vtgate not necessarily between containers where the host vtgate can be resolved i.e. Demonstrate how to start vitess, expose vtgate via a reachable IP and connect applications to it (with appropriate security measures of course.)

Signed-off-by: Maxim Krasilnikov <mak.krasilnikov@gmail.com>
Signed-off-by: Maxim Krasilnikov <m.krasilnikov@space307.com>
@chapsuk
Copy link
Contributor Author

chapsuk commented Nov 12, 2019

ok, PTAL

@jawabuu
Copy link
Contributor

jawabuu commented Nov 12, 2019

@sougou #LGTM
@morgo thoughts?

@sougou sougou merged commit 08810cc into vitessio:master Nov 23, 2019
@chapsuk chapsuk deleted the play_with_compose branch November 26, 2019 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants