赞
踩
- #下载
- wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
- #安装数据源
- yum install mysql80-community-release-el8-1.noarch.rpm
- #检查数据源
- yum repolist enabled | grep "mysql.*-community.*"
- #禁用CentOS8自带mysql模块
- yum module disable mysql
- #安装数据库
- yum install mysql-community-server
- # 上面的不成功用下面的这个命令
- yum install mysql-community-server --nogpgcheck
- #启动mysql
- service mysqld start
- service mysqld status
- #显示mysql的随机密码
- grep 'temporary password' /var/log/mysqld.log
- #登录mysql
- mysql -u root -p
- #修改密码
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test_123456';
- #查看密码策略
- SHOW VARIABLES LIKE 'validate_password%';
- #开放远程访问
- #1.创建权限用户记录
- create user 'root'@'%' identified by 'Test_123456';
- #2. 授权
- grant all privileges on *.* to 'root'@'%' with grant option;
- #开放3306端口
- # 安装Django
- pip3 install Django
-
- # 安装mysqlclient
- yum install mysql-devel
- pip3 install mysqlclient
sudo yum install gcc python3-devel
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple uWSGI==2.0.19.1
- [uwsgi]
- #项目目录
- chdir = /home/YanServer
- file = /home/YanServer/YanServer/wsgi.py
- master = True
- # 进程数
- processes = 4
- # 线程数
- threads=2
- max-requests = 5000
- #使用nginx连接时使用,Django程序所在服务器地址
- socket = 127.0.0.1:8002
- uid = 1000
- gid = 2000
-
- # 存放进程编号的文件
- pidfile=uwsgi.pid
-
- # vim /etc/sysctl.conf 在文件最后添加一行记录net.core.somaxconn = 1024
- # 执行sysctl -p重新load参数设置,这样会立即生效,并且以后重新启动机器也会生效。
- # listen=1024
-
- # 指定依赖的虚拟环境
- ;virtualenv=/server
-
- # websocket支持
- # http-websockets=true
-
- # 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的
- daemonize=uwsgi.log
注意打开服务器安全组80端口
- # 安装
- sudo yum install -y nginx
-
- #
- sudo systemctl enable nginx
-
- # 启动NGINX
- sudo systemctl start nginx
-
- # NGINX启动状态
- sudo systemctl status nginx
-
- # 停止NGINX服务器
- sudo systemctl stop nginx
-
- # 重启
- sudo systemctl start nginx
-
- # NGINX修改,重新加载它而不必停止并重新启动
- sudo systemctl reload nginx
centos安装完Nginx后,/etc/nginx/下没有sites-available 和 sites-enabled目录,自行创建,唯一注意的是需要再/etc/nginx/nginx.conf中添加:
include /etc/nginx/sites-enabled/*;
完整的/etc/nginx/nginx.conf环境:
- user www-data;
- worker_processes auto;
- pid /run/nginx.pid;
- include /etc/nginx/modules-enabled/*.conf;
-
- events {
- worker_connections 768;
- # multi_accept on;
- }
-
- http {
-
- ##
- # Basic Settings
- ##
-
- sendfile on;
- tcp_nopush on;
- tcp_nodelay on;
- keepalive_timeout 65;
- types_hash_max_size 2048;
- # server_tokens off;
-
- # server_names_hash_bucket_size 64;
- # server_name_in_redirect off;
-
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
-
- ##
- # SSL Settings
- ##
-
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
- ssl_prefer_server_ciphers on;
-
- ##
- # Logging Settings
- ##
-
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log;
-
- ##
- # Gzip Settings
- ##
-
- gzip on;
-
- # gzip_vary on;
- # gzip_vary on;
- # gzip_proxied any;
- # gzip_comp_level 6;
- # gzip_buffers 16 8k;
- # gzip_http_version 1.1;
- # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
-
- ##
- # Virtual Host Configs
- ##
-
- include /etc/nginx/conf.d/*.conf;
- include /etc/nginx/sites-enabled/*;
-
-
-
- server {
- listen 443 ssl; # 1.1版本后这样写
- server_name www.yanfriends.com; #填写绑定证书的域名
- ssl_certificate /etc/nginx/cert/4147706_www.xxx.com.pem; # 指定证书的位置,绝对路径
- ssl_certificate_key /etc/nginx/cert/4147706_www.xxx.com.key; # 绝对路径,同上
- ssl_session_timeout 5m;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
- ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #密码加密方式
- ssl_prefer_server_ciphers on; #依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码
- # ssl on; #开启ssl 这个不注释将只能通过https访问
-
- # location / {
- # root html; #站点目录,绝对路径
- # index index.html index.htm;
- # }
-
- location /static {
- alias /home/YanServer/static; # 指向django的static目录
- }
-
- #其他文件转wsgi处理
- location / {
- uwsgi_pass 127.0.0.1:8002;
- include /etc/nginx/uwsgi_params;
- }
- }
-
- }
注意2个目录sites-available/,sites-enabled/,2个文件nginx.conf,uwsgi_params
sites-available/ 这个文件夹的作用就是放置我们设置的文件,可以写很多设置文件放在这里备用,不影响nginx的运行
sites-enabled/ 这个文件夹的作用是,放我们将要启动的设置文件(通常的做法是,通过在site-available/里的设置文件,创建一个软链接放在sites-enabled,)
uwsgi_params 程序nginx就是通过这个uwsgi_params配合我们刚刚设置的8002端口和uwsgi进行通信。
现在cd 进sites-available/创建我们的配置文件
~# cd /etc/nginx/sites-available/
~# vim your_project_nginx.conf
- server {
- listen 8001;
- server_name abqqe;
- charset utf-8;
- client_max_body_size 75M;
-
- location /static {
- alias /path-of-your-project/project/static;
- }
-
- location /media {
- alias /path-of-your-project/project/media;
- }
-
- location / {
- uwsgi_pass 127.0.0.1:8002;
- include /etc/nginx/uwsgi_params;
- }
- }
参数说明listen 8001 表示对外监听8001端口,你的网站通过8001这个端口通信;
server_name 域名,例如qq.com这种,如果没有就随便打一个,不影响nginx运行;
location /static 表示静态文件的放置路径;
location /media 表示客户上传文件的放置路径;
location / 表示和uwsgi的通信,uwsgi_pass 127.0.0.1:8002 通过环回接口127.0.0.1和刚刚uwsgi设置的8002端口,与本机的程序uwsgi进行通信,include 另外带上这个文件; /etc/nginx/uwsgi_params,是和uwsgi通信的一些设置;
your_project_nginx.conf文件写好之后创建软链接(创建快捷方式放到sites-enabled/);
~# ln -s /etc/nginx/sites-available/your_project_nginx.conf /etc/nginx/sites-enabled/your_project_nginx.conf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。