CentOs deploys AKShare HTTP and calls it from external network IP

demand background

When I was chatting on the weekend, I read the official document of akshare. I used to call the data through the python program. As a java developer, I think it is very inconvenient. I took a serious look at the documentation, and I'm sorry. The boss has launched the aktools tool, so that most interfaces can be called through http requests. We only need to deploy one aktools, and then we can flexibly process data through the interface name. The official documentation is very simple

premise

It is necessary to install the relevant environment of python in advance. Here, the officials will search by themselves, so I won’t go into details here.

Into the title

  • install aktools
pip install aktools
  • run aktools
python -m aktools

If there is no problem with the environment, it will display an effect similar to the following after running


After running, generally you do not set the specific running IP and port, and the default is to run under port 8080 of the local environment, so that the external network cannot be accessed

Set the external network to be accessible

python -m aktools --host 你的IP --port 你的端口号

Note that if you use Alibaba Cloud's centos, the IP here needs to use the corresponding intranet IP

Open ports for external network access

1、开启防火墙
systemctl start firewalld

2、开放指定端口
firewall-cmd --zone=public --add-port=1935/tcp --permanent
命令含义:
--zone #作用域
--add-port=1935/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效

3、重启防火墙
firewall-cmd --reload

4、查看端口号
netstat -ntlp //查看当前所有tcp端口·

netstat -ntulp |grep 1935 //查看所有1935端口使用情况

Aliyun security group also needs to open the corresponding port number

This is Baidu. Generally, those who play cloud servers know where it is.

After closing the terminal, the program terminates

  • Countermeasures
    If it needs to run in the background, write a script, the script format is xxx.sh, and the content is as follows:
python -m aktools --host 你的IP --port 你的端口号 &

The change is to add an & at the end

run script

Enter the script directory and execute the following command, so that closing the terminal will not affect the program to continue running

sh xxx.sh

write at the end

Those who are interested in akshare can try it out by themselves. Only when the data is in their own hands can they be analyzed flexibly. This is "Anqianmahou", an account that focuses on sharing practical content. Three companies are welcome, and we will continue to release money-making content in the future. Technology is not the ceiling, and making money is the kingly way.

Guess you like

Origin blog.csdn.net/weixin_42329623/article/details/131751484