centos下docker的lnmp的环境,各部件独立容器

前端之家收集整理的这篇文章主要介绍了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,并关联MysqLPHP容器

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

<?PHP
PHPinfo();
?>

/web/docker/Nginx/www1/index.html

Nginx is working! <br />
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文件

点我查看

原文链接:https://www.f2er.com/centos/375968.html

猜你在找的CentOS相关文章