CentOS7源码安装Pythonvirtualenv虚拟环境安装uwsgi安装配置
Posted begrateful
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7源码安装Pythonvirtualenv虚拟环境安装uwsgi安装配置相关的知识,希望对你有一定的参考价值。
一:Python源码安装
1:Python源码下载XZ开头的 https://www.python.org/downloads/source/
2:解压:tar xf Python-3.8.11.tgz
3:配置:
1:先安装依赖环境
yum -y install gcc-* openssl-* libffi-devel sqlite-devel
4:配置:./configure --enable-optimizations --with-openssl=/usr/bin/openssl
5:编译:make -j4
6:安装:make install
python 默认安装路径:/usr/local/lib/python3.8
二:virtualenv虚拟环境安装
1:升级pip
执行:pip3 install --upgrade pip
会报一个错误关于ssl的,解决如下:
在源码目录中 Modeules/Setup 文件中211-214行放开注释。然后重新编译、安装
2:设置pip镜像地址 参考文档
3:安装虚拟环境 参考文档
三:安装uwsgi
1:执行:pip install uwsgi
2:创建一个配置文件 执行:mkdir /etc/uwsgi
3:编辑配置文件执行:vim /etc/uwsgi/uwsgi.ini
配置内容如下:
[uwsgi] uid = root gid = root # 使用nginx链接时使用,django程序所在服务器地址 # 选择内网IP和端口 192.168.31.170 172.17.0.1:8000 # 47.110.45.184:8090 socket = 127.0.0.1:8090 # 直接做web服务器使用 # http = 0.0.0.0:8090 # uwsgi服务器的角色主进程 master = true # 多站模式 vhost = true # 多站模式时不设置入口模块和文件 no-site = true # 子进程 workers = 2 # 平滑的重启 reload-mercy = 10 # 退出、重启时清理文件 vacuum = true # 开启1000个进程后,自动respawn下 max-requests = 1000 # 将进程的总内存量控制在512M limit-as = 512 buffer-size = 30000 # 存放进程编号文件 pidfile = /var/run/uwsgi8090.pid # 日志文件 daemonize = /var/log/uwsgi8090.log #项目根目录 #chdir = /home/ubuntu/smart_farm # 项目中wsgi.py文件目录 #wsgi-file = smart_farm/wsgi.py # 进程数 #processes = 4 # 线程数建议2*cup核数+1 #threads = 4 # 指定虚拟环境所在目录,不能填写相对目录 virtualenv = /home/centos/.virtualenvs/test
启动:uwsgi --ini /etc/uwsgi/uwsgi.ini
查看:netstat -ntpl
传统修改了配置文件后重启方式:
1:执行 cat /var/run/uwsgi8090.pid 获取进程id
2:在根据上面得到的进程id号杀死 kill -9 进程id
3:重新开启 uwsgi --ini /etc/uwsgi/uwsgi.ini
为了方便管理uwsgi,写一个脚本
执行:vim /etc/init.d/uwsgi 脚本内容如下:
在执行:chmod 755 /etc/init.d/uwsgi
测试如查看uwsgi状态执行:/etc/init.d/uwsgi status
测试关闭uwsgi执行:/etc/init.d/uwsgi stop
测试开启uwsgi执行:/etc/init.d/uwsgi start
四:安装redis 官方文档
源码安装redis 参考文档
redis配置设置 参考文档
[CentOS 7系列]源码包安装
源码包相对yum的安装方式来说,是一种很复杂的安装方式。中间涉及的每一步出错,会导致安装失败。因此在安装源码包的时候,每一步我们都要使用“echo $?”命令查看运行是否正常,确保源码包能够无误的安装上。
源码包的安装主要分为三个步骤:
1、./configure 配置参数
2、make 编译
3、make install 编译安装
下面将演示安装Apache:
[[email protected] src]# ls httpd-2.2.32 httpd-2.2.32.tar.gz [[email protected] src]# cd httpd-2.2.32 [[email protected] httpd-2.2.32]# ./configure --prefix=/usr/local/apache2 ...... config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands [[email protected] httpd-2.2.32]# echo $? ##如果显示不正常,可能是gcc没有安装 0 ##返回0表示运行正常 [[email protected] httpd-2.2.32]# make ...... gcc -g -O2 -pthread -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/src/httpd-2.2.32/srclib/pcre -I. -I/usr/local/src/httpd-2.2.32/os/unix -I/usr/local/src/httpd-2.2.32/server/mpm/prefork -I/usr/local/src/httpd-2.2.32/modules/http -I/usr/local/src/httpd-2.2.32/modules/filters -I/usr/local/src/httpd-2.2.32/modules/proxy -I/usr/local/src/httpd-2.2.32/include -I/usr/local/src/httpd-2.2.32/modules/generators -I/usr/local/src/httpd-2.2.32/modules/mappers -I/usr/local/src/httpd-2.2.32/modules/database -I/usr/local/src/httpd-2.2.32/srclib/apr/include -I/usr/local/src/httpd-2.2.32/srclib/apr-util/include -I/usr/local/src/httpd-2.2.32/srclib/apr-util/xml/expat/lib -I/usr/local/src/httpd-2.2.32/modules/proxy/../generators -I/usr/local/src/httpd-2.2.32/modules/ssl -I/usr/local/src/httpd-2.2.32/modules/dav/main -c /usr/local/src/httpd-2.2.32/server/buildmark.c /usr/local/src/httpd-2.2.32/srclib/apr/libtool --silent --mode=link gcc -g -O2 -pthread -o httpd modules.lo buildmark.o -export-dynamic server/libmain.la modules/aaa/libmod_authn_file.la modules/aaa/libmod_authn_default.la modules/aaa/libmod_authz_host.la modules/aaa/libmod_authz_groupfile.la modules/aaa/libmod_authz_user.la modules/aaa/libmod_authz_default.la modules/aaa/libmod_auth_basic.la modules/filters/libmod_include.la modules/filters/libmod_filter.la modules/loggers/libmod_log_config.la modules/metadata/libmod_env.la modules/metadata/libmod_setenvif.la modules/metadata/libmod_version.la modules/http/libmod_http.la modules/http/libmod_mime.la modules/generators/libmod_status.la modules/generators/libmod_autoindex.la modules/generators/libmod_asis.la modules/generators/libmod_cgi.la modules/mappers/libmod_negotiation.la modules/mappers/libmod_dir.la modules/mappers/libmod_actions.la modules/mappers/libmod_userdir.la modules/mappers/libmod_alias.la modules/mappers/libmod_so.la server/mpm/prefork/libprefork.la os/unix/libos.la -lm /usr/local/src/httpd-2.2.32/srclib/pcre/libpcre.la /usr/local/src/httpd-2.2.32/srclib/apr-util/libaprutil-1.la /usr/local/src/httpd-2.2.32/srclib/apr-util/xml/expat/libexpat.la /usr/local/src/httpd-2.2.32/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread -ldl make[1]: 离开目录“/usr/local/src/httpd-2.2.32” [[email protected] httpd-2.2.32]# echo $? 0 [[email protected] httpd-2.2.32]# make install ...... Installing icons mkdir /usr/local/apache2/icons mkdir /usr/local/apache2/logs Installing CGIs mkdir /usr/local/apache2/cgi-bin Installing header files Installing build system files Installing man pages and online manual mkdir /usr/local/apache2/man mkdir /usr/local/apache2/man/man1 mkdir /usr/local/apache2/man/man8 mkdir /usr/local/apache2/manual make[1]: 离开目录“/usr/local/src/httpd-2.2.32” [[email protected] httpd-2.2.32]# echo $? 0 [[email protected] httpd-2.2.32]# ls /usr/local/apache2 bin build cgi-bin conf error htdocs icons include lib logs man manual modules
源码包的卸载就是删除安装文件。
本文出自 “乱码时代” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1942512
以上是关于CentOS7源码安装Pythonvirtualenv虚拟环境安装uwsgi安装配置的主要内容,如果未能解决你的问题,请参考以下文章