运维

yum源配置

DNS配置

防火墙配置

uwsgi

nginx

  1.tengine(淘宝版nginx)编译安装

  2、nginx负载均衡

  3.Nginx反向代理功能

  4.niginxs大全

docker

mysql(linux部署)

redis持久化、主从复制、哨兵集群

项目部署

  项目迁移

  前后端分离项目部署(uwsgi+nginx+supervisor+nginx)

supervisor的安装和使用

一、yum源配置(阿里)

1 备份下原来的yum源

cd /etc/yum.repos.d/

mv CentOS-Base.repo CentOS-Base.repo_bak

2 获取阿里云yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3 清除缓存

yum clean all

4 生成缓存

yum makecache

二、DNS配置

DNS解析流程:
1.优先查找本地dns缓存
2.查找本地/etc/hosts文件,是否有强制解析
3.如果没有去/etc/resolv.conf指定的dns服务器中查找记录(需联网
4.在dns服务器中找到解析记录后,在本地dns中添加缓存
5.完成一次dns解析

三、防火墙配置

 centos7(centos6的服务管理模块是service)

iptables -F 临时关闭防火墙
systemctl stop firewalld 关闭防火墙服务
systemctl disable firewalld禁止防火墙自启

centos6的服务管理模块是service

即时生效,重启后失效
开启:service iptables start
关闭:service iptables stop

四、nginx

1.tengine(淘宝版nginx)编译安装

#1.下载源码包
wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
#2.卸载yum安装的nginx
yum remove nginx -y
#3.安装环境依赖包
yum install gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y
#4.解压源码包
#5.源码编译安装三部曲
./configure  --prefix=/opt/tnginx220 #路径为安装到的路径
#step2 和 3:
make&&make install

2、nginx负载均衡

#1.环境准备:三台服务器,均安装好nginx,两台资源服务器对应不同的index页面
#代理服务器编辑nginx.conf下http选项
upstream myserver{
server 192.168.11.229;
server 192.168.11.136; 反向代理服务器
}
#2.配置代理服务器,修改nginx配置文件。登录--》安装nginx--》conf配置
#server中配置location:#proxy_pass  http://自定义myserver 代替root和HTML两个参数
upstream s17server {
server 192.168.11.229;
server 192.168.11.176;
}

        #转发请求给负载均衡池
        location / {
            proxy_pass   http://s17server;
        }
#语法检测及重启
#3.此时访问代理服务器,默认轮询方式访问资源服务器
#upstream 每个server 加权轮询:weight=8,weight=2#                    ip-hash;不能与weight共用11:40
#​                    url_hash;least_conn两个参数
#调度算法      概述
#轮询        按时间顺序逐一分配到不同的后端服务器(默认)
#weight       加权轮询,weight值越大,分配到的访问几率越高
        upstream s17server {
    server 192.168.11.229 weight=8;
    server 192.168.11.176 weight=2;
    }
#ip_hash      每个请求按访问IP的hash结果分配,这样来自同一IP的固定访问一个后端服务器
#url_hash      按照访问URL的hash结果来分配请求,是每个URL定向到同一个后端服务器
#least_conn    最少链接数,那个机器链接数少就分发

3.Nginx反向代理功能

nginx实现负载均衡的组件

ngx_http_proxy_module    proxy代理模块,用于把请求抛给服务器节点或者upstream服务器池

机器准备,两台服务器

master  192.168.11.63  主负载
slave   192.168.11.64  web1

反向代理配置文件nginx.conf

worker_processes  1;
error_log  logs/error.log;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    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  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  192.168.11.63;
        location / {
        proxy_pass  http://192.168.11.64;
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

此时访问master的服务器192.168.11.63:80地址,已经会将请求转发给slave的80端口

除了页面效果的展示以外,还可以通过log(access.log)查看代理效果

63端日志

64端日志

更多详情见:https://www.cnblogs.com/lvxw/articles/10980385.html

五、docker

1.docker基本概念和安装

#镜像  ,理解为系统盘dvd镜像 ,轻量级的镜像文件          class  
        把运行路飞学诚的应用程序,打包成一个docker镜像 
#仓库,存储docker镜像的 
#容器 ,是基于镜像运行出的,容器实例              

#1.安装docker,由于网速问题,选择阿里云的yum源下载 
yum install docker -y 
#2.启动docker
systemctl start docker
#3.docker加速器,加速下载
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
#会生成一个docker配置文件,路径是/etc/docker/daemon.json
#4.配置了加速器,需要重启docker
systemctl restart docker 

2.docker基础命令

docker run  镜像id    #运行出容器
docker pull  镜像名   #从dockerhub下载镜像  私有的docker仓库
docker search   搜索docker镜像
docker ps     查看docker正在运行的容器进程
docker ps -a   #查看所有运行过的容器记录
docker images  -a   #查看所有镜像文件
docker rm  #删除容器
docker  rmi  #删除镜像
docker rm  `docker ps -aq`
删除命令 添加 -f    参数,是强制删除容器,镜像记录
docker run -it  centos  /bin/bash 
docker tag  镜像名   新的镜像名 
docker tag  centos     yuchao163/s17centos  
docker push  yuchao163/s17centos 
docker commit  提交容器记录,为新的镜像
docker save    #将本地镜像,导出到一个文件 
docker  load  #导入本地镜像压缩文件,到docker镜像列表中

3、后台、交互等方式运行ubuntu容器

docker run it --rm unbuntu /bin/bash #--rm退出容器删除容器记录

    hostname

    cat /etc/os-release

    ps -ef交互式环境中查看docker容器中进程

docker run --name myredis ubuntu /bin/bash #定义names的用法

docker run -d centos /bin/bash   #后台运行程序

docker run -d centos /bin/sh -c   “while true;do echo 你好;sleep 1; done" #指定shell解释器

        -d 后台运行 
        centos  指定镜像文件 
        /bin/sh    指定shell解释器
        -C 指定一个shell语句

docker logs 容器id #查看容 日志

docker logs -f 容器id #查看容器日志,动态监控

docker exec -it 4b3 /bin/bash#进入容器空间 /bin/bash为运行解释器

docker start 容器id<-->dcker stop 容器id

4、本地镜像上传到dockhub

1.先注册dockerhub然后登陆;
2.找到上传页面;查看玩玩
3.linux中docker login
操作过程中可以用docker images反复查看镜像
4.docker push 镜像全名

5、搭建私有docker仓库docker registry

1.下载私有仓库的容器实例;代码老师有
-v 数据挂载,后跟宿主机的文件夹,其中包含下载registry的过程
2.访问ip+port不拒绝,??提供私有仓库api从查看结果;
3.更改docker配置,允许http推送
vim /ect/docker/daemon.json docker的配置文件4.指定docker服务加载配置代码
vim ..../service
        Environment增加
5.重新加载docker
systemctl daemon reload
6.重启docker
systemctl restart docker
7.重启私有容器的仓库
重启时要加入安全机制
8.修改私有仓库名字,以ip+port开头
9.docker push私有镜像文件名
其他:更改镜像tag,开头是自己的ip+port

 更多详情见:https://www.cnblogs.com/lvxw/articles/10980948.html

六、Redis(持久化、主从复制、哨兵集群

详情见:https://pythonav.com/wiki/detail/3/33/

详情见:https://www.cnblogs.com/lvxw/articles/10980847.html

七、项目部署

 1、windows下项目迁移到linux下

  # 1.准备crm代码
  # 自己从本地windows拷贝
  # 2.上传到linux服务器
  # 3.解压缩crm代码
  #     zip压缩文件unzip解压
  # 4.解决运行crm的环境问题
    # 方式1:
       # 1.通过命令,导出开发机器的所有模块 
       #     可以在windows下 通过这个命令,导出模块文件: 
       pip3 freeze   # requirements.txt   
       # 如果windows用的是虚拟机则需要贴换到虚拟虚拟环境中再执行上述命令。进入虚拟环境方法:cmd命令窗口贴换到虚拟环境的scripts路径下,执行avtivate命令
       avtivate
       # 2.将这个文件,上传到linux,进行安装
       pip3 install -i https://pypi.douban.com/simple -r requirements.txt 

    
     # 方式2:自己写requirements.txt ,再执行pip3安装命令(方式1中步骤2)  
       # 示例格式(顶格):
       ​        service-identity==17.0.0
       ​        six==1.11.0
               virtualenv==16.1.0
  #
  # 5.准备数据库
  # 此处用的是mysql数据库
   yum install mariadb-server    mariadb    -y 
  # 6.启动mariadb数据库
   systemctl  start mariadb 
  # 输入mysql_secure_installation进行安全配置
  # 7.修改Ace_crm的settings.py配置文件,修改mysql数据库驱动,去掉密码,还有修改 settings.py的allow_hosts
  # 8.创建mysql的数据库 crm 
  # 9.再次运行项目 

2、前后端分离项目部署(uwsgi+nginx+supervisor+nginx)

#部署:
#1.安装python3 环境(python3虚拟环境准备,pip3 ventualenvwarraper-->修改配置文件--》workon 虚拟环境--》which pip3;which python;pip3 list)
#2.安装 mysql,redis,nginx
  pip3 install uwsgi、django #3.部署前端 #1.安装node.js的环境 #2.安装依赖包 #3.修改axios的发送的端口接口 #4.打包 #4.部署后端 #1.安装virtualenv #2.创建虚拟环境 #3.安装django和uwsgi,以及项目的依赖包 #4.修改uwsgi的配置文件 #5.通过uwsgi -ini 配置文件启动django项目 #5.配置nginx #1.创建两个虚拟主机,分别监听80和8000端口 #2.访问80端口是访问呢vue #3.访问8000端口是vue发起的8000端口请求,反向代理到9000的uwsgi #6.启动nginx,mysql,redis #7.通过supervisor来管理
#1.新建虚拟环境,并激活;
#2.建立项目代码存放文件夹,导入前后端分离的项目代码并解压;
#3.解决环境依赖问题
    #成功运行机器导入:
        pip3 freeze > requirements.txt
    #传输文件到linux
        pip3 install -r requirement.txt
    #挨个下载依赖包:
        #no module named 'rest_framework'
        #no module named 'django_redis'  pip3 install django_redis
        #Crypto 不会装就百度pip3 install pycrypto
#4.uwsgi安装及启动
    pip3 install uwsgi     
    #启动方式1,用参数启动uwsgi --socket  :8000  --module  luffy_boy.wsgi
    #启动方式2:用配置文件启动
    touch uwsgi.ini 
    #写入配置
    [uwsgi]
    参数启动:
        uwsgi--http :8000 --module module mysite.wsgi
        uwsgi--socket :8000 --module module luffy_boy.wsgi
    
    #文件启动:
# Django-related settings
# the base directory (full path)
chdir           = /opt/luffy_city/luffy_boy
# Django's wsgi file
module          = luffy_boy.wsgi
# the virtualenv (full path)
home            = /root/Envs/luffy
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 1
# the socket (use the full path to be safe
socket          = 0.0.0.0:6666
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true    

#5.另开一个窗口,配置前端
> cd 前段项目路径
> vue、DRF可以看博客介绍
> 1.准备node环境
> ​    前端解释器
> ​    perl shell python nodejs,都是解释器
> ​    下载源码包
> wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz

> ​    解压缩

> tar -zxvf node-v8.6.0-linux-x64.tar.gz
> ​    bin目录查看,不需要编译安装(二进制包)
> 2.添加node到环境变量,source生效
> node-v npm-v,验证环境
> 3.编译打包voe文件
> > 3.1修改vue发起请求的地址?9:41
> > /opt/luffy_city/07-luffy_project_01/src/restful/api.js
> > ​    vim ..restful/api.rs
> > ​    Axio.get(改成服务器地址,linux服务器IP地址,注意区分9:44)
> > ​    127.0.0.1:8000-->192.168.11.194.sed命令 -i参数,注意绝对路径地址改为自己的9:47
> > sed -i "s/127.0.0.1/192.168.11.194/g"   /opt/luffy_city/07-luffy_project_01/src/restful/api.js 
> > PATH="/opt/node-v8.6.0-linux-x64/bin:/opt/python36/bin:/opt/ruby/bin/:/opt/tnginx220/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
> > 3.2安装node模块,voe代码第一层(前段代码?)
> > ​    npm install #出现package.json文件
> > ​            npm err Z_BUF_ERROR... 
> > ​            1024个包,安装时间过长报错
> > ​    编译打包vue代码,生成dist静态文件夹
> > ​    npm run build
> > ​        出现dist文件夹 老师用云服务器生成后传回
#6.配置nginx
    #1.创建两个虚拟主机,分别监听80和8000端口
    #2.访问80端口是访问呢vue
    #3.访问8000端口是vue发起的8000端口请求,反向代理到9000的uwsgi
#7.启动nginx,mysql,redis
#8.通过supervisor来管理

更多详情见:https://pythonav.com/wiki/detail/3/35/

 八、supervisor的安装和使用

#基于python2写的
#1.安装:
#退出虚拟环境,使用物理环境下的python2安装
yum
install
python - setuptools
easy_install
supervisor
#2.生成配置文件并编辑:命令生成和配置文件
echo_supervisord_conf > / etc / supervisord.conf
#3.在配置文件中,添加任务,管理uwsgi
vim / etc / supervisord.conf  # 在最底行,写入配置如下
uwsgi - -ini
uwsgi.ini

[program: s17uwsgi]
command = / root / Envs / my_crm_enve / bin / uwsgi - -ini / opt / ace_crm_self / uwsgi.ini
stopasgroup = true
killasgroup = true

[program: s17nginx]
command = / opt / tnginx220 / sbin / nginx
stopasgroup = true
killasgroup = true

#[program: xx] xx是为自己起的项目名。command = uwsgi启动命令,注意转换为绝对路径
#stopasgroup = true和killasgroup = true  # 整体杀死、启动进程(此处共有5个)
#4.启动
supervisord - c / etc / supervisord.conf
#5.通过命令管理任务,管理uwsgui
supervisorctl - c / etc / supervisord.conf查看uwsgi状态并进入supervisor操作界面
supervisorctl - c / etc / supervisord.conf
#6.管理supervisor的命令
stop s17uwsgi(任务名 )#任务名即配置文件中[program:xx]的xx
start s17uwsgi

start all
stop all
status

 九、uwsgi

uwsgi安装及启动
    pip3 install uwsgi 
    
    启动方式1,用参数启动uwsgi --socket  :8000  --module  luffy_boy.wsgi
    启动方式2:用配置文件启动
    touch uwsgi.ini 
    写入配置
    [uwsgi]

示例:
参数启动:
uwsgi--http :8000 --module module mysite.wsgi
uwsgi--socket :8000 --module module luffy_boy.wsgi


文件启动:
# Django-related settings
# the base directory (full path)
chdir           = /opt/luffy_city/luffy_boy
# Django's wsgi file
module          = luffy_boy.wsgi
# the virtualenv (full path)
home            = /root/Envs/luffy
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 1
# the socket (use the full path to be safe
socket          = 0.0.0.0:6666
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

启动

 

posted @ 2019-06-05 17:29  海予心  阅读(453)  评论(0编辑  收藏  举报