Docker构建其它组件

构建mysql

  • 运行centos7容器 docker run --privileged -dti --name=centos-container centos:7 /usr/sbin/init
  • 查询centos7容器 docker ps -a
  • 进入centos7容器 docker exec -it CONTAINER ID /bin/bash
  • 安装mysql数据库 yum install -y mariadb-server
  • 启动数据库 systemctl start mariadb
  • 修改用户状态
mysql
mysql -u root
use mysql;
select * from user;
delete from user where Host <> '127.0.0.1';
update user set Host = '%', Password=password('zmkj1123');
flush privileges;
  • 退出系统创建镜像 docker commit -m "centos add mysql" -a "M.Zeng" ae3c246eceaa zeng/mysql:5.5
  • 启动mysql容器 docker run -dti -p 3306:3306 --name=mysql-container --privileged --net=host zeng/mysql:5.5 /usr/sbin/init

构建redis

  • 运行redis容器 docker run -d -p 6379:6379 --name=redis-container redis
  • 优化:使用自定义redis配置文件 https://www.cnblogs.com/cgpei/p/7151612.html
  • docker run -d -p 6379:6379 --name=redis-container -v /etc/redis.conf:/etc/redis/redis.conf redis redis-server /etc/redis/redis.conf

-v $PWD/data:/data redis:3.2 redis-server /etc/redis/redis.conf --appendonly yes```

######## NETWORK ########
# bind 192.168.1.100 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

######## GENERAL ########
daemonize yes
supervised no
pidfile /var/run/redis.pid
loglevel notice
logfile ""
databases 16

################################ SNAPSHOTTING  #################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
# 工作目录,数据库镜像备份的文件放置的路径。注意这里必须制定一个目录而不是文件
dir ./

######## REPLICATION ########
slave-serve-stale-data yes
slaveread-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

######## SECURITY ########
requirepass zm#1123

######## APPEND ONLY MODE ########
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

######## LUASCRIPTING ########
lua-time-limit 5000

######## SLOW LOG ########
slowlog-log-slower-than 10000
slowlog-max-len 128

######## LATENCY MONITOR ########
latency-monitor-threshold 0

######## EVENT NOTIFICATION ########
notify-keyspace-events ""

######## ADVANCED CONFIG ########
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

构建rabbitmq

docker run -dti --name rabbitmq-container -p 4369:4369 -p 5671:5671 -p 5672:5672 -p  15671:15671 -p 15672:15672 -p 25672:25672  -e RABBITMQ_DEFAULT_USER=bms -e RABBITMQ_DEFAULT_PASS='zmkj1123' rabbitmq:3-management

构建nginx

docker run -d -p 80:80 --name=nginx-container -v /Data/html:/Data/html -v /Data/logs:/Data/logs -v /etc/nginx.conf:/etc/nginx/nginx.conf nginx
  • nginx.conf
worker_processes auto;
pid /Data/logs/nginx.pid;
events {
	worker_connections  1024;
	use epoll;
}
##定义nginx访问日志状态,连接参数,超时时间等基本调优###
http {
	include       mime.types;
    default_type  application/octet-stream;
    log_format  bms  '$remote_addr - $remote_user [$time_local] "$request"     '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /Data/logs/access.log bms;
    server_tokens off;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 60;
    send_timeout 60;
    client_header_timeout 30;
    client_body_timeout 60;

##访问url下gateway跳转到后端两台服务器9100端口##
    upstream gw {
         server 118.31.114.152:9100 weight=1;
    }

##监听80端口,ip解析域名,/gateway跳转到后端9100端口####
	server {
         listen    80;
         charset utf8;
		location ^~/gateway {
	         proxy_pass http://gw;
	         proxy_set_header Host      $host;
	         proxy_set_header X-Real-IP $remote_addr;
	         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	         proxy_next_upstream http_404 http_403 http_502 http_504 error timeout invalid_header;
		}
##定义网页发布路径为/opt/html/###
		location / {
			root   /Data/html;
			index  index.html index.htm;
		}
	}
}
原文地址:https://www.cnblogs.com/ggza/p/9448988.html