用python脚本 部署 redis
import time
import zipfile
from time import sleep
import os
import requests
def download():
"""下载reids"""
print("downloading with Redis")
url = 'https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.zip'
r = requests.get(url)
with open("Redis-x64-3.2.100.zip", "wb") as code:
code.write(r.content)
print(" Redis下载完毕")
def decompression():
"""解压安装"""
file_dir = os.path.abspath(os.getcwd())
for root, dirs, files in os.walk(file_dir):
# print(root) # 当前目录路径
# print(dirs) # 当前路径下所有子目录
print(files) # 当前路径下所有非目录子文件
files_list = files
target_dir = root
for file in files_list:
if file.startswith('Redis'):
source_zip = target_dir + "\" + file
myzip = zipfile.ZipFile(source_zip)
path1 = target_dir + "\redis"
os.mkdir(path1)
myzip.extractall(path1)
myzip.close()
print("redis 解压完成")
return path1
def cmd_server(path):
"""设置服务启动"""
time.sleep(3)
os.chdir(path)
time.sleep(2)
os.system(command="redis-server --service-install redis.windows.conf") # 设置成window服务
print("设置成window服务启动成功")
sleep(3)
os.system(command="redis-server --service-start") # 启动redis
print("redis启动成功")
def main():
# download() # 下载
path = decompression() # 解压安装
cmd_server(path) # 设置成服务,启动
if name == 'main':
main()