方法一:使用xftp工具,進項上傳文件夾,將項目代碼,傳到linux服務器當中html
方式2: 使用scp從本地將文件上傳到linux服務器中vue
scp -r 本地文件夾 遠程用戶名@遠程ip:遠程文件夾/
服務器端安裝mysql(mariadb)數據庫連接:https://www.cnblogs.com/yuncong/p/10253215.htmlnode
數據導入導出python
在linux服務端,mysql,導入knight的數據 1.mysql數據的導出,與導入 這個命令是在linux/windows中敲的 mysqldump -u root -p --all-databases > knight.dump 2.上傳這個數據文件到linux數據庫中 3.在linux的mysql,導入這個數據文件 mysql -uroot -p < /opt/knight.dump
注意:linux的數據庫,須要對root用戶設置遠程連接的權限mysql
grant all privileges on *.* to root@'%' identified by 'redhat'; # 受權全部的權限,在全部庫,全部表 對 root用戶在全部的主機上, 權限密碼爲redhat, 注意是本身設置的密碼 # 刷新受權表 flush privileges;
注意2:linux的防火牆要給關閉,不然windows去連接linux的3306端口可能被拒絕linux
centos7默認已經使用firewall做爲防火牆了 1.關閉防火牆 systemctl status firewalld #查看防火牆狀態 systemctl stop firewalld #關閉防火牆 systemctl disable firewalld#關閉防火牆開機啓動 systemctl is-enabled firewalld.service#檢查防火牆是否啓動
下載node,因爲此包含有node,因此不須要編譯ios
wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz
解壓node源碼包nginx
tar -zxvf node-v8.6.0-linux-x64.tar.gz # 查看 ls # 進入 cd node-v8.6.0-linux-x64/
將node命令加入PATH環境變量中,方便調用redis
vim /etc/profile # 在底行添加代碼 PATH=$PATH:/opt/node-v8.6.0-linux-x64/bin # 保存退出 # 讀出該文件,使其生效 source /etc/profile # 查看該變量看是否成功 echo $PATH # 測試 node -v npm -v
進入到vue項目中,打包node模塊sql
cd 07-luffy_project_01/
安裝vue模塊,默認安裝該目錄中的package.json模塊.若是出錯,請手動安裝
npm install # 該命令執行後會生成node_modules文件
此時注意,你本地寫的vue代碼,接口極可能鏈接的服務器地址有問題,注意Axios.POST提交的地址,必定得發送給django應用(若是用了nginx,就發送給nginx的入口端口)
這裏爲了試驗方便,將vue項目和django項目放在了一臺服務器,經過nginx反向代理功能(8000端口),轉發vue請求給django(9000)
準備編譯打包vue項目,使用sed命令替換配置文件中全部的地址,給爲服務器地址
sed -i 's/127.0.0.1/192.168.11.99/g' /opt/opt/07-luffy_project_01/src/restful/api.js # 將該路徑下的全部127.0.0.1換成192.168.11.99
注意:換成本身的服務器地址,換成本身的服務器地址,換成本身的服務器地址
打包,生成一個dist靜態文件
npm run build # 檢查該文件 ls dist/ # 結果 index.html static
配置完成
mkvirtualenv drf # 進入該虛擬環境 workon drf # 中止該虛擬環境 deactivate
若是未安裝,查看該連接:https://www.cnblogs.com/yuncong/p/10251899.html
解決項目模塊依賴
該項目所需文件
certifi==2018.11.29 chardet==3.0.4 crypto==1.4.1 Django==2.1.4 django-redis==4.10.0 django-rest-framework==0.1.0 djangorestframework==3.9.0 idna==2.8 Naked==0.1.31 pycrypto==2.6.1 pytz==2018.7 PyYAML==3.13 redis==3.0.1 requests==2.21.0 shellescape==3.4.1 urllib3==1.24.1 uWSGI==2.0.17.1
新建文件requirements.txt
touch requirements.txt # 編輯該文件 vim requirements.txt # 插入上訴所需文件
生成項目依賴模塊
pip freeze > requirements.txt
touch requirements.txt
vim requirements.txt
pipenv --python python3
pipenv shell
pipenv install
注意目錄中初始化虛擬環境以前,就要有requirements.txt這個文件,他會將裏面全部的依賴包加載到Pipfile中,而後根據這個文件下載包
新建一個redis-6379.conf,配置文件以下
port 6379 daemonize yes pidfile /data/6379/redis.pid loglevel notice logfile "/data/6379/redis.log" # #這個文件要本身在相應的目錄下建立 dir /data/6379 protected-mode yes
啓動redis服務端
redis-server redis-6379.conf # 這裏是相對路徑,若是不在,起使用絕對路徑
啓動時報錯,若是沒有/data/6379/redis.log,這個文件須要本身建立
查看進程是否啓動
ps -ef|grep redis
在該django虛擬環境中安裝uwsgi
pip3 install uwsgi
使用uwsgi.ini配置文件去啓動項目,這個文件本身去建立便可,放哪均可以,可是放在項目中最好
touch /opt/luffy_boy/uwsgi.ini
配置信息以下
vim uwsgi.ini # 插入信息 [uwsgi] # Django-related settings # the base directory (full path) #寫上項目的絕對路徑 chdir = /opt/vue_drf/luffy_boy # Django's wsgi file #填寫找到django的wsgi文件,填寫相對路徑,以chdir參數爲相對路徑 module = luffy_boy.wsgi # the virtualenv (full path) #填寫虛擬環境的絕對路徑 home = /root/Envs/drf # process-related settings # master #啓動uwsgi主進程 master = true # maximum number of worker processes processes = 5 #若是你使用了nginx,作反向代理,必須填寫socket連接,而不是http參數 # the socket (use the full path to be safe socket = 0.0.0.0:9000 #若是你不用nginx,直接使用uwsgi,運行一個http服務端,就用這個http參數 #http = 0.0.0.0:9000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true
注意: 查看虛擬環境的命令
cdvirtualenv 導航到當前激活的虛擬環境的目錄中,好比說這樣您就可以瀏覽它的 site-packages pwd # 查看 就能看到當前虛擬環境的路徑
啓動django項目
uwsgi --ini uwsgi.ini # 這裏用的是相對路徑,找不到使用絕對路徑
設置django的靜態文件目錄,收集一下
修改項目中settings.py,寫下以下參數
STATIC_ROOT= '/opt/static' #該路徑根據實際放置
使用命令收集django的靜態文件
python manage.py collectstatic
查看django的靜態文件收集目錄
ls /opt/static
配置nginx,進行反向代理,找到uwsgi項目,且配置nginx處理uwsgi的靜態文件
編輯nginx.conf
server { listen 80; #域名 server_name hedouyu.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root /opt/vue_luffy/07-luffy_project_01/dist; index index.html index.htm; } error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 8000; server_name 192.168.11.96; location / { include /opt/nginx1-12/conf/uwsgi_params; uwsgi_pass 0.0.0.0:9000; #root /opt/huya; #index index.html; } location /static { alias /opt/vue_luffy/static; } }
這步要注意本身的路徑,和代理
重啓nginx
./nginx/sbin/nginx -s reload
此時項目就已經徹底能夠運行了
使用supervisor命令,生配置文件
echo_supervisord_conf > /etc/supervisor.conf
在這個配置文件中加入咱們想要管理的任務
vim /etc/supervisor.conf # 在底部寫入以下配置 #定義一個任務,名字自定義 #commnad=參數,定義咱們啓動項目的命令 [program:my_luffy] # uwsgi的絕對路徑和 uwsgi.ini的絕對路徑 command=/root/.local/share/virtualenvs/luffy_boy-8uvrb15Z/bin/uwsgi /opt/luffy_boy/uwsgi.ini stopasgroup=true ;默認爲false,進程被殺死時,是否向這個進程組發送stop信號,包括子進程 killasgroup=true ;默認爲false,向進程組發送kill信號,包括子進程
經過配置文件啓動supervisor服務
supervisord -c /etc/supervisor.conf
啓動了supervisor服務端後,管理任務
supervisorctl -c /etc/supervisor.conf
任務管理命令以下:有兩種,一個是交互式,一個是參數形式
參數形式
supervisorctl -c /etc/supervisor.conf stop/start/restart all supervisorctl -c /etc/supervisor.conf start crm_knight
交互式形式
supervisorctl -c /etc/supervisor.conf
注意,可能在前面配置文件的時候就會啓動項目,形成報錯,那麼就能夠經過如下的命令找出來並殺死進程,而後重啓
netstat -tunlp 查看端口號 ps -ef| grep super 查看supervisor