bookwebsite部署服务

7 篇文章 0 订阅
1 篇文章 0 订阅

操作系统版本介绍

在这里插入图片描述

更新apt-get

apt-get update

安装mysql

apt-get --purge remove mysql-server mysql-common mysql-client #卸载以前的依赖
apt-get install mysql-server mysql-common mysql-client # 安装

设置密码

如果安装的过程中没有跳出密码,那么安装mysql之后你会发现mysql没有密码,即输入mysql -u root -p就可以回车直接登录。别问我为啥知道,因为我经历过。我太难了所以需要人为设置密码。如果有密码,可以直接跳过

root@ilocalhost:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=PASSWORD("yourpassword") where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> update user set plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 4  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

重启mysql

service  mysql  restart

mysql添加数据库

由于博客系统是将数据存储在数据库的,所以我们就需要创建数据库

create database bktest;

设置编码

安装中文语言包

这里我们会遇到一个坑,就是在后面程序启动保存数据的时候会出现中文乱码,但是我们明明已经编辑过默认编码了呀。这里我发现是阿里云服务器本身没有安装中文包,我们需要进行安装。

安装中文语言包

sudo apt-get -y install language-pack-zh-hans

修改语言环境设置

echo "LC_ALL=zh_CN.utf8" >> /etc/profile
echo "export LC_ALL" >> /etc/profile

查看语言

source /etc/profile

locale
看到zh_CN.UTF-8就成功了。接着需要重启服务器。

解压压缩包/git下载项目

下载地址

链接:https://pan.baidu.com/s/12vKb38jSOkr9OptbpQqyCw
提取码:****
复制这段内容后打开百度网盘手机App,操作更方便哦

在这里插入图片描述

生成虚拟环境

virtualenv venv

激活虚拟环境

linux

. /venv/bin/activate

windows

venv/Scripts/activate

效果
在这里插入图片描述

安装依赖

pip install -r requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple

修改配置文件

在这里插入图片描述

远程数据库增加远程用户登录

如果你使用的是远程数据库,那么这里就要设置一下远处数据库配置信息,从而实现博客使用远程数据库,如果使用的是本地数据库,请跳过这一步

  1. 修改配置文件
    vi /etc/mysql/mysql.conf.d/mysqld.cnf
    
    注释掉里面的
    bind-address           = 127.0.0.1
    
  2. 创建远程用户
    use mysql;
    create user 'userName'@'%' identified by 'password';
    
  3. 为用户分配权限
    grant all privileges on bktest.* to 'userName'@'%'identified by 'password' with grant option;
    
  4. 刷新权限表
    flush privileges;
    
  5. 重启mysql
    service mysql restart
    
  6. 测试链接
    在这里插入图片描述

运行

最简单的运行方式

在这里插入图片描述

使用nginx+uwsgi部署

安装nginx

apt-get install nginx

写nginx配置文件

server { 
  listen 80; # 80端口需要打开
  server_name X.X.X.X; #阿里云公网ip
  location / { 
  include uwsgi_params;
  uwsgi_pass 127.0.0.1:5000; # 指向uwsgi 所应用的内部地址
  uwsgi_param UWSGI_PYHOME /home/root/project/bk/venv; # 虚拟环境目录
  uwsgi_param UWSGI_CHDIR /home/root/project/bk; # 应用根目录
  uwsgi_param UWSGI_SCRIPT manage:app; # 启动程序
  uwsgi_read_timeout 100; 
 }  
}

重启nginx

service nginx restasrt

安装uwsgi

pip install uwsgi

注意实在虚拟环境。安装成功后需要配置。我们在项目的根目录下也就是bookwebsite下,创建配置文件config.ini,添加内容:

[uwsgi]
master = true
home = venv
wsgi-file = manage.py
callable = app
socket = :5000
processes = 4
threads = 2
buffer-size=32768
daemonize =/home/bookwebsite/book.log

