Deploy the local Python crawler project to the Alibaba Cloud lightweight server through the pagoda


Note: Recently, I want to get a set of local crawler projects to run on the server.

1. Upload project files

It can be compressed into a zip locally, manually upload the compressed package to the pagoda folder, and finally extract it and put it under the path of the picture below.

![Insert picture description here](https://img-blog.csdnimg.cn/35683919ba694d5485ad9b5197549105.png

2. Prepare the project environment

2.1. Install requirements.txt dependencies

For adding python projects, I won’t go into details here. For details, please refer to my previous blog notes:Pagoda deploys flask project

First make sure you have packaged project module dependencies: enter the project root directory and enter the following command:

 pip freeze > requirements.txt

Installation dependency method 1:
insert image description here
Installation dependency method 2:
If the method 1 reports that there is an error in the installation dependency, after confirming that the network, project path and other factors are correct, you can install it according to the figure below, and click the module in the project management. (You can also start and run directly, check the log for installation or other operations)

insert image description here
insert image description here

2.2. Install node.js environment

Because the nodejs environment is used, it needs to be installed and configured separately. Installing node can mess me up for a long time!
At the beginning, the PM2 manager was installed. It is said that it has built-in nodejs, and it is convenient to install modules. As a result, after the installation, an error was reported. I didn’t find a related article on the Internet. After working on it for
insert image description here
a while, I felt that it would be troublesome to fix the above error. After thinking about it for a while, I gave up, because I just use node Environment, using several node libraries. Direct installation is, refer to the link:install node
Check it out at the end:
insert image description here

2.3, Alibaba Cloud Server MySQL 8.0 enables remote connection

To install mysql first, you can install it directly on the pagoda panel. My version is 8X
one-click 管理员root to connect to the server. If you have not set or forgotten the server root password, just click the overview on the page below, and click to enter the page 重置密码.
insert image description here

1. Login to the database

mysql -u root -p

Enter the password (it will not be displayed after entering the password) and press Enter. If the password is not modified, it is the root password of your pagoda panel database:
insert image description here

insert image description here
2. Select the mysql library

use mysql;

3. Modify the password when connecting

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '连接用的密码';

4. List all users and hosts from the user table

select user,host from user;

5. Modify the ip address of the root user to %

update user set host='%' where user = 'root';

6. Refresh the permission information to make the update take effect

flush privileges;

7. Exit mysql

exit;

Screenshot:
insert image description here
By the way, it’s almost here, let’s goLet go of 3306the portIt's OK.
In Alibaba Cloud:insert image description here
In the pagoda panel:

insert image description here

Reference Big Brother Article: Reference Article

2.4, local remote connection MySQL test

2.4.1, navicat remote connection test

没有标注的,就不用修改。
one,
insert image description here
two,
insert image description here

For the password shown above:
one,

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '连接用的密码';

The password you set when modifying

two,insert image description here
Cool!The connection is successful, now you can easily type sql, and you can also view the data intuitively! Cool! ! !
insert image description here

2.4.2, python code connection test

code:

"""
CSDN: 抄代码抄错的小牛马
mailbox:[email protected]
"""
"""
params:
    1、mysql: 指定那种数据库连接
    2、username: root
    3、password: 密码
    4、databaseIP: 数据库IP端口:本地IP + MySQL端口: 127.0.0.1:3306
    5、database_name: 要连接的数据库名字
    6、pymysql 对应数据库操作驱动

"""
from sqlalchemy import create_engine
from sqlalchemy import text
from urllib.parse import quote_plus as urlquote

host = "你的服务器公网IP"
port = 3306
user = "root"
password = "连接用的密码"
database = "lucky"

url = f'mysql+pymysql://{
      
      user}:{
      
      urlquote(password)}@{
      
      host}:{
      
      port}/{
      
      database}?charset=utf8'

engine = create_engine(url=url, echo=True, future=True)

# 测试连接是否成功
with engine.connect() as conn:
    sql = "select * from `bus_source_log`"
    result = conn.execute(text(sql))
    print(result.all())

OK, see you next time~

Guess you like

Origin blog.csdn.net/qq_61122628/article/details/131127211