Centos 中安裝python,mysql

 


 

 

1,安裝依賴 html

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel python-develpython

 

2,安裝pythonmysql

#wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
#mkdir -p /usr/local/python3
#tar zxvf Python-3.6.5.tgz
#cd Python-3.6.5
#./configure --prefix=/usr/local/python3
#make
#make install
#ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
#ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
#pip3 install --upgrade pip #更新pip
#pip3 install ipython #安裝ipython方便調試
#python3 -v 進行調試nginx

!!!千萬別刪centos中自帶的python2web

三、安裝虛擬環境 sql

pip3 install virtualenvdjango

若是出現報錯參考vim

https://blog.csdn.net/weixin_42670402/article/details/88551804centos

virtualenv -p /usr/local/python/bin/python3 websocket

(激活)source web/bin/activate

4,pip install django==2.1.8

django-admin.py (查看命令)

django-admin.py startproject myweb

cd myweb 而後 python manage.py runserver

 

 


安裝mysql

一、下載數據包

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 

二、安裝包

 rpm -ivh mysql-community-release-el7-5.noarch.rpm

三、安裝mysql-server

sudo yum install mysql-server

 四、若是登錄mysql報錯,把文件權限更改成當前用戶

 sudo chown -R openscanner:openscanner /var/lib/mysql

五、重啓mysql 

service mysqld restart
mysql -u root 

六、設置登錄密碼

use mysql;
update user set password=password('123456') where user='root';
flush privileges;
 

一、安裝uwsgi(Nginx沒法直接收到python的數據)

pip install uwsgi

 

二、建立配置文件

mkdir /etc/uwsgi

vim /etc/uwsgi/uwsgi.ini

 

三、編寫配置文件

[uwsgi]
uid = root
gid = root
socket = 127.0.0.1:9090
master = true                            //啓動主進程
vhost = true         //多站模式

no-site = true        //多站模式時不設置入口模塊和文件
workers = 2          //子進程數
reload-mercy = 10       //平滑的重啓
cacuum = true       //退出、重啓時清楚的文件
max-requests = 1000    //開啓1000個進程後,自動respawn下

limit-as = 512        //將進程的內容內存量控制在512,
buffer-size = 30000
pidfile = /var/run/uwsgi9090.pid
daemonize = /var/log/uwsgi9090.log   //pid文件,用於下面的腳本啓動、中止該進程

pythonpath = /usr/local/python/bin/web/lib/python3.7/site-packages(django在虛環境下)

 

四、開始、關閉

 開 uwsgi --ini /etc/uwsgi/uwsgi.ini 

 關 cat  /var/run/uwsgi9090.pid   返回數字n

  kill -9 數字n

 

五、更改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

 

 

location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
uwsgi_param UWSGI_SCRIPT myweb.wsgi;
uwsgi_param UWSGI_CHDIR /usr/local/nginx/html/myweb;
index index.html index.htm;
client_max_body_size 35m;
}

 

六、將django項目包移至nginx,啓動nginx

mv myweb /usr/local/nginx/html/

/usr/local/nginx/sbin/nginx

相關文章
相關標籤/搜索