宝塔怎么运行python程序 宝塔安装python3

您所在的位置:网站首页 宝塔安装python3 宝塔怎么运行python程序 宝塔安装python3

宝塔怎么运行python程序 宝塔安装python3

2023-11-23 02:13| 来源: 网络整理| 查看: 265

python3的安装

直接使用weget工具下载官方包,tar -zxvf解压到任意目录下,进入到主目录执行:

./configure –prefix=/usr/local/python3/ # 安装目录 make && make install # 编译并安装

安装好后配置软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

由于yum以及宝塔socket均用的python2,linux直接改为3的环境,会导致很多问题,所以还是默认使用2,在执行时使用python3,安装pip,设置软连接为pip3。

wget –no-check-certificate https://bootstrap.pypa.io/get-pip.py python3 get-pip.py #配置软连接的情况下,可以使用python3 -m pip来使用python3的pip。

软连接备份的话,可以cd到 /usr/bin下,执行:

# 备份 python -> python2 # 删除 rm /python

centos自带的sqlite版本过低,如果django用sqlite数据库,会报错(SQLite 3.8.3 or later is required (found 3.7.17),升级版本以下教程链接:

mysql还是装5.7或以上,避免出现很多未知问题,很坑。 手动安装需要加入path环境变量:

export PATH=”$PATH”:/usr/local/mysql/bin #当前shell其作用 echo 'PATH=”$PATH:/usr/local/mysql/bin”' >> ~/.bashrc #当前用户,全局 /etc/profile

宝塔mysql默认配置以下,可以参考:

[client] #password = your_password port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock datadir = /www/server/data default_storage_engine = InnoDB performance_schema_max_table_instances = 400 table_definition_cache = 400 skip-external-locking key_buffer_size = 8M max_allowed_packet = 100G table_open_cache = 32 sort_buffer_size = 256K net_buffer_length = 4K read_buffer_size = 128K read_rnd_buffer_size = 256K myisam_sort_buffer_size = 4M thread_cache_size = 4 query_cache_size = 4M tmp_table_size = 8M sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp = true #skip-name-resolve max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 expire_logs_days = 10 slow_query_log=1 slow-query-log-file=/www/server/data/mysql-slow.log long_query_time=3 #log_queries_not_using_indexes=on early-plugin-load = "" innodb_data_home_dir = /www/server/data innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /www/server/data innodb_buffer_pool_size = 16M innodb_log_file_size = 5M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 [mysqldump] quick max_allowed_packet = 500M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeoutuwsgi

pip安装后,配置下软连接

ln -s /usr/local/python3/bin/django-admin.py /usr/bin/django-admin.py ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv ln -s /usr/local/python3/bin/gunicorn /usr/bin/gunicorn

测试是否成功

uwsgi –version

随便建立个socket,test.py

def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3

8000端口启动:uwsgi –http :8000 –wsgi-file test.py

连接Django

pycharm直接sftp远端,上传项目到云服务器,项目根目录建立uwsgi.ini文件,写入配置:

[uwsgi] socket=127.0.0.1:8001 chdir=/www/wwwroot/bbs wsgi-file=/www/wwwroot/bbs/bbs/wsgi.py module=bbs.wsgi master=true processes=4 vacuum=true daemonize=/www/wwwroot/bbs/uwsgi.log virtualenv=/www/wwwroot/bbs/bbs_venv

其中log文件很重要,我们后台启动uwsgi时,可以通过log日志定位错误。 socket保持nginx一致。

启动:uwsgi uwsgi.ini

Nginx

调试nginx会出现许多问题, 1.端口占用,冲突。 2.django项目启动了出错,依赖问题,数据库连接问题,这些都是log排查解决。

宝塔有许多坑,自带的python项目管理器,问题很多,调试好了比较方便些,具体步骤如下:

1.添加项目,宝塔会建立一个虚拟环境,先在项目生成一个requirement.txt,有时候虚拟环境也是导致项目挂的原因,得去环境中运行排查。选项如下,运行文件夹选第二层吧,应该没什么影响,不知道宝塔启动机制。

宝塔怎么运行python程序 宝塔安装python3_mysql

创建好,一些功能可以帮我们快速重启什么,改uwsgi配置什么的,比较方便。

宝塔怎么运行python程序 宝塔安装python3_mysql_02

建立的项目端口别冲突,宝塔安全里面加入新增的开放端口。

然后去配置nginx.conf,注意的是,include会包含外部其他文件夹的conf文件,我这里注释了宝塔的最后一行。

user www www; worker_processes auto; error_log /www/wwwlogs/nginx_error.log crit; pid /www/server/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; #include luawaf.conf; include proxy.conf; default_type application/octet-stream; server_names_hash_bucket_size 512; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m; server_tokens off; access_log off; server { listen 888; server_name phpmyadmin; index index.html index.htm index.php; root /www/server/phpmyadmin; #error_page 404 /404.html; include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /www/wwwlogs/access.log; } server { listen 80; server_name 111.67.204.165; charset utf-8; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8003; } location /static { alias /www/wwwroot/bbs/static; } } server { listen 80; server_name 111.67.204.164; charset utf-8; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8002; } location /static { alias /www/wwwroot/library_manage/static; } } #include /www/server/panel/vhost/nginx/*.conf; }

前面不用管,后面80端口是我们添加的,对外访问,默认。 我们这里双站点,server_name 的ip写两个不同,监听都是80没问题,uwsgi_pass 必须与项目一致,这是核心,其他就没啥问题了,只要本地django项目127.0.0.1:端口启动,nginx将会自动帮我们映射到外网。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3