图片项目部署

1,准备

mysql 主从+读写分离 3台
nginx+uwsgi+python3.6 1台
redis 哨兵 3台
A nginx uwsgi python3 上传代码包,调试
B mysql redis 配置账号密码,导入数据

A:

下载nginx

[root@localhost ~]# yum -y install nginx
[root@localhost ~]# vim /etc/nginx/nginx.conf #添加以下内容
location / {
include uwsgi_params; # 导入uwsgi配置
uwsgi_pass 127.0.0.1:5555; # 转发端口
uwsgi_param UWSGI_PYTHON /usr/bin/python3; # Python解释器
uwsgi_param UWSGI_CHDIR /opt/web;# 项目根目录
uwsgi_param UWSGI_SCRIPT manager:app; # 项目的主程序,比如
}

在本地上传web的压缩包到opt下
[root@localhost opt]# yum -y install unzip
[root@localhost opt]# unzip web.zip

2,下载python3.6

下载安装依赖包
[root@localhost ~]# yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel
[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.12/Python-3.6.12.tar.xz
解压安装
[root@localhost ~]# tar -xf Python-3.6.12.tar.xz
[root@localhost ~]# cd Python-3.6.12
修改配置信息
[root@localhost Python-3.6.12]# vim Modules/Setup.dist #给下面这的#号备注去掉
在这里插入图片描述
编译安装
[root@localhost Python-3.6.12]# ./configure --enable-shared
[root@localhost Python-3.6.12]# make -j 2 # -j为当前主机cpu核心数
[root@localhost Python-3.6.12]# make install
配置环境
[root@localhost ~]# vim /etc/profile.d/python3_lib.sh #添加以下内容
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/lib
[root@localhost ~]# vim /etc/ld.so.conf.d/python3.conf #添加以下内容
usr/local/lib

接下来,执行如下命令使配置好的环境信息生效
[root@localhost ~]# ldconfig
[root@localhost ~]# source /etc/profile
测试 python3
[root@localhost ~]# python3 -V
python 3.7.6

安装所需要的模块
#requirement.txt 文件需要从本地上传
[root@localhost ~]# pip3 install -r requirement.txt

uwsgi 安装

[root@localhost ~]# wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz # 下载资源
[root@localhost ~]# tar xf uwsgi-latest.tar.gz
[root@localhost ~]# yum install -y gcc gcc-c++
[root@localhost ~]# cd uwsgi-2.0.19.1
[root@localhost uwsgi-2.0.19.1]# python3 uwsgiconfig.py --build # 编译,需要gcc
[root@localhost uwsgi-2.0.19.1]# python3 setup.py install # 安装
uwsgi配置文件
[root@localhost uwsgi-2.0.19.1]# vim uwsgi.ini #创建文件 添加以下内容,备注要去掉 不能留空格
[uwsgi]
socket = 127.0.0.1:5555 # 服务端口
processes = 4 # 进程
threads = 2 # 线程
wsgi-file = /opt/web/app.py # 入口文件
master = true # 允许主线程存在
pythonpath = /opt/web # 项目根路径
module = manager
callable = app
memory-report = true
uwsgi 管理

uwsgi --ini 配置文件路径 -d # -d 为后台
[root@localhost uwsgiconfig.py]#uwsgi -d --ini uwsgi.ini

启动nginx
[root@localhost ~]# systemctl start nginx

B:

下载redis并部署
[root@localhost ~]# yum install -y gcc gcc-c++ #安装编译工具
[root@localhost ~]# mkdir -p /data/application —创建工作目录
[root@localhost ~]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz —下载redis
[root@localhost ~]# tar xzf redis-4.0.9.tar.gz -C /data/application/ —解压
[root@localhost ~]# cd /data/application/
[root@localhost application]# mv redis-4.0.9/ redis
[root@localhost application]# make
[root@localhost ~]# vim redis.conf
bind 192.168.246.202  #只监听内网IP 就是允许谁访问 如允许所有人访问就0.0.0.0
daemonize yes     #开启后台模式将on改为yes
slave-read-only no #这个是只读的权限把yes修改为no。
timeout 300      #连接超时时间
port 6379 #端口号
dir /data/application/redis/data  #本地数据库存放持久化数据的目录该目录—待会要手动创建
pidfile /var/run/redis_6379.pid  #定义pid文件
logfile /var/log/redis.log  #定义log文件
创建存放数据的目录
[root@redis-master redis]# mkdir /data/application/redis/data
配置redis为systemctl启动
[root@redis-master redis]# cd /usr/lib/systemd/system
[root@redis-master system]# vim redis.service
[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/data/application/redis/src/redis-server /data/application/redis/redis.conf --daemonize no
ExecStop=/data/application/redis/src/redis-cli -h 127.0.0.1 -p 6379 shutdown

[Install]
WantedBy=multi-user.target

参数详解:
• [Unit] 表示这是基础信息
• Description 是描述
• After 是在那个服务后面启动,一般是网络服务启动后启动

• [Service] 表示这里是服务信息
• ExecStart 是启动服务的命令
• ExecStop 是停止服务的指令

• [Install] 表示这是是安装相关信息
• WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。

启动服务:
[root@redis-master system]# systemctl daemon-reload
[root@redis-master system]# systemctl start redis.service

登陆redis
[root@redis-master system]# cd /data/application/redis/src/
[root@redis-master src]# ./redis-cli -h 192.168.246.202 -p 6379
192.168.246.202:6379> ping #测试redis是否可以用
PONG
192.168.246.202:6379> set name newrain #设置key–name,并设置值
OK
192.168.246.202:6379> get name #获取到key
“newrain”
上传缓存文件到redis中
[root@localhost ~]# cd /data/application/redis/data # 吧缓存文件放到这个目录中就ok了

部署mysql
下载mysql,做主从同步
GTID复制
MS流程 GTID:
主配置
Master
1.[root@localhost ~]# vim /etc/my.cnf
log-bin
server-id=1
gtid_mode = ON
enforce_gtid_consistency=1

  1. 进入mysql数据库,授权一个用户
  2. mysql > grant all on . to slave@’%’ identified by ‘123’;
  3. mysql > flush privifeges;
  4. mysql > exit #退出数据库
  5. [root@localhost ~]# systemctl restart myslqd #重启服务

从配置
Slave部署:
1.修改配置文件打开gtid功能:
[root@localhost ~]# vim /etc/my.cnf
log-bin
server-id=2
gtid_mode = ON
enforce_gtid_consistency=1
master-info-repository=TABLE #这两个参数会将master.info和relay.info保存在表中,默认是Myisam引擎,官方建议用
relay-log-info-repository=TABLE #这两个参数会将master.info和relay.info保存在表中,默认是Myisam引擎,官方建议用
relay_log_recovery = on
[root@localhost ~]# systemctl restart mysqld #重启服务

【2. 进入数据库】
2. mysql > stop slave;
3. mysql > edit
4. mysql > change master to
master_host=‘master1’,
master_user=‘授权用户’,
master_password=‘授权密码’,
master_auto_position=1;
4. mysql > start slave; #启动slave角色
5. mysql > show slave status\G #查看主从同步是否成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值