CentOS环境安装Docker配置nginx+uwsgi+django

Docker安装

11[root@CentOS ~]# yum install docker 22[root@CentOS ~]# service docker start 33[root@CentOS ~]# chkconfig docker on

Docker安装Nginx

[root@CentOS ~]# docker pull nginx

Docker安装MySQL

[root@CentOS ~]# docker pull mysql

Docker安装Python

[root@CentOS ~]# docker pull python

Docker安装Redis

[root@CentOS ~]# docker pull redis

Docker安装MongoDB

[root@CentOS ~]# docker pull mongo

一、Docker环境安装CentOS 1、查找镜像源

1[root@CentOS ~]# docker search centos 2INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED 3docker.io docker.io/centos The official build of CentOS. 5070 [OK] 4docker.io docker.io/ansible/centos7-ansible Ansible on Centos7 119 [OK] 5docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x... 104 [OK] 6docker.io docker.io/consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 73 [OK] 7docker.io docker.io/imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 48 [OK] 8docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 45 9docker.io docker.io/tutum/centos Simple CentOS docker image with SSH access 43 10docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 38 [OK] 11docker.io docker.io/openshift/base-centos7 A Centos7 derived base image for Source-To... 37 12docker.io docker.io/centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relationa... 36 13docker.io docker.io/centos/python-35-centos7 Platform for building and running Python 3... 33 14docker.io docker.io/kinogmt/centos-ssh CentOS with SSH 25 [OK] 15docker.io docker.io/openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use... 20 16docker.io docker.io/centos/php-56-centos7 Platform for building and running PHP 5.6 ... 17 17docker.io docker.io/pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag nam... 10 18docker.io docker.io/openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for us... 6 19docker.io docker.io/openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x i... 4 20docker.io docker.io/darksheer/centos Base Centos Image -- Updated hourly 3 [OK] 21docker.io docker.io/pivotaldata/centos Base centos, freshened up a little with a ... 2 22docker.io docker.io/pivotaldata/centos-mingw Using the mingw toolchain to cross-compile... 2 23docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK] 24docker.io docker.io/pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated ... 1 25docker.io docker.io/pivotaldata/centos7-build CentosOS 7 image for GPDB compilation 0 26docker.io docker.io/pivotaldata/centos7-test CentosOS 7 image for GPDB testing 0 27docker.io docker.io/smartentry/centos centos with smartentry 0 [OK]

2、下载镜像

[root@CentOS ~]# docker pull docker.io/centos

3、查看已下载的镜像

1[root@CentOS ~]# docker image ls 2REPOSITORY TAG IMAGE ID CREATED SIZE 3docker.io/centos latest 1e1148e4cc2c 2 weeks ago 202 MB 4docker.io/nginx latest 568c4670fa80 3 weeks ago 109 MB 5docker.io/mongo latest 525bd2016729 5 weeks ago 383 MB 6docker.io/tomcat latest 78b258e36eed 5 weeks ago 463 MB 7docker.io/python latest 1e80caffd59e 5 weeks ago 923 MB 8docker.io/redis latest c188f257942c 5 weeks ago 94.9 MB 9docker.io/mysql latest f991c20cb508 5 weeks ago 486 MB 10docker.io/httpd latest 2a51bb06dc8b 5 weeks ago 132 MB 11docker.io/jenkins latest cd14cecfdb3a 5 months ago 696 MB 12 13 14[root@CentOS ~]# docker images 15REPOSITORY TAG IMAGE ID CREATED SIZE 16docker.io/centos latest 1e1148e4cc2c 2 weeks ago 202 MB 17docker.io/nginx latest 568c4670fa80 3 weeks ago 109 MB 18docker.io/mongo latest 525bd2016729 5 weeks ago 383 MB 19docker.io/tomcat latest 78b258e36eed 5 weeks ago 463 MB 20docker.io/python latest 1e80caffd59e 5 weeks ago 923 MB 21docker.io/redis latest c188f257942c 5 weeks ago 94.9 MB 22docker.io/mysql latest f991c20cb508 5 weeks ago 486 MB 23docker.io/httpd latest 2a51bb06dc8b 5 weeks ago 132 MB 24docker.io/jenkins latest cd14cecfdb3a 5 months ago 696 MB

4、启动镜像

1[root@CentOS ~]# docker run -itd centos /bin/bash 2WARNING: IPv4 forwarding is disabled. Networking will not work. 337c8eec506e8cb6867c2352dee59fc47649e903a469ab07bc561c8e3407dcd0a 4问题:创建容器的时候报错WARNING: IPv4 forwarding is disabled. Networking will not work. 5解决办法: 6打开文件:[root@CentOS ~]# vi /usr/lib/sysctl.d/00-system.conf 7添加如下代码:net.ipv4.ip_forward=1 8重启network服务:[root@CentOS ~]# systemctl restart network 9完成以后,删除错误的容器,再次创建新容器 10 11删除容器 12查看所有运行或者不运行容器 13[root@CentOS ~]# docker ps -a 14CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1537c8eec506e8 centos "/bin/bash" 7 minutes ago Up 7 minutes laughing_engelbart 16 17停止运行容器 18[root@CentOS ~]# docker stop 37c8eec506e8 19 20删除容器 21[root@CentOS ~]# docker rm 37c8eec506e8 22 23重新创建容器 24[root@CentOS ~]# docker run -itd -p 80:9000 --name centos docker.io/centos /bin/bash

