| 
       
	1.系统环境 
	CentOS 7 
	安装过更新 
	# yum upgrade 
	  
	2.安装docker见上一篇文章 
	# docker images 
	REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE 
	< none>              <none>              0ea0d582fd90        2 weeks ago         192.7 MB 
	< none>              <none>              aa822e26d727        2 weeks ago         195.7 MB 
	< none>              <none>              822a01ae9a15        2 weeks ago         108 MB 
	centos              centos6             b1bd49907d55        3 weeks ago         212.5 MB 
	centos              centos7             b157b77b1a65        3 weeks ago         243.7 MB 
	centos              latest              b157b77b1a65        3 weeks ago         243.7 MB 
	< none>              <none>              c5881f11ded9        9 weeks ago         172.1 MB 
	< none>              <none>              463ff6be4238        9 weeks ago         169.4 MB 
	< none>              <none>              3db9c44f4520        4 months ago        183 MB 
	  
	[root@CentOS ~]# docker ps -l 
	CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES 
	a8136ef7c817        centos:centos7      cat /etc/issue      About a minute ago   Exited (0) About a minute ago                       clever_kirch8 
	  
	[root@CentOS ~]# docker run -i -t centos /bin/bash 
	bash-4.2# 
	  
	# docker ps -l 
	CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES 
	1b60a96a84e8        centos:centos7      /bin/bash           7 seconds ago       Up 6 seconds 
	  
	装好软件之后 
	# docker commit 1b60a96a84e8 xiongli/mysql 
	  
	3.mysql下载 
	最新版: mysql-5.6.20.tar.gz 
	网站:http://dev.mysql.com/downloads/mysql/ 
	下载命令: 
	# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz 
	cmake 
	# wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz 
	  
	4.docker 安装 CentOS 镜像 
	# docker pull centos 
	  
	安装 mysql 
