docker 安装 mysql
2014-08-26 14:02:41
熊立
  • 访问次数: 10
  • 注册日期: 2014-08-25
  • 最后登录: 2015-09-11

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



熊立 最后编辑, 2014-08-27 10:59:41
沙发
2014-09-23 18:18:14
Tom
  • 访问次数: 4
  • 注册日期: 2014-09-23
  • 最后登录: 2014-09-24

楼主啊,你那个sshd服务是拿什么命令启动的啊?????service 没有,安装也不行;systemctl也没有;/etc/rc.d/init.d/下面什么都没有

板凳
2014-10-22 10:39:58
熊立
  • 访问次数: 10
  • 注册日期: 2014-08-25
  • 最后登录: 2015-09-11

哦 是这样的  你做一个脚本   比如这个   当然 这个 xiongli/mysql 是可以下载的   # docker pull xiongli/mysql

这个机器 是 做监控的,好些cacti 是采集不到数据,所以没有传到docker上面



$ cat /opt/bootstrap.sh  

#!/bin/bash  
# author: xiongli  
# Email:   xionglihdfs@163.com  

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
export PATH  

echo "welcome to xiongli/cacti_nagios"  
echo ""  

echo "the system is Ubuntu 14.04.1 LTS"  

echo "ssh info: "  
echo "the ssh connect username is admin."  
echo "the password of admin is admin."  
echo "the admin has sudo su privileges, so it is super admin."  
echo ""  

echo "mysql info: "  
echo "the mysql user is 'root' and 'cacti'"  
echo "their password is 'xiongli', but user cacti has all privileges on cacti.* to cacti@'localhost' an cacti@'127.0.0.1'."  
echo ""  

echo "cacti web info: "  
echo "the username of cacti web is 'admin'."  
echo "the password of admin is 'xiongli'."  
echo "the host template of general linux is 'General Linux'."  
echo ""  

echo "nagios web info: "  
echo "the username of cacti web is 'admin'."  
echo "the password of admin is 'xiongli'."  

echo ""  
echo "the start ssh command is 'docker run -d -p 1022:22 --name cacti xiongli/cacti_nagios /opt/bootstrap.sh'."  
echo "the start ssh + apache + cacti + nagios command is 'docker run -d -p 1022:22 -p3306:3306 -p 80:80 --name cacti xiongli/cacti_nagios /opt/bootstrap.sh'."  
echo "and so on."  
echo ""  

# start ssh  
/etc/init.d/ssh start  

# lnmp start  
/etc/init.d/mysql start  
/etc/init.d/apache2 start  

# snmpd start  
/etc/init.d/snmpd start  

# nagios start  
/etc/init.d/nagios start  

sleep 99999999999999999999999999999999999999999999999999999  
sleep 99999999999999999999999999999999999999999999999999999  
sleep 99999999999999999999999999999999999999999999999999999 

启动的话很简单啦

docker cacti + nagios start:# docker run -d -p 1025:22 -p 80:80 -p 3306:3306 --name cacti_nagios_1 xiongli/cacti_nagios /opt/bootstrap.sh
#3
2015-05-19 18:23:07
熊立
  • 访问次数: 10
  • 注册日期: 2014-08-25
  • 最后登录: 2015-09-11

对了 你如果是用的 Centos 7版本的话,安装软件会提示少个s y s t e mctl类似的软件,还有s y s t e md之类的,但是怎么也装不上去,所以玩centos7 的可要注意下,尽量用  Ubuntu 来入门,因为他还是选择 service 来管理服务项。要不就把centos7降级成centos6。

#4
2015-05-26 13:32:23
开源春哥
  • 访问次数: 28
  • 注册日期: 2014-06-17
  • 最后登录: 2017-05-17
赞!
1/1