一 、安装MySql
1. 新系统需要安装一下更新
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 reloadservice 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