运行uwsgi

uwsgi config.ini

效果

在这里插入图片描述

填入用户密码,创建完毕

在这里插入图片描述

二次开发

由于是web开发,所以就需要对css、js文件进行打包。
打包之前
在这里插入图片描述
打包之后
在这里插入图片描述

windows环境下

下载 node.js

参考网址下载node

安装node依赖包

这里使用的是package.json一键安装依赖包

E:\LAN\code\bk\app\static>npm install --production

> node-sass@4.12.0 install E:\LAN\code\bk\app\static\node_modules\node-sass
> node scripts/install.js

Cached binary found at C:\Users\asus\AppData\Roaming\npm-cache\node-sass\4.12.0\win32-x64-64_binding.node

> node-sass@4.12.0 postinstall E:\LAN\code\bk\app\static\node_modules\node-sass
> node scripts/build.js

Binary found at E:\LAN\code\bk\app\static\node_modules\node-sass\vendor\win32-x64-64\binding.node
Testing binary
Binary is fine
npm WARN static@1.0.0 No description
npm WARN static@1.0.0 No repository field.
npm WARN The package autoprefixer is included as both a dev and production dependency.
npm WARN The package cssnext is included as both a dev and production dependency.
npm WARN The package gulp-concat is included as both a dev and production dependency.
npm WARN The package gulp-headerfooter is included as both a dev and production dependency.
npm WARN The package gulp-minify-css is included as both a dev and production dependency.
npm WARN The package gulp-plumber is included as both a dev and production dependency.
npm WARN The package gulp-postcss is included as both a dev and production dependency.
npm WARN The package gulp-rename is included as both a dev and production dependency.
npm WARN The package gulp-uglify is included as both a dev and production dependency.
npm WARN The package precss is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 904 packages from 505 contributors in 85.279s

使用glup进行打包静态文件

由于是windows版本,所以肯定与linux版本下不同,这里报错

E:\LAN\code\bk\app\static>gulp
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'gulp-jshint'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (E:\LAN\code\bk\app\static\gulpfile.js:4:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

解决方案

E:\LAN\code\bk\app\static>npm install --save-dev jshint gulp-jshint
npm WARN static@1.0.0 No description
npm WARN static@1.0.0 No repository field.
npm WARN The package autoprefixer is included as both a dev and production dependency.
npm WARN The package cssnext is included as both a dev and production dependency.
npm WARN The package gulp-concat is included as both a dev and production dependency.
npm WARN The package gulp-headerfooter is included as both a dev and production dependency.
npm WARN The package gulp-minify-css is included as both a dev and production dependency.
npm WARN The package gulp-plumber is included as both a dev and production dependency.
npm WARN The package gulp-postcss is included as both a dev and production dependency.
npm WARN The package gulp-rename is included as both a dev and production dependency.
npm WARN The package gulp-uglify is included as both a dev and production dependency.
npm WARN The package precss is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ jshint@2.10.2
+ gulp-jshint@2.1.0
added 86 packages from 62 contributors in 18.371s

继续打包css

E:\LAN\code\bk\app\static>gulp
[17:04:18] Using gulpfile E:\LAN\code\bk\app\static\gulpfile.js
[17:04:18] Starting 'sass'...
[17:04:18] Finished 'sass' after 9.05 ms
[17:04:18] Starting 'js'...
[17:04:18] Finished 'js' after 6.48 ms
[17:04:18] Starting 'watch'...
[17:04:18] Finished 'watch' after 46 ms
[17:04:18] Starting 'cssmin'...
[17:04:18] Finished 'cssmin' after 3.05 ms
[17:04:18] Starting 'jsmin'...
[17:04:18] Finished 'jsmin' after 6.48 ms
[17:04:18] Starting 'dist'...
[17:04:18] Finished 'dist' after 35 μs
[17:04:18] Starting 'default'...
[17:04:18] Finished 'default' after 32 μs

成功

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值