● mysqld.service - MySQL Community Server
sudo yum install git
$wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
$sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
$yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 36
mysql-tools-community/x86_64 MySQL Tools Community 47
mysql57-community/x86_64 MySQL 5.7 Community Server 187
$sudo yum install mysql - community - server
$sudo service mysqld start
$sudo systemctl start mysqld #CentOS 7
$sudo systemctl status mysqld
├─2481 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat2017-05-2712:56:26 CST;15s ago
Process:2482ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process:2421ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID:2481(mysqld_safe)
CGroup:/system.slice/mysqld.service
└─2647 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/...
$ wget --no-check-certificate https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz # 下载 Python 源文件
"pkill supervisor"nbsp;mysql -uroot -p
mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
[client]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci #不区分大小写
collation-server = utf8_bin #区分大小写
collation-server = utf8_unicode_ci #比 utf8_general_ci 更准确
mysql > CREATE DATABASE < datebasename > CHARACTER SET utf8;
sudo mkdir /usr/local/python3 # 创建安装目录
$ wget --no-check-certificate https://github.com/pypa/pip/archive/9.0.1.tar.gz
# 注意:wget获取https的时候要加上:--no-check-certifica
$ tar -xzvf Python-3.6.2.tgz # 解压缩包
$ cd Python-3.6.2 # 进入解压目录
sudo ./configure --prefix=/usr/local/python3 # 指定创建的目录
sudo make
sudo make install # 编译安装
$ sudo ln - s / usr / local / python3 / bin / python3 / usr / bin / python3
$ sudo yum -y install epel-release # 首先安装 epel 扩展源
$ sudo yum -y install python-pip # 安装 python-pip
$ sudo yum clean all # 清除 cache
# 下载源代码
command=/home/www/blog/venv/bin/gunicorn -w4 -b0.0.0.0:8000 wsgi:application ;supervisor启动命令
$ tar -zvxf 9.0.1.tar.gz # 解压文件
$ cd pip-9.0.1
$ python3 setup.py install # 使用 Python 3 安装
$ sudo ln - s / usr / local / python3 / bin / pip / usr / bin / pip3
$ pip install--upgrade pip
cd /home/www/blog
mkdir venv
python3 -m venv venv
source venv / bin / activate
pip3 install - r requirements.txt
pip3 install gunicorn
from app import create_app
application = create_app('production')
if __name__ == '__main__':
application.run()
gunicorn - w 4 - b 127.0.0.1 : 8000 wsgi: application
$ yum - y install nginx
$ service nginx start
$ service nginx stop
$ service nginx restart
$ nginx -s reload
server {
listen 80;
server_name adisonhyh.com;
location / {
proxy_pass http: //127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
}
}
$ pip install supervisor
$ echo_supervisord_conf > supervisor.conf # 生成 supervisor 默认配置文件
$ vim supervisor.conf # 修改 supervisor 配置文件,添加 gunicorn 进程管理
[program:blog]
directory=/home/www/blog ; 项目的文件夹路径
startsecs=0 ; 启动时间
stopwaitsecs=0 ; 终止等待时间
autostart=false ; 是否自动启动
autorestart=false ; 是否自动重启
stdout_logfile=/home/www/blog/logs/gunicorn.log ; log 日志
stderr_logfile=/home/www/blog/logs/gunicorn.err ; 错误日志
$ sudo supervisord -c supervisor.conf
$ sudo supervisorctl start blog
pip install fabric
import os
from fabric.api import local, env, run, cd, sudo, prefix, settings, execute, task, put
from fabric.contrib.files import exists
from contextlib import contextmanager
env.hosts = ['204.152.201.69']
env.user = 'root'
env.password = '****'#密码
env.group = "root"
DEPLOY_DIR = '/home/www/blog'
VENV_DIR = os.path.join(DEPLOY_DIR, 'venv')
VENV_PATH = os.path.join(VENV_DIR, 'bin/activate')
@contextmanager
def source_virtualenv():
with prefix("source {}".format(VENV_PATH)):
yield
def update():
with cd('/home/www/blog/'):
sudo('git pull')
def restart():
with cd(DEPLOY_DIR):
if not exists(VENV_DIR):
run("virtualenv {}".format(VENV_DIR))
with settings(warn_only=True):
with source_virtualenv():
run("pip install -r {}/requirements.txt".format(DEPLOY_DIR))
with settings(warn_only=True):
stop_result = sudo("supervisorctl -c {}/supervisor.conf stop all".format(DEPLOY_DIR))
if not stop_result.failed:
kill_result = sudo("pkill supervisor")
if not kill_result:
sudo("supervisord -c {}/supervisor.conf".format(DEPLOY_DIR))
sudo("supervisorctl -c {}/supervisor.conf reload".format(DEPLOY_DIR))
sudo("supervisorctl -c {}/supervisor.conf status".format(DEPLOY_DIR))
sudo("supervisorctl -c {}/supervisor.conf start all".format(DEPLOY_DIR))
@task
def deploy():
execute(update)
execute(restart)
fab deploy
来源: https://juejin.im/post/5a5a7fce6fb9a01caa207d1d