Ubuntu 安装Mysql+Redis+Nginx

一 、安装MySql

1. 新系统需要安装一下更新

bash 复制代码
apt update -y
apt dist-upgrade -y 
apt install -y wget 

2. 安装mysql,并修改配置
apt install -y mysql-server

mysql配置文件通常位于
vi /etc/mysql/mysql.conf.d/mysqld.cnf

[mysqld]把bind 改成0.0.0.0,增加连接数,修改mode,开启默认鉴权插件,最后加上编码配置:

复制代码
bind            = 0.0.0.0 #开启远程访问,看实际需要开启
max_connections = 10000  
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION  
default_authentication_plugin = mysql_native_password  
[mysql]  
default-character-set = utf8  

3. 安装成功后重启mysql服务
systemctl restart mysql

4. 初次安装mysql,root账户重置密码(初始的root用户 本地登录是不需要密码的)

sudo mysql -uroot

开始修改密码,因为策略问题,先设置一个符合复杂策略的密码,否则无法做其他操作:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword';

查看账户信息:

mysql> use mysql

mysql> select host, user, authentication_string, plugin from user;

5. 创建其他帐号并且外网可以访问:

mysql> CREATE USER 'test'@'%' IDENTIFIED BY 'YourPassword';

mysql> ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'YourPassword';

mysql> grant all privileges on *.* to 'test'@'%';

mysql> flush privileges;

二 、安装Redis

1. 在线安装

apt install -y redis-server

2. 修改 redis.conf 文件,必须开启持久化

vi /etc/redis/redis.conf

复制代码
################################## NETWORK #####################################  
bind 127.0.0.1 -::1   # 将这行代码注释,监听所有的ip地址,外网可以访问  
protected-mode no     # 把yes改成no,允许外网访问  
################################# GENERAL #####################################  
daemonize yes         # 把no改成yes,后台运行  
requirepass YourPassword #去掉前面的井号,并修改密码    
############################## APPEND ONLY MODE ###############################  
appendonly yes        # 把no改成yes,开启持久化  
#appendfsync always  
appendfsync everysec  #设置持久化的方式  
#appendfsync no  

3. 创建 redis 命令软链接
ln -s /usr/bin/redis-cli /usr/bin/redis

通过命令 登录redis测试
redis -a Oatos@123
127.0.0.1:6379> exit
4. 服务操作命令

复制代码
systemctl start redis.service   #启动redis服务  
systemctl stop redis.service   #停止redis服务  
systemctl restart redis.service   #重新启动服务  
systemctl status redis.service   #查看服务当前状态  
systemctl enable redis.service   #设置开机自启动  
systemctl disable redis.service   #停止开机自启动  

三、安装Nginx

1. Ubuntu 安装比较简单:
apt-get install nginx

2. 查找一下安装的目录与查状态

whereis nginx
systemctl status nginx

3. nginx文件安装完成之后的文件位置

/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志

复制代码
service nginx start
service nginx stop
service nginx reload

service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}

4. Nginx设置成服务并开机自动启动

systemctl enable nginx

5. 80和443端口相关配置

通过nginx的反省代理访问dotnet服务

vi /etc/nginx/conf.d/myapp.conf

80端口

复制代码
server {  
        listen       80;  
        server_name  xxx.com;  
        proxy_http_version 1.1;
        client_max_body_size    32m;  
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        location / {
            root   /path/web/html;#如果是前后的分离,这里可以填前端的路径,这样子前端就不会有跨域的问题
            index  index.html;
        }  
 location /api {
            proxy_pass http://127.0.0.1:5896; #dotnet服务的地址
        } 
        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {
            root   /usr/share/nginx/html;
        } 
    }  

443端口

复制代码
  server {  
        listen 443 ssl;
        server_name  xxx.com;
        ssl_certificate conf.d/ssl/xxx.com.pem;# 注意该SSL证书路径
        ssl_certificate_key conf.d/ssl/xxx.com.key;#注意该SSL证书路径
        proxy_http_version 1.1;
        client_max_body_size    32m;  
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        location / {
            root   /path/web/html;#如果是前后的分离,这里可以填前端的路径,这样子前端就不会有跨域的问题
            index  index.html;
        }  
 location /api {
            proxy_pass http://127.0.0.1:5896; #dotnet服务的地址
        } 

        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {
            root   /usr/share/nginx/html;
        }  
    } 

6. 测试一下配置

/usr/sbin/nginx -t
/usr/sbin/nginx -s reload 或者 service nginx reload

相关推荐
simple_whu40 分钟前
Ubuntu24.04编译ORB_SLAM的一系列报错解决
ubuntu·slam
我不是秃头sheep43 分钟前
Ubuntu 安装 Docker(镜像加速)完整教程
linux·ubuntu·docker
进击的CJR43 分钟前
MySQL 8.0 OCP 英文题库解析(三)
android·mysql·开闭原则
JhonKI1 小时前
【MySQL】变更缓冲区:作用、主要配置以及如何查看
数据库·mysql
老李不敲代码2 小时前
榕壹云打车系统:基于Spring Boot+MySQL+UniApp的开源网约车解决方案
spring boot·mysql·微信小程序·uni-app·软件需求
小猪写代码2 小时前
Ubuntu 系统默认已安装 python,此处只需添加一个超链接即可
linux·python·ubuntu
杨凯凡3 小时前
MySQL入门指南:环境搭建与服务管理全流程
数据库·mysql
有谁看见我的剑了?3 小时前
ubuntu 22.04 wifi网卡配置地址上网
linux·运维·ubuntu
码农新猿类4 小时前
Ubuntu摄像头打开失败
linux·运维·ubuntu
qq_441685754 小时前
King3399(ubuntu文件系统)KGDB配置与功能测试
ubuntu