The environment that
- Linux: centos7
- docker
Docker version 1.13.1, build dded712/1.13.1
- The rancher: v1.6.18
This environment needs to install docker first, docker installation here does not write, everyone baidu bar.
Create MySQL container
-
Create a mount directory
mkdir -p /opt/datas/mysql/{datadir,conf.d,logs} Copy the code
-
Create mysql container and set password 123456
docker run --name mysqldb -p 3306:3306 \ -v /opt/datas/mysql/datadir:/var/lib/mysql \ -v /opt/datas/mysql/conf.d:/etc/mysql/conf.d \ -e MYSQL_ROOT_PASSWORD=123456 -dMysql: 5.7Copy the code
-
Query test
docker exec -it mysqldb mysql -p123456 -e "show databases;" Copy the code
The mysql database is successfully initialized if the following information is displayed:
mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | information_schema | | cattle | | mysql | | performance_schema | | sys | +--------------------+ Copy the code
-
Create library and authorize (library, user, password are all cattle)
docker exec -it mysqldb mysql -p123456 -e " create database if not exists cattle collate = 'utf8_general_ci' character set = 'utf8'; grant all on cattle.* to 'cattle'@'%' identified by 'cattle'; grant all on cattle.* to 'cattle'@'localhost' identified by 'cattle'; flush privileges; show databases;" Copy the code
The following error occurs when you run the mysql container:
Solution: Turn off Linux Selinux
To view:Blog.csdn.net/lijiqidong/…
Create the Rancher container
-
Mysql machine IP: IP address of the machine where the mysql container is running
docker run -d--name rancher --link=mysqldb:db \ --restart=unless-stopped -p 8080:8080 -p 9345:9345 rancher/server:latest \ --db-host Db --db-port 3306 --db-user cattle --db-pass cattle --db-name cattle \ --advertise-address mysql machine IP addressCopy the code
Wait a few minutes, and when more than 100 tables have been created, you can open your browser and access the Rancher Web administration page. Query the number of tables in the cattle database. If 109 is displayed, the installation is complete
Query the number of tables in the cattle database docker exec -it mysqldb mysql -u"cattle" -h localhost -p"cattle" -e "use cattle; show tables;" |wc -l Copy the code
-
Visit http:// host IP address :8080 on the Rancher Web management page
Adding a Host (Node)
Infrastructure — Host — Add host (save) — Copy part 5 code and execute it on the Docker machine node that needs to be managed.
Access control
System Administration – Access Control – Enable access control
Refer to the link: www.cnblogs.com/elvi/p/8478…