ubuntu 安裝mysql+redis+nginx

王竹笙發表於2024-11-08

1. mysql安裝

vim /etc/apt/sources.list

追加一下內容

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# 清華映象源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
sudo apt update    # 更新映象源
# 安裝MySQL5.7(需要輸入兩次mysql的root使用者的密
sudo apt install -y mysql-server-5.7

#密碼
Aisheji%188588

配置開機自啟動

systemctl restart mysql
systemctl enable mysql

2. redis安裝

 sudo apt install redis-server -y

修改配置

vim /etc/redis/redis.conf

# 註釋掉繫結地址#bind 127.0.0.1,讓Redis可遠端訪問
bind 0.0.0.0 ::1

#取消註釋requirepass 啟動密碼認證,並設定訪問密碼
requirepass Z3OvRFiTiKN@8*N18hKDF

# 以守護程序執行Redis 
daemonize yes
systemctl restart redis-server
systemctl enable redis-server

3.安裝nginx

sudo apt install -y nginx
sudo systemctl restart nginx
sudo systemctl enable nginx