Docker部署常用服务
1、docker部署mysql
1.1查找mysql镜像
docker serach mysql
1.2拉取镜像
docker pull mysql:5.7
1.3创建用于挂载的数据卷
mkdir -p /data/mysql/{conf,data,logs}
1.4准备配置文件
vi /data/mysql/conf/my.cnf
[mysql]
default-character-set=utf8mb4
[mysqld]
user=mysql
port=3306
collation_server=utf8mb4_general_ci
character-set-server=utf8mb4
1.5创建mysql容器
(注意,要先数据卷的mysql路径下运行,这里是/data/mysql)
cd /data/mysql
docker run -id \
--privileged=true \
-p 3306:3306 \
--name mysql01 \
-v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7
2、docker部署redis
2.1搜索镜像
docker search redis
2.2拉取镜像
docker pull redis
2.3创建挂载的数据卷
mkdir -p /data/redis/{conf,data,logs}
2.4准备配置文件
vi /data/redis/conf/redis.conf
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
#requirepass foobared
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
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
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
以上配置可以做出相应调整,例如:
bind 127.0.0.1
#当你需要远程连接时需要注释掉bind 127.0.0.1允许外地连接
daemonize no
#将daemonize yes注释起来或者改成daemonize no设置,因为该配置和docker run中-d参数冲突,会导致容器一直启动失败
appendonly yes
#开启redis数据持久化(可选)
#requirepass foobared
#配置连接密码格式为“requirepass 密码”
2.5创建容器
注意,要先数据卷的redis路径下运行,这里是/data/redis
cd /data/redis
docker run -id \
--privileged=true \
-p 6379:6379 \
--name redis01 \
-v $PWD/conf/redis.conf:/etc/redis/redis.conf \
-v $PWD/logs:/var/log \
-v $PWD/data:/data \
redis:latest \
redis-server /etc/redis/redis.conf
注意:最后跟的是redis容器内的配置文件,而不是宿主的。
3、docker部署nginx
3.1搜索镜像
docker search nginx
3.2拉取镜像
docker pull nginx
3.3创建挂载的数据卷
mkdir -p /data/nginx/{html,conf,logs}
3.4准备配置文件
3.4.1准备主配置文件
cat >/data/nginx/conf/nginx.conf<<'EOF'
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
EOF
3.4.2准备需要外部引用的配置文件
mkdir -p /data/nginx/conf/conf.d
cat >/data/nginx/conf/conf.d/default.conf<<'EOF'
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
EOF
3.5创建容器
注意,要先切换数据卷的nginx路径下运行,这里是/data/nginx
cd /data/nginx
docker run -id \
--privileged=true \
-p 80:80 \
--name nginx01 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/conf/conf.d:/etc/nginx/conf.d \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx:latest
注:由于挂载的根目录默认是空的,所以缺少50x.html和index.html,可看情况添加,以下给出默认文件内容:
cat >/data/nginx/html/50x.html<<'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>Sorry, the page you are looking for is currently unavailable.<br/>
Please try again later.</p>
<p>If you are the system administrator of this resource then you should check
the error log for details.</p>
<p><em>Faithfully yours, nginx.</em></p>
</body>
</html>
EOF
cat >/data/nginx/html/index.html<<'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
EOF
4、docker部署nacos
1.1 搜索镜像
docker pull nacos/nacos-server:v2.2.3
1.2 导入数据到MySQL
数据可以从github上下载同版本nacos之后解压即可看到SQL:
create database if not exists `nacos_config` character set utf8;
mysql -uroot -p -D nacos_config < nacos-db.sql
创建日志挂载路径:
mkdir -p /data/nacos/logs
创建容器:
cd /data/nacos
docker run -d --name minghu_nacos -p 8848:8848 -p 9848:9848 \
-e MODE=standalone \
-e JVM_XMS=512m \
-e JVM_XMX=512m \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=172.17.0.2 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
nacos/nacos-server:v2.2.3
# 注意以上连接的数据库信息要修改,ip改成mysql主机IP,如果是容器可以使用docker inspect查看
启动之后为了安全要打开鉴权,进入容器内部,该容器带有vi编辑器,可以打开/home/nacos/conf/application.properties配置文件后清空,把我准备的配置文件刷进去即可。
标签:常用,部署,redis,nginx,conf,mysql,docker,data From: https://www.cnblogs.com/luguojie/p/18590947