5、查看容器

1[root@CentOS ~]# docker ps 2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3050e1835cbc8 docker.io/centos "/bin/bash" 51 seconds ago Up 50 seconds 0.0.0.0:80->9000/tcp centos

6、进入容器

1[root@CentOS ~]# docker exec -it 050e1835cbc8 /bin/bash 2[root@CentOS ~]# docker attach 050e1835cbc8 3[root@050e1835cbc8 /]#

7、通过配置文件修改docker容器端口映射

1[root@CentOS ~]# docker ps -a 2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3d916e60cd091 docker.io/centos "/bin/bash" 2 days ago Up 6 minutes 0.0.0.0:80->80/tcp centos 4 5[root@CentOS ~]# docker inspect d916e60cd091|grep Id 6 "Id": "d916e60cd09151085a9dc08377cb3e152b5dc86197b8591bbf5b0a129c840760", 7 8[root@CentOS ~]# docker stop centos 9 10[root@CentOS ~]# cd /var/lib/docker/containers/ 11 12停止 docker 引擎服务,systemctl stop docker 或者 service docker stop 13 14进入对应 Id 所在目录后,修改 /var/lib/docker/containers/{ 容器 ID+ 一些字符串}/hostconfig.json15"PortBindings":{"容器端口 /tcp":[{"HostIp":"","HostPort":"宿主机端口"}] 16例如: 17"PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"80"}],"8080/tcp":[{"HostIp":"","HostPort":"8080"}],"8888/tcp":[{"HostIp":"","HostPort":"8888"}]} 18 19同时修改同目录下的 config.v2.json20"ExposedPorts":{"容器端口 /tcp":{}} 21"Ports":{"容器端口 /tcp":[{"HostIp":"0.0.0.0","HostPort":"宿主机端口"}]} 22例如: 23"ExposedPorts":{"80/tcp":{},"8080/tcp":{},"8888/tcp":{}} 24"Ports":{"80/tcp":[{"HostIp":"0.0.0.0","HostPort":"80"}],"8080/tcp":[{"HostIp":"0.0.0.0","HostPort":"8080"}],"8888/tcp":[{"HostIp":"0.0.0.0","HostPort":"8888"}]} 25 26重启服务, 启动容器 (systemctl start docker/service docker start)

8、查看docker容器IP

1想看到docker容器的ip先安装net-tools 2[root@050e1835cbc8 ~]# yum install net-tools -y 3之后就可以用ifconfig查看 4[root@050e1835cbc8 ~]# ifconfig

二、CentOS环境安装Python3.7

1、安装编译相关工具

1[root@050e1835cbc8 /]# yum -y groupinstall "Development tools" 2[root@050e1835cbc8 /]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 3[root@050e1835cbc8 /]# yum install libffi-devel -y

2、下载安装包解压

1[root@050e1835cbc8 ~]# yum -y install wget 2[root@050e1835cbc8 ~]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz 3[root@050e1835cbc8 ~]# tar -xvJf Python-3.7.0.tar.xz

3、编译安装

1[root@050e1835cbc8 ~]# mkdir /usr/local/python3 #创建编译安装目录 2[root@050e1835cbc8 ~]# cd Python-3.7.0 3[root@050e1835cbc8 Python-3.7.0]# ./configure --prefix=/usr/local/python3 4[root@050e1835cbc8 Python-3.7.0]# make && make install

4、创建软连接

1[root@050e1835cbc8 ~]# ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3 2[root@050e1835cbc8 ~]# ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

5、验证是否成功

1[root@050e1835cbc8 ~]# python3 -V 2[root@050e1835cbc8 ~]# pip3 -V

三、CentOS环境安装Nginx

1、gcc 安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境。nginx也需要 gcc 环境。

[root@050e1835cbc8 ~]# yum install gcc-c++

2、pcre pcre-devel 安装 PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。

[root@050e1835cbc8 ~]# yum install -y pcre pcre-devel

3、zlib 安装 zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

[root@050e1835cbc8 ~]# yum install -y zlib zlib-devel

4、openssl openssl-devel安装 OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

[root@050e1835cbc8 ~]# yum install -y openssl openssl-devel

5、下载安装包解压

1[root@050e1835cbc8 ~]# wget https://nginx.org/download/nginx-1.14.2.tar.gz 2[root@050e1835cbc8 ~]# tar -zxvf nginx-1.14.2.tar.gz

6、编译安装

