centos下docker的lnmp的环境,各部件独立容器
来源:SegmentFault
时间:2023-02-16 19:20:32 345浏览 收藏
本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《centos下docker的lnmp的环境,各部件独立容器》对你有很大帮助!欢迎收藏,分享给更多的需要的朋友学习~
docker安装
卸载
yum remove docker docker-common docker-selinux docker-engine
安装docker需要环境
yum install -y yum-utils device-mapper-persistent-data lvm2
配置安装reps
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo #更新yum包 yum makecache fast
安装docker 并启动
yum install docker-ce systemctl start docker
docker mysql 容器
安装mysql
mkdir -p /web/docker/mysql/logs mkdir -p /web/docker/mysql/pid mkdir -p /web/docker/mysql/data mkdir -p /web/docker/mysql/conf docker pull mysql:5.6.37
宿主机上/web/docker/mysql/conf/my.cnf 配置文件
[mysqld] slow_query_log = ON slow_launch_time=5 #pid-file = /web/docker/mysql/pid/mysqld.pid #socket = /web/docker/mysql/pid/mysqld.sock datadir = /web/docker/mysql/data log-error = /web/docker/mysql/logs/error.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
启动并自定义配置文件和数据目录
docker run -p 3306:3306 --name mysql-server -v /web/docker/mysql/conf:/etc/mysql/mysql.conf.d -v /web/docker/mysql:/web/docker/mysql -e MYSQL_ROOT_PASSWORD=123345 -d mysql:5.6.37
注意这里的--name mysql-server 后续有用,因为data是宿主机上,所以下次可以省略-e MYSQL_ROOT_PASSWORD=123345
docker php 容器
安装php
docker pull php:5.6.31-fpm
启动php-fpm
docker run --name php-fpm-1 --rm -p 9000:9000 -v /web/docker/nginx/www1:/var/www/html -d php:5.6.31-fpm
安装iconv、mcrypt、gd和pdo_mysql扩展
docker exec -it container_id /bin/bash apt-get update apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12-dev docker-php-ext-install -j$(nproc) iconv mcrypt docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ docker-php-ext-install -j$(nproc) gd exit
container_id 是你php-fpm启动后的容器id
安装redis、xdebug、memcache扩展
pecl install redis-3.1.3 pecl install xdebug-2.5.5 docker-php-ext-enable redis xdebug apt-get install -y libmemcached-dev zlib1g-dev pecl install memcached-2.2.0 docker-php-ext-enable memcached
停止和重启php-fpm重启
docker stop container_id docker start container_id
注意这里的/var/www/html是php-fpm的读取源码默认位置,请勿修改后续nginx里有配置相关对应
docker nginx 容器
安装nginx
docker pull nginx:1.12.1
启动nginx,并关联mysql和php容器
mkdir -p /web/docker/nginx/logs mkdir -p /web/docker/nginx/pid mkdir -p /web/docker/nginx/www1 mkdir -p /web/docker/nginx/conf docker run --name nginx-server-1 --link php-fpm-1:php-fpm --link mysql-server:mysql-server -v /web/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /web/docker/nginx:/web/docker/nginx -p 80:80 -d nginx:1.12.1
注意这里的/etc/nginx/nginx.conf是nginx的读取源码默认配置文件
/web/docker/nginx/www1/index.php
/web/docker/nginx/www1/index.html
nginx is working!
create by qklin(object); wechat: qklandy!
/web/docker/nginx/conf/nginx.conf 配置
user nginx; worker_processes 2; #error_log /var/log/nginx/error.log warn; #pid /var/run/nginx.pid; error_log /web/docker/nginx/logs/error.log warn; pid /web/docker/nginx/pid/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include /etc/nginx/mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; 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; include /web/docker/nginx/conf/vhost/*.conf; }
vhost.example.conf
server { listen 80; server_name localhost; root /web/docker/nginx/www1; location / { index index.html index.htm index.php; } # limit_conn crawler 20; location ~ ^.+\.php$ { fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include /web/docker/nginx/conf/fastcgi.conf; fastcgi_pass php-fpm:9000; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } }
fastcgi.conf
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #/var/www/html/ 为php-fpm容器里源码存放的路径,这个php-fpm能解析执行php文件的关键 fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; try_files $fastcgi_script_name =404;
测试nginx
curl http://localhost/ curl http://localhost/index.php
docker redis 容器
安装redis
docker pull redis:4.0.1
启动redis
docker run -d -p 6379:6379 -v /web/docker/redis:/web/docker/redis --name redis-server-1 redis:4.0.1 redis-server /web/docker/redis/conf/redis1.conf
/web/docker/redis/data/redis1 redis数据库文件夹(保存rdb和aof)
/web/docker/redis/conf/redis.conf
bind 127.0.0.1 protected-mode yes tcp-backlog 511 timeout 0 tcp-keepalive 300 #daemonize yes # supervision tree. Options: # supervised no - no supervision interaction # supervised upstart - signal upstart by putting Redis into SIGSTOP mode # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET # supervised auto - detect upstart or systemd method based on # UPSTART_JOB or NOTIFY_SOCKET environment variables # Note: these supervision methods only signal "process is ready." # They do not enable continuous liveness pings back to your supervisor. supervised no #pidfile /var/run/redis_6379.pid #loglevel notice #logfile "/web/docker/redis/logs/redis-server.log" 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 dir /web/docker/redis/data/redis1 slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no appendonly yes 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 no 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 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
redis4.0.1 官方源码包里的redis.conf文件
以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于数据库的相关知识,也可关注golang学习网公众号。
声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
499 收藏
-
160 收藏
-
105 收藏
-
244 收藏
-
235 收藏
最新阅读
更多>
-
120 收藏
-
393 收藏
-
482 收藏
-
481 收藏
-
482 收藏
-
107 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习
评论列表
-
- 动人的吐司
- 很详细,码住,感谢作者大大的这篇文章,我会继续支持!
- 2023-03-25 11:28:05
-
- 美好的山水
- 这篇文章真及时,很详细,太给力了,码起来,关注老哥了!希望老哥能多写数据库相关的文章。
- 2023-03-16 19:52:41
-
- 哭泣的小蚂蚁
- 受益颇多,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,帮助很大,总算是懂了,感谢博主分享博文!
- 2023-03-13 04:17:49
-
- 激动的钢笔
- 好细啊,码住,感谢博主的这篇技术文章,我会继续支持!
- 2023-03-02 21:51:07
-
- 威武的鸵鸟
- 这篇技术贴真是及时雨啊,太详细了,太给力了,已加入收藏夹了,关注师傅了!希望师傅能多写数据库相关的文章。
- 2023-02-24 08:13:32
-
- 香蕉红酒
- 这篇文章内容出现的刚刚好,作者加油!
- 2023-02-22 04:17:41
-
- 疯狂的树叶
- 很有用,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,看完之后很有帮助,总算是懂了,感谢作者大大分享技术贴!
- 2023-02-20 21:27:17