timetask 附带nginx版本

1. 传输文件到ubuntu上

https://blog.csdn.net/amin_hui/article/details/81837257?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param

也可以在windows上安装 FileZilla 上传文件

image-20200801134559575

更新 apt-get源

sudo apt-get update  

继续更新:

sudo apt-get upgrade

传送项目打包文件

安装net-tools

sudo apt install net-tools

查看本地ip地址

ifconfig -a 

image-20200803164658967

设置虚拟机静态ip

image-20200731212449058

image-20200805140258951

image-20200731212940479

在ubuntu服务器上安装 openssh-server

sudo apt install openssh-server

在windows上下载软件pscp

下载地址:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

image-20200801102702866

https://segmentfault.com/a/1190000023090036

下载到本地目录中

image-20200801103040821

传输文件需要文件的全名,而windows默认不显示后缀名,点击左上角查看,显示文件扩展名

image-20200801115906568

用cmd打开当前目录

image-20200801102819189

上传文件至虚拟机

pscp -P 22 JobCenter.tar.xz user@192.168.96.128:/opt/files

# -p 端口号
# 当前目录下要传输的文件名
# 用户名@服务器ip地址:要传入服务器的文件路径

其中如果跳出ssh key是否保存 记得选择yes

image-20200801114148337

image-20200801120520951

下载下来的文件是2层压缩文件,需要解压,一步解压方法:

tar -xvJf JobCenter.tar.xz

2. 安装mysql

https://zhuanlan.zhihu.com/p/61459645

准备

  1. sudo apt-get update(更新Ubuntu系统)

    sudo apt-get install mysql-server mysql-client

  2. 输入如下命令进行检验是否安装mysql成功。

    sudo apt-get install net-tools

    sudo netstat -tap | grep mysql

image-20200801152628157

  1. mysql默认是只允许本地主机访问127.0.0.1(需要注释掉),并关闭了远程连接,所以安装之后打开远程连接,并修改配置允许其他ip访问

    现在设置mysql允许远程访问,首先编辑文件/etc/mysql/mysql.conf.d/mysqld.cnf:编辑配置文件就输入命令

    sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf(注意报错:这个文件有的默认是只读,把光标调到该位置,按insert键输入,esc键退出编辑,:wq保存)或者 vim

    /etc/mysql/mysql.conf.d/mysqld.cnf

image-20200801152701234

如果后续仍然有报错,可以将127.0.0.1 改为 0.0.0.0 允许任何人连接(之后会设置账号密码),问题解决

  1. 重启mysql服务 /etc/init.d/mysql restart 或者 service mysql restart

image-20200801152721049

由于安装时未跳出密码设置,这里得想办法跳过密码:

初始化Root密码

若安装过程中没有要求输入密码,则Mysql会生成一个默认的密码,查看方式如下:

sudo cat /etc/mysql/debian.cnf

image-20200801153308861

需要编辑mysql配置文件来跳过密码验证:

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 按insert 进入编辑模式
# 编辑完后按Esc退出编辑模式
# 输入:wa! 保存文件输入并回到shell中

同时添加一些后续数据库的格式设置

(skip-grant-tables对应的是跳过验证)

image-20200803170021403

改完后记得重启数据库

service mysql restart

此时进入数据库无需密码,

mysql -uroot

image-20200803170330823

2、查看user表(错误发生的原因就是root的plugin设置错误)

select user, plugin from mysql.user;

image-20200803171036726

3、修改root的plugin
UPDATE user SET plugin='mysql_native_password' WHERE User='root';

flush privileges;

# 再次查看
select user, plugin from mysql.user;

image-20200803171225335

use mysql;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';  

4、刷新

flush privileges;

# 再次查看
select user, plugin from mysql.user;
image-20200803171259432

https://blog.csdn.net/zvenWang/article/details/99253611

查看host

查看host 对应的user 发现root对应是在localhost下

image-20200801170722026

因此我们需要创建一个新用户

# 以下写法8.0已经不支持了
# 坑爹啊 难怪一直出错
grant all privileges on *.* to  boss@"%" identified by "boss" with grant option;


# 正确写法

flush privileges
CREATE USER 'boss'@'%' IDENTIFIED BY '123456';
grant all privileges on *.* to 'boss'@'%';

# 刷新数据库账户权限;
flush privileges;

#刷新权限之后,重新查询。
select user,host from user;

image-20200803171922417

然后ctrl+D退出,注释掉/etc/mysql/mysql.conf.d/mysqld.cnf中添加的跳过密码的语句,此时初始化mysql root密码就完成了。

#重启mysql数据库服务器
service mysql start

之后就可以创建数据库并顺利连接到项目了~

3. 配置运行环境

安装pycharm

将文件下载至downloads中,在当前目录打开终端,解压

tar -zxvf  pycharm-professional-2020.1.2.tar.gz

image-20200803201434266

[Desktop Entry]
Name = PyCharm
Type = Application
Exec = /opt/pycharm-community-2019.3.3/bin/pycharm.sh #注意切换成自己的
Icon = /opt/pycharm-community-2019.3.3/bin/pycharm.png
Terminal = False