1[root@050e1835cbc8 ~]# cd nginx-1.14.2 2[root@050e1835cbc8 nginx-1.14.2]# ./configure 3* 4* 5Configuration summary 6 + using system PCRE library 7 + OpenSSL library is not used 8 + using system zlib library 9 10 nginx path prefix: "/usr/local/nginx" 11 nginx binary file: "/usr/local/nginx/sbin/nginx" 12 nginx modules path: "/usr/local/nginx/modules" 13 nginx configuration prefix: "/usr/local/nginx/conf" 14 nginx configuration file: "/usr/local/nginx/conf/nginx.conf" 15 nginx pid file: "/usr/local/nginx/logs/nginx.pid" 16 nginx error log file: "/usr/local/nginx/logs/error.log" 17 nginx http access log file: "/usr/local/nginx/logs/access.log" 18 nginx http client request body temporary files: "client_body_temp" 19 nginx http proxy temporary files: "proxy_temp" 20 nginx http fastcgi temporary files: "fastcgi_temp" 21 nginx http uwsgi temporary files: "uwsgi_temp" 22 nginx http scgi temporary files: "scgi_temp" 23 24[root@050e1835cbc8 nginx-1.14.2]# make 25[root@050e1835cbc8 nginx-1.14.2]# make install

7、查找安装路径

[root@050e1835cbc8 nginx-1.14.2]# whereis nginx

8、启动、停止nginx

1[root@050e1835cbc8 nginx-1.14.2]# cd /usr/local/nginx/sbin/ 2[root@050e1835cbc8 sbin]# ./nginx 3[root@050e1835cbc8 sbin]# ./nginx -s stop 4[root@050e1835cbc8 sbin]# ./nginx -s quit 5[root@050e1835cbc8 sbin]# ./nginx -s reload

9、查看nginx是否启动成功

1[root@050e1835cbc8 sbin]# curl localhost 2[root@050e1835cbc8 sbin]# ps -aux|grep nginx

10、修改nginx配置

1[root@050e1835cbc8 sbin]# vi /usr/local/nginx/conf/nginx.conf 2 3* 4 server { 5 listen 80;#修改端口9000 6 server_name localhost; 7 8 #charset koi8-r; 9 10 #access_log logs/host.access.log main; 11 12 location / { 13 root html; 14 index index.html index.htm; 15 } 16*

systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd –state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

四、CentOS环境通过Python3安装django和uwsgi以及配置

1[root@050e1835cbc8 ~]# pip3 install django 2* 3* 4You are using pip version 10.0.1, however version 18.1 is available. 5You should consider upgrading via the 'pip install --upgrade pip' command. 6安装提示时需要更新pip 7[root@050e1835cbc8 ~]# python3 -m pip install --upgrade pip 8[root@050e1835cbc8 ~]# pip3 install uwsgi 9创建软链接可以在终端使用uwsgi命令 10[root@050e1835cbc8 ~]# ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi 11 12进入/home/文件路径 13[root@050e1835cbc8 home]# pwd 14/home/ 15 16创建django项目 17[root@CentOS www]# python3 /usr/local/python3/bin/django-admin.py startproject ChinaDaas 18进入项目路径 19[root@CentOS www]# cd ChinaDaas/ 20启动项目测试django 21[root@CentOS ChinaDaas]# python3 manage.py runserver 22 修改settings.py文件ALLOWED_HOSTS = ['*'] 23 24 25uwsgi --ini uwsgi.ini # 启动uwsgi配置 26ps -ef |grep uwsgi 27uwsgi --stop uwsgi.pid # 关闭uwsgi 28pkill -f uwsgi -9 # 关闭uwsgi 29uwsgi --reload uwsgi.pid #重新加载配置

uwsgi.ini文件

1[uwsgi] 2 #请求方式与端口号 3 socket = :8080 4 #日志文件 5 daemonize = /usr/local/nginx/uwsgi_temp/uwsgi.log 6 pidfile = /usr/local/nginx/uwsgi_temp/uwsgi.pid 7 #允许主进程存在 8 master = true 9 #开启进程数 10 processes = 4 11 #开启线程数 12 threads =2 13 #当服务器退出时自动清理环境 14 vacuum = true

~
~

nginx.conf文件

1worker_processes 1; 2 3events { 4 worker_connections 1024; 5} 6 7http { 8 include mime.types; 9 default_type application/octet-stream; 10 sendfile on; 11 keepalive_timeout 65; 12 server { 13 listen 8080; 14 server_name localhost 192.168.100.100; 15 charset utf-8; 16 location / { 17 include /usr/local/nginx/conf/uwsgi_params; 18 uwsgi_pass 127.0.0.1:8000; 19 uwsgi_param UWSGI_SCRIPT ChinaDaas.wsgi; 20 uwsgi_param UWSGI_CHDIR /home/ChinaDaas; 21 } 22 location /templates/ { 23 alias /home/ChinaDaas/templates/; 24 } 25 } 26}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )