0%
Theme NexT works best with JavaScript enabled
项目上线(裸机) 项目部署架构
补充
kvm
vmare
OpenStack
docker
k8s
云服务器安装mysql 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 yum update -y yum -y groupinstall "Development tools" yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel git 1 )前往用户根目录>: cd ~ 2 )下载mysql57>: wget http://dev.mysql.com/get/mysql57-community-release-el7-10. noarch.rpm 也可以本地上传,这条命令要在本地终端上执行 >: scp .\mysql57-community-release-el7-10. noarch.rpm root@106.14 .137 .210 :/root 3 )安装mysql57>: yum -y install mysql57-community-release-el7-10. noarch.rpm >: yum -y install mysql-community-server 4 )启动mysql57并查看启动状态>: systemctl start mysqld.service >: systemctl status mysqld.service 5 )查看默认密码并登录>: grep "password" /var/log/mysqld.log xdjj(/qgj0A4 >: mysql -uroot -p 6 )修改密码>: ALTER USER 'root' @'localhost' IDENTIFIED BY 'new password' ; >: ALTER USER 'root' @'localhost' IDENTIFIED BY 'Jerry123?' ;
云服务器安装redis 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 1 )前往用户根目录>: cd ~ 2 )下载redis-5.0 .5 >: wget http://download.redis.io/releases/redis-5.0 .5 .tar.gz 3 )解压安装包>: tar -xf redis-5.0 .5 .tar.gz 4 )进入目标文件>: cd redis-5.0 .5 5 )编译环境>: make 6 )复制环境到指定路径完成安装>: cp -r ~/redis-5.0 .5 /usr/local/redis 7 )配置redis可以后台启动:修改下方内容>: vim /usr/local/redis/redis.conf daemonize yes 8 )完成配置修改>: esc >: :wq 9 )建立软连接>: ln -s /usr/local/redis/src/redis-server /usr/bin /redis-server >: ln -s /usr/local/redis/src/redis-cli /usr/bin /redis-cli 10 )后台运行redis>: cd /usr/local/redis >: redis-server ./redis.conf & ctrl + c 11 )测试redis环境>: redis-cli ctrl + c 12 )关闭redis服务>: pkill -f redis -9
云服务器安装nginx 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 1 )前往用户根目录>: cd ~ 2 )下载nginx1.13 .7 >: wget http://nginx.org/download/nginx-1.13 .7 .tar.gz 3 )解压安装包>: tar -xf nginx-1.13 .7 .tar.gz 4 )进入目标文件>: cd nginx-1.13 .7 5 )配置安装路径:/usr/local/nginx>: ./configure --prefix=/usr/local/nginx 6 )编译并安装>: make && sudo make install 7 )建立软连接:终端命令 nginx>: ln -s /usr/local/nginx/sbin/nginx /usr/bin /nginx 8 )删除安装包与文件:>: cd ~ >: rm -rf nginx-1.13 .7 >: rm -rf nginx-1.13 .7 .tar.xz 9 )测试Nginx环境,服务器运行nginx,本地访问服务器ip>: nginx >: 服务器绑定的域名 或 ip:80 1 )启动>: nginx 2 )关闭nginx>: nginx -s stop 3 )重启nginx>: nginx -s reload 4 )查看端口,强行关闭>: ps -aux|grep nginx >: kill <pid:进程编号>
安装python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 )前往用户根目录>: cd ~ 2 )下载 或 上传 Python3.7 .7 >: wget https://www.python.org/ftp/python/3.7 .7 /Python-3.7 .7 .tar.xz 3 )解压安装包>: tar -xf Python-3.7 .7 .tar.xz 4 )进入目标文件>: cd Python-3.7 .7 5 )配置安装路径:/usr/local/python3>: ./configure --prefix=/usr/local/python3.7 6 )编译并安装 yum -y install zlib* yum install libffi-devel >: make && sudo make install 7 )建立软连接:终端命令 python3,pip3>: ln -s /usr/local/python3.7 /bin /python3.7 /usr/bin /python3.7 >: ln -s /usr/local/python3.7 /bin /pip3.7 /usr/bin /pip3.7 8 )删除安装包与文件:>: rm -rf Python-3.7 .7 >: rm -rf Python-3.7 .7 .tar.xz
安装uwsgi 1 2 3 4 5 6 pip3.7 install uwsgi 在任意路径下执行uwsgi会发现命令存在,这就可以了 ln -s /usr/local/python3.7 /bin /uwsgi /usr/bin /uwsgi
配置虚拟环境 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 )安装依赖>: pip3.7 install virtualenv >: pip3.7 install virtualenvwrapper pip3.7 install --upgrade setuptools python3.7 -m pip install --upgrade pip 2 )建立虚拟环境软连接(使用内置的python3.6 不需要加)>: ln -s /usr/local/python3.7 /bin /virtualenv /usr/bin /virtualenv 3 )配置虚拟环境:填入下方内容>: vim ~/.bash_profile VIRTUALENVWRAPPER_PYTHON=/usr/bin /python3.7 source /usr/bin /virtualenvwrapper.sh 4 )退出编辑状态>: esc 5 )保存修改并退出>: :wq 6 )更新配置文件内容>: source ~/.bash_profile 7 )虚拟环境默认根目录:~/.virtualenvs8 )创建虚拟环境 mkvirtualenv luffy workon luffy
前端项目部署 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 base_url: 'http://106.14.137.210:8000' , // 真实环境:django项目就是跑在8000 端口上的 cnpm run build 压缩成zip ,拖到服务器上去 yum install unzip unzip dist.zip mkdir /home/html mv ~/dist /home/html cd /usr/local/nginx/conf >: cd /usr/local/nginx/conf >: mv nginx.conf nginx.conf.bak >: vim nginx.conf >: i events { worker_connections 1024 ; } http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 80 ; server_name 127.0 .0 .1 ; charset utf-8 ; location / { root /home/html; index index.html; try_files $uri $uri/ /index.html; } } } >: esc >: :wq >: nginx -s reload
后端项目部署 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 pip3 freeze > req.txt mkdir /home/project cd /home/project git clone https://gitee.com/liuqingzheng/luffy_api.git <uwsgi> <socket>127.0 .0 .1 :8888 </socket> <chdir>/home/project/luffy_api/</chdir> <module>luffy_api.wsgi</module> <processes>4 </processes> <daemonize>uwsgi.log</daemonize> </uwsgi> >: events { worker_connections 1024 ; } http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 80 ; server_name 127.0 .0 .1 ; charset utf-8 ; location / { root /home/html; index index.html; try_files $uri $uri/ /index.html; } } server { listen 8000 ; server_name 127.0 .0 .1 ; charset utf-8 ; location / { include uwsgi_params; uwsgi_pass 127.0 .0 .1 :8888 ; uwsgi_param UWSGI_SCRIPT luffy_api.wsgi; uwsgi_param UWSGI_CHDIR /home/project/luffy_api/; } } } 1 )管理员连接数据库>: mysql -uroot -Jerry123? 2 )创建数据库>: create database imooc default charset=utf8mb4; 3 )设置权限账号密码:账号密码要与项目中配置的一致>: grant all privileges on imooc.* to 'cjt' @'%' identified by 'Jerry123?' ; >: grant all privileges on imooc.* to 'cjt' @'localhost' identified by 'Jerry123?' ; >: flush privileges; 4 )退出mysql>: quit; export DB_PASSWORD=Lqz12345? workon luffy pip install -r req.txt pip install uwsgi python manage_pro.py migrate python manage_pro.py createsuperuser uwsgi -x ./imooc.xml ps aux |grep uwsgi nginx -s reload mkdir /home/project/luffy/luffy_api/static STATIC_URL = '/static/' STATIC_ROOT = '/home/project/luffy/luffy_api/static' STATICFILES_DIRS = (os.path.join(BASE_DIR, "static" ),) python ./manage_pro.py collectstatic location /static { alias /home/project/luffy/luffy_api/static; } 把域名指向我们服务器的地址即可
docker-compose一键部署 安装/更新依赖包 1 2 3 4 yum update -y yum -y groupinstall "Development tools" yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel git
安装docker/docker-compose 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 一 安装Docker yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ce systemctl enable docker systemctl start docker docker version 二 安装Docker-compose curl -L https://github.com/docker/compose/releases/download/1.26 .2 /docker-compose-$(uname -s)-$(uname -m) > /usr/bin /docker-compose chmod +x /usr/bin /docker-compose docker-compose --version docker-compose up -d
整合项目文件夹 1 2 3 https://gitee.com/chi-jintao/imooc.git