:wq保存文件,并执行下面命令,给予权限
sudo chmod u+x pycharm.desktop

将文件从download目录移动到opt目录下

# 在downloads目录下右键打开当前终端
cp JobCenter.tar.xz /opt

解压文件
tar -xvJf JobCenter.tar.xz

3. 安装python3.7环境

查看python指向环境

ls -l /usr/bin | grep python

image-20200803205331776

2.2 python环境

https://blog.csdn.net/qq_35933777/article/details/84325856

https://juejin.im/post/6844903921765318663

3、python相关安装
安装pip3(这里还是和需要使用的python版本有关,安装适合自己的版本)

sudo apt-get install python3-pip



sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

sudo tar xzf Python-3.7.0.tgz

image-20200804094721414

3.安装路径

sudo mkdir -p /usr/local/python3

下载pipenv

sudo pip3.7 install pipenv -i https://mirrors.aliyun.com/pypi/simple/

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100

3、python相关安装

安装pip3(这里还是和需要使用的python版本有关,安装适合自己的版本)

sudo apt-get install python3-pip

安装pipenv

cd JobCenter.

pipenv install --dev

pipenv shell

4、uwsgi安装与配置**

pip换源

在Windows下:
C:\Users\Administrator\下新建pip文件夹,在创建pip.ini文件,拷贝下面代码进去,保存。

在linux下:
sudo vim ~/.pip/pip.conf

替换为:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

进入项目虚拟环境目录下的bin文件,即:项目根目录/venv/bin

pipenv install uwsgi -i https://mirrors.aliyun.com/pypi/simple/

如果报错:

      File "/tmp/pip-install-q21no8ws/uwsgi/uwsgiconfig.py", line 755, in __init__
        raise Exception("you need a C compiler to build uWSGI")
    Exception: you need a C compiler to build uWSGI

# 输入
sudo apt-get install gcc #实在不行就安装build-essential

02、键入以下命令安装build-essential软件包:

linuxidc@linuxidc:~/www.linuxidc.com$ sudo apt install build-essential

该命令将安装一堆新包,包括gcc,g ++和make。

03、要验证GCC编译器是否已成功安装,请使用gcc --version命令打印GCC版本:

linuxidc@linuxidc:~/www.linuxidc.com$ gcc --version

Ubuntu 18.04存储库中可用的默认GCC版本是7.4.0:



#ubuntu
sudo apt-get install python3.7-dev

修改启动文件webhook.py rename为 manage.py

from flask_script import Manager
from app import create_app

app =create_app()
manager = Manager(app)

if __name__ == '__main__':
    manager.run()
    
# 即可测试
python manage.py runserver

进入项目根目录,新建目录

# 新建 uwsgi.ini

[uwsgi]

# 当载入的时候, Uwsgi的IP和端口
http=192.168.136.130:5001

# 对应web项目的主目录
chdir=/home/yang/mywork/JobCenter/

# 虚拟环境位置
 virtualenv=/home/yang/.local/share/virtualenvs/JobCenter-6lJXnf_S

# 启动文件
wsgi-file=manage.py

# The application variable of Python Flask Core Oject
callable=app

# The maximum numbers of Processes
processes=3

# The maximum numbers of Threads
threads=2

运行测试~

`uwsgi --ini uwsgi.ini`

Ctrl+C 结束运行。

配置虚拟机,允许其他主机访问域名

1.首先安装ssh服务

#检测是否安装
ssh localhost

出现以下提示则为未安装:
ssh: connect to host localhost port 22: Connection refused

2.安装ssh-server

 sudo apt-get install openssh-server

3.启动服务

sudo /etc/init.d/ssh start

4.检查服务是否启动成功

ps -e|grep ssh

image-20200806143326370

安装成功

如果想要修改配置比如修改默认端口号22为 其他

sudo vim /etc/ssh/sshd_config
# 找到Port 22 修改成你想要的

卸载SSH服务
$ sudo /etc/init.d/ss stop
$ sudo apt-get remove openssh-sftp-server                    //卸载sftp服务
$ sudo apt-get remove openssh-server                     //卸载openssh-server服务

开始 Nginx 的安装与配置

5. nginx

执行以下代码安装

sudo apt-get updat
sudo apt-get install nginx

修改目录/etc/nginx/sites-enabled/的default文件

cd /etc/nginx/sites-enabled/
sudo vim default

image-20200804135434683

24452#0: open() "/var/log/nginx/error.log" failed (13: Permission denied)

image-20200804141440991

按esc键,输入:wq,保存数据
重新载入及重新启动

sudo nginx -s reload
nginx

备注:如果以下操作无误,页面应该显示「502 Bad Way],以server_name 设置为localhost为例执行命令

curl http://localhost

html代码会显示以上内容

nginx默认配置目录

image-20200804170155172

思考

如何实现 编辑弹出修改定时任务的功能

将定时任务的div 复制到想加入到的地方

将原本由后端渲染的wtf_qick_form替换为前端生成的form表单.

将填入的新值传给后端, 后端更新数据

posted on 2020-08-14 11:50  sunnywillow  阅读(182)  评论(0编辑  收藏  举报