2 Star 6 Fork 1

cuiliang / myblog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

项目简介

一、网站技术

网站前端使用到了layui、jQuery、Bootstrap框架,以及echaets实现数据可视化。

文章编辑器使用markdown,评论留言使用layui富文本实现。

后端使用python语言,django框架开发。

数据库主要使用MySQL,缓存使用Redis。

网站部署在阿里云服务器,使用docker部署,通过nginx反向代理,实现动静分离,css、js、字体、图片等静态资源使用七牛OSS对象存储,并通过华为CDN提供加速服务,动态资源由Django解析并处理。

整个站点流量通过调用百度统计的api接口实现流量统计分析。

二、网站架构

三、功能模块

博客网站按照用户身份权限共划分为网站前台、用户管理后台、管理员后台三部分,总共二十八个模块。

1. 前台模块

所有用户都可以通过网站前台浏览到博文、轮播广告、最新博文、热点博文、文章点赞等功能。

  • 首页

  • 文章分类

  • 笔记目录

  • 时间轴

  • 留言板

  • 关于页

  • 文章正文

  • 笔记正文

  • 用户登录

  • 用户注册

  • 忘记密码

  • 注销登录

2. 用户管理模块

用户注册后,通过登陆的用户可以进行发表文章评论、收藏文章、发表留言以及回复留言评论操作,在个人中心可以查看自己的浏览记录,收藏记录,点赞记录,还可以修改个人信息、修改密码、修改邮箱等功能。

  • 个人中心首页

  • 修改信息

  • 修改密码

  • 修改邮箱

  • 浏览记录

  • 收藏记录

  • 评论记录

  • 留言记录

3. 后台模块

后台博客管理系统是为管理员管理博客而设置的,管理员可以查看网站流量数据,查看注册用户信息,可以对文章进行发布、修改、删除操作。以及对文章分类,标签管理。还有设置博客网站的轮播图、友情链接等内容。

  • 流量统计

  • 文章发布

  • 文章列表

  • 文章分类

  • 文章标签

  • 文章评论

  • 笔记发布

  • 笔记列表

  • 笔记名称

  • 目录编排

  • 笔记评论

  • 网站配置

  • 博主信息

  • 关于页面

  • 轮播管理

  • 友链管理

  • 留言管理

  • 用户管理

四、部署流程

1. 代码目录准备

[root@aliyun root]# cd /opt
# git记住密码
[root@aliyun opt]# vim ~/.git-credentials
https://cuiliang0302:cl147963@gitee.com
[root@aliyun opt]# git config --global credential.helper store
# 拉取项目代码
[root@aliyun opt]# git clone https://gitee.com/cuiliang0302/myblog.git
# 初始化项目
[root@aliyun opt]# pip3 install click tinify
[root@aliyun opt]# chmod u+x /opt/myblog/other/update.sh 
[root@aliyun opt]# sh /opt/myblog/other/update.sh

2. MySQL部署

[root@aliyun opt]# mkdir -p /opt/docker/mysql
[root@aliyun opt]# cd /opt/docker/mysql/
[root@aliyun mysql]# docker run -p 3306:3306 --name mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d --restart=always mysql

3. MySQL导入数据

# 拷贝数据库文件
[root@aliyun mysql]# docker cp myblog/other/myblog.sql mysql:/root
[root@aliyun mysql]# docker exec -it mysql bash
root@3bd762759930:/# mysql -u root -p

# 设置远程连接数据库权限(按需)
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> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.00 sec)

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

# 创建数据库
mysql> CREATE DATABASE myblog DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myblog             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

# 导入数据
mysql> use myblog;
Database changed
mysql> source /root/myblog.sql;
mysql> show tables;

4. redis部署

[root@aliyun docker]# docker run --name redis -p 6379:6379 -d --restart=always redis --requirepass password
fe24cb38242ed2f1c8c7340fa1ce05f39c8fc351a7a96506c43dff41ca0774bb
[root@aliyun docker]# docker exec -it redis redis-cli
127.0.0.1:6379> auth CuiLiang@0302
OK

5. django部署

运行前记得将setting.py密码密钥等信息填写自己的内容。

[root@aliyun docker]# cd /opt/myblog/
# 构建镜像并运行
[root@aliyun myblog]# docker build -t myblog:v1 .
# 测试开发环境
[root@aliyun myblog]# docker run --name myblog -p 8000:8000 -v /opt/myblog:/opt/myblog -d --restart=always --link mysql --link redis myblog:v1
[root@aliyun myblog]# curl 127.0.0.1:8000
# 线上环境
[root@aliyun myblog]# docker run -d --name myblog -p 8997:8997 -v /opt/myblog:/opt/myblog -d --restart=always --link mysql --link redis myblog:v1

6. nginx部署

# 将项目下的other/nginx移动至/opt/docker下
[root@aliyun myblog]# cp -R other/nginx/ /opt/docker/
[root@aliyun myblog]# cd /opt/docker/
[root@aliyun docker]# tree nginx/
nginx/
├── conf
│   └── nginx.conf
└── ssl
    ├── cdn.cuiliangblog.cn_chain.crt
    ├── cdn.cuiliangblog.cn_key.key
    ├── www.cuiliangblog.cn_chain.crt
    └── www.cuiliangblog.cn_key.key
[root@aliyun docker]# docker run --name nginx -p 80:80 -p 443:443 -v /opt/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/docker/nginx/ssl:/etc/ssl -v /opt/myblog:/opt/myblog -v /opt/docker/nginx/log:/var/log/nginx -d --link myblog --restart=always nginx

五、运维

1. 壁纸定时更换

[root@aliyun ~]# chmod u+x /opt/myblog/other/make_bgc.py 
[root@aliyun ~]# crontab -e
* 3 * * * /usr/bin/python3 /opt/myblog/other/make_bgc.py >/dev/null

2. 数据库定时备份

[root@aliyun ~]# chmod u+x /opt/myblog/other/db_backup.sh
[root@aliyun ~]# crontab -e
* 4 * * * /usr/bash /opt/myblog/other/db_backup.sh >/dev/null
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

博客网站源码 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/cuiliang0302/myblog.git
git@gitee.com:cuiliang0302/myblog.git
cuiliang0302
myblog
myblog
master

搜索帮助

14c37bed 8189591 565d56ea 8189591