[root@CentOS ~]# docker run -i -t centos /bin/bash 
	bash-4.2# 
	因为只有一个窗口,运行起来输命令不方便,现在安装ssh,并且用其他主机通过ssh连接进来,安装,没有 docker commit 不可以关闭主docker 窗口,否则,安装全部要重新开始。 
	# yum install openssh 
	下面两个用不了,可以用命令启动 
	# systemctl start sshd.service 
	# systemctl enable sshd.service 
	  
	在这个命令下面安装,步骤如下: 
	# cd /root/ 
	# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz 
	# wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz 
	# yum upgrade 
	# yum install gcc gcc-c++ make autoconf bison ncurses-devel wget tar 
	# tar zxvf cmake-3.0.1.tar.gz 
	# cd cmake-3.0.1 
	# ./configure --prefix=/usr/local/cmake 
	# gmake 
	# make && make install 
	 
	# groupadd mysql 
	# useradd -s /sbin/nologin -g mysql mysql 
	 
	# mkdir -p /mysql /mysql/3306 /mysql/3307 
	# chown -R mysql:mysql /mysql 
	 
	# tar zxvf mysql-5.6.20.tar.gz 
	# cd mysql-5.6.20 
	# /usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/mysql -DMYSQL_TCP_PORT=3306 
	 
	# make && make install 
	# cp support-files/mysqld_multi.server /etc/init.d/mysqld 
	  
	环境变量 
	# vi /etc/profile 
	追加 
	# /usr/local/mysql/bin/mysql 
	export MYSQL_HOME=/usr/local/mysql 
	export PATH=${MYSQL_HOME}/bin:$PATH 
	  
	# source /etc/profile 
	  
	配置 my.cnf 
	# vi /etc/my.cnf 
	[mysqld_multi] 
	mysqld = /usr/local/mysql/bin/mysqld_safe 
	mysqladmin = /usr/local/mysql/bin/mysqladmin 
	user = root 
	#password = 
	 
	[mysqld1] 
	port            = 3306 
	socket          = /mysql/3306/mysql.sock 
	pid-file        = /mysql/3306/mysqld.pid 
	datadir         = /mysql/3306 
	back_log = 50 
	expire_logs_days = 15 
	character-set-server = utf8 
	log_bin_trust_function_creators = 1 
	binlog-ignore-db = mysql 
	binlog-ignore-db = test 
	binlog-ignore-db = information_schema 
	skip-name-resolve 
	external-locking = FALSE 
	skip-external-locking 
	max_connections = 10240 
	max_connect_errors = 3072 
	table_open_cache = 2048 
	max_allowed_packet = 16M 
	binlog_cache_size = 1M 
	max_heap_table_size = 64M 
	read_buffer_size = 2M 
	read_rnd_buffer_size = 16M 
	sort_buffer_size = 8M 
	join_buffer_size = 8M 
	thread_cache_size = 8 
	thread_concurrency = 8 
	query_cache_size = 64M 
	query_cache_limit = 4M 
	ft_min_word_len = 4 
	default-storage-engine = INNODB 
	thread_stack = 192K 
	transaction_isolation = REPEATABLE-READ 
	tmp_table_size = 64M 
	log-bin=mysql-bin 
	binlog_format=mixed 
	concurrent_insert = 2 
	max_binlog_cache_size = 8M 
	slow_query_log 
	long_query_time = 2 
	server-id = 1 
	key_buffer_size = 128M 
	bulk_insert_buffer_size = 64M 
	myisam_sort_buffer_size = 128M 
	myisam_max_sort_file_size = 10G 
	myisam_repair_threads = 1 
	myisam_recover 
	innodb_additional_mem_pool_size = 16M 
	innodb_buffer_pool_size = 8G 
	innodb_data_file_path = ibdata1:10M:autoextend 
	innodb_file_io_threads = 4 
	innodb_thread_concurrency = 16 
	innodb_flush_log_at_trx_commit = 2 
	innodb_log_buffer_size = 8M 
	innodb_log_file_size = 256M 
	innodb_log_files_in_group = 3 
	innodb_max_dirty_pages_pct = 90 
	innodb_lock_wait_timeout = 120 
	innodb_file_per_table = 1 
	 
	[mysqld2] 
	port            = 3307 
	socket          = /mysql/3307/mysql.sock 
	pid-file        = /mysql/3307/mysqld.pid 
	datadir         = /mysql/3307 
	back_log = 50 
	character-set-server = utf8 
	expire_logs_days = 15 
	binlog-ignore-db = mysql 
	binlog-ignore-db = test 
	binlog-ignore-db = information_schema 
	skip-name-resolve 
	external-locking = FALSE 
	skip-external-locking 
	max_connections = 10240 
	max_connect_errors = 3072 
	table_open_cache = 2048 
	max_allowed_packet = 16M 
	binlog_cache_size = 1M 
	max_heap_table_size = 64M 
	read_buffer_size = 2M 
	read_rnd_buffer_size = 16M 
	sort_buffer_size = 8M 
	join_buffer_size = 8M 
	thread_cache_size = 8 
	thread_concurrency = 8 
	query_cache_size = 64M 
	query_cache_limit = 4M 
	ft_min_word_len = 4 
	default-storage-engine = INNODB 
	thread_stack = 192K 
	transaction_isolation = REPEATABLE-READ 
	tmp_table_size = 64M 
	log-bin=mysql-bin 
	binlog_format=mixed 
	concurrent_insert = 2 
	max_binlog_cache_size = 8M 
	slow_query_log 
	long_query_time = 2 
	server-id = 1 
	key_buffer_size = 128M 
	bulk_insert_buffer_size = 64M 
	myisam_sort_buffer_size = 128M 
	myisam_max_sort_file_size = 1G 
	myisam_repair_threads = 1 
	myisam_recover 
	innodb_additional_mem_pool_size = 16M 
	innodb_buffer_pool_size = 1G 
	innodb_data_file_path = ibdata1:10M:autoextend 
	innodb_file_io_threads = 4 
	innodb_thread_concurrency = 16 
	innodb_flush_log_at_trx_commit = 2 
	innodb_log_buffer_size = 8M 
	innodb_log_file_size = 256M 
	innodb_log_files_in_group = 3 
	innodb_max_dirty_pages_pct = 90 
	innodb_lock_wait_timeout = 120 
	innodb_file_per_table = 1 
	innodb_flush_method = O_DIRECT 
	 
	[mysqldump] 
	quick 
	max_allowed_packet = 16M 
	 
	[mysql] 
	no-auto-rehash 
	 
	[myisamchk] 
	key_buffer_size = 512M 
	sort_buffer_size = 512M 
	read_buffer = 8M 
	write_buffer = 8M 
	 
	[mysqlhotcopy] 
	interactive-timeout 
	 
	[mysqld_safe] 
	open-files-limit = 8192 
	  
	初始化 
	# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3306 
	# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3307 
	  
	启动 
	启动命令 
	# mysql start 
	# /etc/init.d/mysqld start 1-2 
	  
	查询状态 
	# /etc/init.d/mysqld report 1 
	# /etc/init.d/mysqld report 2 
	  
	提交到 docker images 
	# docker commit 1b60a96a84e8 xiongli/mysql 
	注意:要退出安装的 docker 
	# docker run -i -t centos /bin/bash 
	# exit 
	然后通过 这个命令可以查看 镜像的id 
	# docker ps -a 
	CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES 
	1b60a96a84e8        centos:centos7      /bin/bash              3 hours ago         Exited (1) 9 minutes ago                       agitated_hoover0 
	  
	查看 commit 的镜像 
	# docker images 
	REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE 
	xiongli/mysql       latest              a05d5001d934        39 minutes ago      4.275 GB 
	  
	使用提交的镜像 
	# docker run -i -t xiongli/mysql /bin/bash 
	  
	5.docker 安装 ubuntu 
	# docker pull ubuntu 
	安装顺序和上面的过程一样,这里不再详细展开 
	  
	  
	6.docker pull安装mysql 
	# docker search mysql 
	找到所需要的 mysql 版本和镜像名,执行下面命令进行安装 
	# docker pull sawarame/mysql5.6.19 
	安装完成之后,启动 sawarame/mysql5.6.19 
	# docker images 
	  
      (责任编辑:IT) |