摘要:安装卸载安装需要环境配置安装更新包安装并启动容器安装宿主机上配置文件启动并自定义配置文件和数据目录注意这里的后续有用,因为是宿主机上,所以下次可以省略容器安装启动
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 dockerdocker 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
docker php 容器 安装php注意这里的--name mysql-server 后续有用,因为data是宿主机上,所以下次可以省略-e MYSQL_ROOT_PASSWORD=123345
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
安装redis、xdebug、memcache扩展container_id 是你php-fpm启动后的容器id
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
docker nginx 容器 安装nginx注意这里的/var/www/html是php-fpm的读取源码默认位置,请勿修改后续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
/web/docker/nginx/www1/index.php /web/docker/nginx/www1/index.html注意这里的/etc/nginx/nginx.conf是nginx的读取源码默认配置文件
nginx is working!/web/docker/nginx/conf/nginx.conf 配置
create by qklin(object); wechat: qklandy!
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.phpdocker 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/conf/redis.conf/web/docker/redis/data/redis1 redis数据库文件夹(保存rdb和aof)
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 yesredis4.0.1 官方源码包里的redis.conf文件
点我查看
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/25816.html
摘要:安装卸载安装需要环境配置安装更新包安装并启动容器安装宿主机上配置文件启动并自定义配置文件和数据目录注意这里的后续有用,因为是宿主机上,所以下次可以省略容器安装启动 docker安装 卸载 yum remove docker docker-common docker-selinux docker-engine 安装docker需要环境 yum install -y yum-utils d...
摘要:安装卸载安装需要环境配置安装更新包安装并启动容器安装宿主机上配置文件启动并自定义配置文件和数据目录注意这里的后续有用,因为是宿主机上,所以下次可以省略容器安装启动 docker安装 卸载 yum remove docker docker-common docker-selinux docker-engine 安装docker需要环境 yum install -y yum-utils d...
摘要:如果不用我们可能将上述讲的命令每搭建一次就需要执行一遍,有没有能统一管理的有,就是在环境搭建中的作用快速创建镜像,快速创建并运行容器,实现统一管理。 前言 初学者在dcoker学习过程中,可能不太清楚docker中那么多的命令,参数,工具在lnmp环境搭建中起了什么作用,下面跟着我来熟悉一下。(本文面向的是不怎么熟悉linux的:phper) 镜像,容器,仓库 镜像:Docker 镜像...
摘要:为了能只使用一个文件就能快速部署环境,我们把及环境的相关配置保存到阿里云的代码托管,然后使用阿里云的镜像仓库从拉取自动构建镜像。编写以上在阿里云创建的镜像到本地,在此项目中创建然后在目录分别创建目录,用于存放它们各自及配置文件。 Docker基于LXC实现了把软件封装到一个完整的文件系统,可以在docker容器中运行所需的一切代码,运行环境,系统工具和系统库。由于docker使用独立于...
阅读 988·2023-04-25 22:27
阅读 852·2021-11-22 14:56
阅读 941·2021-11-11 16:54
阅读 1651·2019-08-30 15:54
阅读 3481·2019-08-30 13:20
阅读 1195·2019-08-30 10:55
阅读 2058·2019-08-26 13:34
阅读 3265·2019-08-26 11:53