概述:
此文记录我如何在一台全新的腾讯云主机上部署一个flask web,
一般我们的博客都会在完成后整理成一个最优解,但
这篇文章我不准备做任何整理,完全展现我部署的整个思维方式,希望给更多的人一种另外一种启示
nginx安装
#nginx 编译依赖库
1.yum install pcre pcre-devel
2. yum install openssl openssl-devel
#nginx 下载网址
http://nginx.org/download/nginx-1.15.10.tar.gz
#创建nginx账号
useradd nginx -s /sbin/nologin -M # -M 不创建家目录 -s /sbin/nologin 禁止shell登录
#解压
tar -zxvf nginx-1.15.10.tar.gz
#编译,安装目录/usr/local/app/nginx/
./configure --user=nginx --group=nginx --prefix=/usr/local/app/nginx/ --with-http_stub_status_module --with-http_ssl_module
#编译显示的信息
nginx path prefix: "/usr/local/app/nginx/"
nginx binary file: "/usr/local/app/nginx//sbin/nginx"
nginx modules path: "/usr/local/app/nginx//modules"
nginx configuration prefix: "/usr/local/app/nginx//conf"
nginx configuration file: "/usr/local/app/nginx//conf/nginx.conf"
nginx pid file: "/usr/local/app/nginx//logs/nginx.pid"
nginx error log file: "/usr/local/app/nginx//logs/error.log"
nginx http access log file: "/usr/local/app/nginx//logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"#
#测试nginx
cd /usr/local/app/nginx/sbin
./nginx -t
nginx: the configuration file /usr/local/app/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/app/nginx//conf/nginx.conf test is successful#nginx 重载命令
nginx -s reload
#放通80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#nginx 配置
去掉#和空行 生成 新的 nginx.conf 配置文件
egrep -v "#|^$" nginx.conf.bak >nginx.conf# nginx配置文件如下
[root@VM_0_12_centos conf]# pwd /usr/local/app/nginx/conf [root@VM_0_12_centos conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_buffer_size 4k; proxy_buffers 4 32k ; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; #root html; #index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } [root@VM_0_12_centos conf]#
vim设置4空格
在修改nginx 配置的时候,tab键不是4空格就顺手改了
#vim 简单配置 设置tab键为4个空格
cp /etc/vimrc ~/.vimrc
set ts=4
python 安装
#linux python 安装 linux 可以通过wget 下载安装包,但是下载太慢了,我就本地开代理下载后,直接通过scp上传的
1.wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz #云主机wget太慢2.scp ./Python-3.6.5.tgz root@148.70.xxx.22:~ #scp上传python安装包
#解压
tar -zxvf Python-3.6.5.tgz
cd Python-3.6.5#配置-编译-安装
./configure --prefix=/usr/local
make&&make install#
python3.6程序的执行文件:/usr/local/bin/python3.6
python3.6应用程序目录:/usr/local/lib/python3.6
pip3的执行文件:/usr/local/bin/pip3.6
#
git安装
yum install git
#安装git 的原因我想直接在github clone web工程,后来发现速度太太慢了,后来还是自己本地上传的
gunicorn 安装
#安装
pip3 install gunicorn
启动命令
gunicorn -w 2 -D --log-level info --access-logfile /usr/local/app/gun_log/access.log --error-logfile /usr/local/app/gun_log/error.log -b 127.0.0.1:8000 blog:app
-w 进程数
-b 设置端口-D 后台启动
mysql安装
在gunicorn 启动后,远程访问,报错了,才想起来mysql 没有安装。。。。。
#通过yum 安装,简单粗暴,但是我想安装5.7的mysql 所以我手动通过方式二安装的mysql
yum install mysql方式二:
# groupadd mysql
# useradd -s /sbin/nologin -g mysql -M mysql#安装mysql
# wget https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
# yum -y localinstall mysql57-community-release-el7-8.noarch.rpm
# yum -y install mysql-community-server#启动
service mysqld start #我习惯这种方式启动mysql
systemctl start mysqld
systemctl restart mysqld#开机启动
systemctl enable mysqldsystemctl daemon-reload
#mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。
vi /var/log/mysqld.log
1 [Note] A temporary password is generated for root@localhost: d6#(*YXu!x92
#mysql -u root -p
修改root 密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你自己的密码';
授权远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Onionxxxxxx' WITH GRANT OPTION;
查看编码
mysql> show variables like '%character%';mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
修改mysql编码
# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'#修改后记得重启mysql,
登录mysql 创建blog数据库
mysql> create database blog;
进入工程生成数据
cd /home/onion/project/blog/app
python3 data_fake.py #执行报错app 找不到
手动在data_fake.py 中加入如下几行
import sys sys.path.append("/home/onion/project/blog")
自此 整个工程部署完成
后记
点击左上角onion博客,会弹出登录界面,
账号:zhou@foxmail.com
密码:zhou