Skip to content

Commit

Permalink
updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
voocel committed Jul 30, 2019
1 parent bcbe594 commit 4481844
Show file tree
Hide file tree
Showing 31 changed files with 3,114 additions and 24 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,27 @@ docker_lnmp
### 创建镜像与安装
> 直接使用docker-compose一键制作镜像并启动容器
**版本一**

*该版本是通过拉取纯净的CentOS镜像,通过Dockerfile相关命令进行源码编译安装各个服务。所以该方式很方便定制自己需要的镜像,但是占用空间大且构建慢。*
**版本一(v1)**

```
git clone https://github.com/voocel/docker-lnmp.git
cd docker-lnmp
cd docker-lnmp/v1
docker-compose up -d
```

**版本二(推荐)**
*该版本是通过拉取纯净的CentOS镜像,通过Dockerfile相关命令进行源码编译安装各个服务。所以该方式很方便定制自己需要的镜像,但是占用空间大且构建慢。*


**当前版本(推荐)**
```
git clone https://github.com/voocel/docker-lnmp.git
cd docker-lnmp/v2
cd docker-lnmp
chmod 777 ./redis/redis.log
chmod -R 777 ./redis/data
docker-compose up -d
```
*站点根目录为 docker-lnmp/www*

*该版本是通过拉取官方已经制作好的各个服务的镜像,再通过Dockerfile相关命令根据自身需求做相应的调整。所以该方式构建迅速使用方便,因为是基于Alpine Linux所以占用空间很小。*

### 测试
Expand Down Expand Up @@ -150,18 +153,18 @@ RUN pecl install memcached-2.2.0 \
```
# 安装Redis和swoole扩展
RUN cd ~ \
&& wget https://github.com/phpredis/phpredis/archive/4.2.0.tar.gz \
&& tar -zxvf 4.2.0.tar.gz \
&& wget https://github.com/phpredis/phpredis/archive/5.0.2.tar.gz \
&& tar -zxvf 5.0.2.tar.gz \
&& mkdir -p /usr/src/php/ext \
&& mv phpredis-4.2.0 /usr/src/php/ext/redis \
&& mv phpredis-5.0.2 /usr/src/php/ext/redis \
&& docker-php-ext-install redis \
&& apk add libstdc++\
&& cd ~ \
&& wget https://github.com/swoole/swoole-src/archive/v4.2.12.tar.gz \
&& tar -zxvf v4.2.12.tar.gz \
&& wget https://github.com/swoole/swoole-src/archive/v4.4.2.tar.gz \
&& tar -zxvf v4.4.2.tar.gz \
&& mkdir -p /usr/src/php/ext \
&& mv swoole-src-4.2.12 /usr/src/php/ext/swoole \
&& mv swoole-src-4.4.2 /usr/src/php/ext/swoole \
&& docker-php-ext-install swoole \
```
*注:因为该镜像需要先安装swoole依赖的libstdc++,否则安装成功后无法正常加载swoole扩展*
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- "80:80"
- "443:443"
volumes:
- ./nginx/www:/usr/share/nginx/html
- ./www:/usr/share/nginx/html
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/cert:/etc/nginx/cert
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
Expand All @@ -23,7 +23,7 @@ services:
volumes:
- ./nginx/www:/var/www/html
- ./php/config/php.ini:/usr/local/etc/php/php.ini
- ./php/config/php-fpm.conf:usr/local/etc/php-fpm.conf
- ./php/config/php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./php/config/php-fpm.d:/usr/local/etc/php-fpm.d
networks:
- frontend
Expand Down
4 changes: 2 additions & 2 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
# return 501;
# }

