|
|
@ -1,4 +1,180 @@ |
|
|
|
# phshare |
|
|
|
|
|
|
|
Cloud computing coursework:Saas |
|
|
|
图片社交网站 |
|
|
|
# Photo Share
|
|
|
|
|
|
|
|
张硕闻 陈煜 杜涵悦 |
|
|
|
|
|
|
|
如部署遇到问题可微信联系(应该不会,亲测多次) |
|
|
|
|
|
|
|
## 部署流程
|
|
|
|
|
|
|
|
1. 首先,创建云主机。 |
|
|
|
2. 连接云主机,配置python环境。 |
|
|
|
|
|
|
|
```shell |
|
|
|
# 1、yum更新
|
|
|
|
yum update |
|
|
|
|
|
|
|
# 2、安装Python 3.7所需的依赖否则安装后没有pip3包
|
|
|
|
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make |
|
|
|
|
|
|
|
# 3、在官网下载所需版本,这里用的是3.7.2版本
|
|
|
|
# 如果速度太慢可以在浏览器中访问下面的链接把它下载到本地电脑再上传到云主机上
|
|
|
|
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz |
|
|
|
|
|
|
|
# 4、解压
|
|
|
|
tar -xvJf Python-3.7.2.tar.xz |
|
|
|
|
|
|
|
# 5、配置编译
|
|
|
|
cd Python-3.7.2 |
|
|
|
./configure --prefix=/usr/local/python3 |
|
|
|
make && make install |
|
|
|
|
|
|
|
# 6. 安装pip
|
|
|
|
wget https://bootstrap.pypa.io/get-pip.py |
|
|
|
python3 get-pip.py |
|
|
|
pip -V # 检查 |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3. nginx安装 |
|
|
|
|
|
|
|
```shell |
|
|
|
# 1、下载对应当前系统版本的nginx包
|
|
|
|
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm |
|
|
|
|
|
|
|
# 2、建立nginx的yum仓库
|
|
|
|
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm |
|
|
|
|
|
|
|
# 3、安装nginx
|
|
|
|
yum install -y nginx |
|
|
|
|
|
|
|
# 4、启动nginx服务
|
|
|
|
systemctl start nginx.service |
|
|
|
|
|
|
|
# 5、查看启动状态
|
|
|
|
# systemctl status nginx
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4. 安装mysql数据库客户端 |
|
|
|
|
|
|
|
```shell |
|
|
|
yum -y install mysql |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5. 创建 mysql 云数据库 |
|
|
|
|
|
|
|
创建成功后通过phpMyAdmin网页登录 |
|
|
|
|
|
|
|
创建名为phshare的数据库 |
|
|
|
|
|
|
|
![](./pictures/1.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6. 下载代码,改代码 |
|
|
|
|
|
|
|
```shell |
|
|
|
cd /usr/local/python3/bin |
|
|
|
|
|
|
|
# 将phshare整个项目文件夹放入该目录下
|
|
|
|
git clone http://gitea.shuishan.net.cn/10185501403/phshare |
|
|
|
cd phshare |
|
|
|
|
|
|
|
# 改连数据库的ip与密码 见下图
|
|
|
|
vim phshare/settings.py |
|
|
|
``` |
|
|
|
|
|
|
|
以下两行需要改密码与云数据库ip。 |
|
|
|
|
|
|
|
![](./pictures/2.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7. 安装python第三方库 |
|
|
|
|
|
|
|
```shell |
|
|
|
pip install -r requirements.txt |
|
|
|
pip install gunicorn |
|
|
|
``` |
|
|
|
|
|
|
|
8. 运行 |
|
|
|
|
|
|
|
```shell |
|
|
|
# 初始化数据库
|
|
|
|
flask init |
|
|
|
|
|
|
|
# 运行 内网ip替换 3389端口 由于云账户设置了3389暴露
|
|
|
|
gunicorn -w 3 -b x.x.x.x:3389 manage:app |
|
|
|
|
|
|
|
# 后台运行 内网ip替换
|
|
|
|
nohup gunicorn -w 3 -b x.x.x.x:3389 manage:app >/dev/null 2>&1 & |
|
|
|
``` |
|
|
|
|
|
|
|
浏览器中访问 http://X.X.X.X:3389/ (用外网Ip) |
|
|
|
|
|
|
|
部署完成 |
|
|
|
|
|
|
|
9. 负载均衡准备 |
|
|
|
|
|
|
|
另外创建两个与以上部署好的云主机**完全相同**的云主机(相当于以上步骤都要做好),可以从镜像中创建,或将以上步骤重做两次。**使用后台运行命令启动gunicorn** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10. 创建负载均衡,创建VServer。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11. 添加节点,监听端口3389。将之前创建的云主机都加入 |
|
|
|
|
|
|
|
![](./pictures/3.png) |
|
|
|
|
|
|
|
![](./pictures/4.png) |
|
|
|
|
|
|
|
12. 这样我们访问负载均衡的外网ip就也可以访问到应用了。可以另创建一台云主机对负载均衡进行压测。 |
|
|
|
|
|
|
|
```shell |
|
|
|
# 安装ApacheBench
|
|
|
|
yum -y install httpd |
|
|
|
|
|
|
|
# 替换负载均衡ip
|
|
|
|
ab -c 1000 -n 10000 http://xxx.xxx.xxx.xxx/ |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 主要功能描述
|
|
|
|
|
|
|
|
主页:主页动态、搜索、探索、评论点赞收藏举报、添加描述标签提醒等 |
|
|
|
|
|
|
|
用户:注册登录、账户设置以及主页、关注、被关注 |
|
|
|
|
|
|
|
管理:管理图片、用户、评论、标签,编辑标签以及网站设置 |
|
|
|
|
|
|
|
## SaaS 应用效果
|
|
|
|
|
|
|
|
demo可访问网址探索:[Home - Phshare](http://106.75.209.92/) |
|
|
|
|
|
|
|
http://106.75.209.92/ |
|
|
|
|
|
|
|
**截图不能反应全部功能,可访问网站以查看** |
|
|
|
|
|
|
|
截图: |
|
|
|
|
|
|
|
![](./pictures/5.png) |
|
|
|
|
|
|
|
![](./pictures/6.png) |
|
|
|
|
|
|
|
![](./pictures/7.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![](./pictures/8.png) |
|
|
|
|
|
|
|
|
|
|
|
|