Linux系統部署Python專案
阿新 • • 發佈:2019-01-05
一、LNM+Python Djiango +uwsgi +redis 部署Python專案
(一)匯入專案以及專案檔案修改
上傳壓縮檔案以及資料庫到/opt (注意要把資料庫建成sql檔案上傳)
然後解壓上傳專案檔案
進入核心目錄(兩次cd mybbs) 注意:自己的專案名
進入設定檔案(vim settings)
進入根目錄下面,配置檔案(注意:配置檔案的資訊要與自己的專案一致)
vim /etc/nginx/conf.d/py.conf server { listen 80; server_name 10.0.0.100; client_max_body_size 100M; location /static { alias /code/BBS/static/; } location /media { alias /code/BBS/media; } location / { index index.html; include uwsgi_params; uwsgi_pass 127.0.0.1:9090; uwsgi_param UWSGI_SCRIPT BBS.wsgi; uwsgi_param UWSGI_CHDIR /code/BBS; }
(二)資料庫的操作
/etc/init.d/mysqld restart 啟動資料庫
systemctl start mysqld
systemctl restart mysqld 重啟資料庫
netstat -tulnp |grep 3306 檢視資料庫是否啟動
注意:如果還是進不去就用資料庫登入的賬戶名和密碼
grant all on *.* to [email protected]'10.0.0.%' identified by '123'; mysql -uroot -p123
進入資料庫以後腰建立一個bbs使用者:
5.8版本下建立和授予許可權可以一起,使用者不在自動建立
5.7下要先建立使用者,後授予許可權
grant select,update,delete ,insert on bbs.* to [email protected]'10.0.0.%' identified by '123';
mysql -ubbs -p123 -h10.0.0.100 bbs使用者登入
drop database bbs; 刪除資料庫裡面的表 create database bbs charset utf8mb4; 再建立一個bbs資料庫,注意編碼格式要和資料庫檔案的編碼格式一致 use bbs; 使用建立庫 use bbs; 匯入指定目錄下的專案資料庫 show tables; 檢視匯入結果
二MySQL使用者操作
使用者定義 : [email protected]‘白名單’
白名單:主機域IP地址
[email protected]‘localhost’ 只允許本機的root使用者進行訪問
[email protected]‘10.0.0.110’ 只允許root使用者通過10.0.0.110地址進行訪問
[email protected]‘10.0.0.%’ 允許10.0.0.N網段的root使用者進行訪問
[email protected]‘10.0.0.0/255.255.240.0’
[email protected]‘10.0.0.5%’ 允許10.0.0.5N ip地址的root使用者進行訪問
[email protected]‘%’ 允許所有root使用者進行訪問
1.許可權操作介紹
- grant all 除root使用者外的最高許可權
- grant selent,update,insert 生產環境下,通常的專案許可權
- 將del操作,替換成update操作 - 使用狀態鏈,1,0表示可否可視
- 注意:也就是新建立一個新的欄位,在查詢的時候根據這個新的欄位進行查詢,需要定期清理欄位的固定屬性
grant select,update,delete ,insert on bbs.* to [email protected]'10.0.0.%' identified by '123';
bbs.*庫的增刪改查許可權,給予[email protected]'10.0.0.%' 進行連結,並建立使用者(建立使用者並授權操作,僅限mysql5.7版本);密碼為123
三.Nginx的配置
檢視nginx是否啟動:systemctl status nginx
啟動nginx:systemctl restart nginx
檢視uwsgi程序情況:ps -ef |grep uwsgi
需要把之前開啟的程序全部關掉:kill -9 ps -ef |grep uwsgi|awk {'print $2'}
在專案的一層目錄下面配置:
[[email protected] BBS]# vim uwsgi.ini
[uwsgi]
socket = 127.0.0.1:9090
master = true
workers = 2
reload-mercy = 10
vacuum = true
max-requests = 1000
limit-as = 512
buffer-size = 30000
最後啟動uginx即可:uwsgi --ini uwsgi.ini &
注意:uwsgi.ini 檔案目錄