ssl_certificate /etc/nginx/cert/*.pem;
ssl_certificate_key /etc/nginx/cert/*.key;
# ssl_certificate /etc/nginx/cert/*.pem;
# ssl_certificate_key /etc/nginx/cert/*.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
Expand Down
18 changes: 10 additions & 8 deletions php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM daocloud.io/library/php:7.2-fpm-alpine
FROM daocloud.io/library/php:7.3-fpm-alpine

COPY config/php.ini /usr/local/etc/php

Expand All @@ -11,21 +11,23 @@ COPY config/php.ini /usr/local/etc/php
# && make \
# && make install \

ENV PHPREDIS_VERSION 4.2.0
ENV PHPREDIS_VERSION 5.0.2
ENV SWOOLE_VERSION 4.4.2

RUN cd ~ \
&& wget https://github.com/phpredis/phpredis/archive/4.2.0.tar.gz \
&& tar -zxvf 4.2.0.tar.gz \
&& useradd --create-home --no-log-init --shell /bin/bash git \
&& wget https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
&& tar -zxvf $PHPREDIS_VERSION.tar.gz \
&& mkdir -p /usr/src/php/ext \
&& mv phpredis-4.2.0 /usr/src/php/ext/redis \
&& mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
&& docker-php-ext-install redis \

&& apk add libstdc++ libpng-dev \
&& cd ~ \
&& wget https://github.com/swoole/swoole-src/archive/v4.2.12.tar.gz \
&& tar -zxvf v4.2.12.tar.gz \
&& wget https://github.com/swoole/swoole-src/archive/v$SWOOLE_VERSION.tar.gz \
&& tar -zxvf v$SWOOLE_VERSION.tar.gz \
&& mkdir -p /usr/src/php/ext \
&& mv swoole-src-4.2.12 /usr/src/php/ext/swoole \
&& mv swoole-src-$SWOOLE_VERSION /usr/src/php/ext/swoole \
&& docker-php-ext-install swoole \

&& docker-php-ext-install pdo_mysql mysqli pcntl gd\
Expand Down
78 changes: 78 additions & 0 deletions v1/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: '3'
# 定义四个服务nginx,php,mysql,redis
services:
nginx:
# 依赖php服务,意味着在启动nginx之前先启动php
depends_on:
- php
# nginx镜像的路径
build: ./nginx
volumes:
- ./nginx/www:/usr/share/nginx/html
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/ssl/:/etc/nginx/ssl/
- ./nginx/log/error.log:/var/log/nginx/error.log
# nginx意外退出时自动重启
restart: always

# 映射80和443端口
ports:
- "80:80"
- "443:443"
networks:
- frontend

# 容器名称
container_name: nginx

php:
depends_on:
- mysql
- redis
build: ./php
ports:
- "9000"
networks:
- frontend
- backend
volumes:
- ./php/php-fpm.conf:/usr/local/php/etc/php-fpm.conf
- ./php/www.conf:/usr/local/php/etc/php-fpm.d/www.conf
- ./php/php.ini:/usr/local/php/etc/php.ini
- ./php/log/php-fpm.log:/usr/local/php/var/log/php-fpm.log
- ./nginx/www:/usr/share/nginx/html
restart: always
container_name: php

# MySQL
mysql:
image: hub.c.163.com/library/mysql:latest
ports:
- "127.0.0.1:3306:3306"
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/my.cnf
environment:
MYSQL_ROOT_PASSWORD: 123456
networks:
- backend
restart: always
container_name: mysql

# REDIS
redis:
build: ./redis
ports:
- "127.0.0.1:6379:6379"
networks:
- backend
volumes:
- ./redis/redis.conf:/usr/local/redis/redis.conf
- ./redis/redis.log:/usr/local/redis/redis.log
restart: always
container_name: redis

networks:
frontend:
backend:
2 changes: 2 additions & 0 deletions v1/mysql/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
42 changes: 42 additions & 0 deletions v1/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default-storage-engine=INNODB

character-set-server=utf8

collation-server=utf8_general_ci


[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]

default-character-set=utf8

77 changes: 77 additions & 0 deletions v1/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 拉取 CentOS
FROM hub.c.163.com/library/centos:latest

# 维护者
MAINTAINER voocel <voocel@gmail.com>

# 设置 openssl 和 nginx 版本
ENV NGINX_VERSION 1.17.2

# 安装依赖
RUN set -x \
&& yum update -y \
&& yum install -y wget gcc gcc-c++ make automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel perl file tar bzip2-devel bzip2 openssl openssl-devel zlib zlib-devel \

# 创建下载目录
&& mkdir ~/download \

# 下载 openssl
&& cd ~/download \

# 下载 nginx
&& wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz \
&& tar -zxvf nginx-$NGINX_VERSION.tar.gz \
&& cd nginx-$NGINX_VERSION \
&& mkdir -p /var/cache/nginx \
&& groupadd nginx \
&& useradd -r -g nginx nginx \
&& ./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
&& make \
&& make install \
&& rm -rf ~/download \
&& yum clean all

# 若要使用https,请将以下三个注释去掉,并在ssl文件夹中添加你自己申请的两个证书文件
# && mkdir -p /etc/nginx/cert
#COPY ssl/nginx.pem /etc/nginx/cert/nginx.pem
#COPY ssl/nginx.key /etc/nginx/cert/nginx.key

CMD ["/usr/sbin/nginx","-g","daemon off;"]

EXPOSE 80 443
47 changes: 47 additions & 0 deletions v1/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
server {
listen 80;
server_name localhost;
# 全站使用https则开启下面这个注释
# rewrite ^ https://$http_host$request_uri? permanent;

#charset koi8-r;

#access_log logs/host.access.log main;
root /usr/share/nginx/html;
location / {

index index.html index.htm index.php;
}

#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 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$ {

fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
21 changes: 21 additions & 0 deletions v1/nginx/conf.d/frps.proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
upstream frps{
server 10.163.56.122:8080;
keepalive 64;
}

server {
listen 80;
server_name *.yahui.wang;
# access_log /data/logs/frpc.proxy.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://frps;
client_max_body_size 1000m;

}

}
Empty file added v1/nginx/log/error.log
Empty file.
Loading

0 comments on commit 4481844

Please sign in to comment.