wsl的设置

如何安装wsl看官方文档:

https://docs.microsoft.com/zh-cn/windows/wsl/install-win10

更改源, 换成清华源

更改源, 换成清华源, 参考Ubuntu 镜像使用帮助

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list


# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

系统更新

sudo apt-get update
sudo apt-get upgrade

开启ssh

  • 安装
sudo apt-get remove openssh-server
sudo apt-get install openssh-server
  • 修改配置,
sudo vim /etc/ssh/sshd_config
Port 2222
PasswordAuthentication yes
  • 启动
sudo service ssh --full-restart

安装mysql

  • 安装
sudo apt-get update
sudo apt-get install mysql-server
  • 配置.
sudo service mysql start

在mysql5.7默认root使用socket连接…只能用sudo mysql连接..使用mysql -u root -p 没有用处

sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;
Output
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

FLUSH PRIVILEGES;

SELECT user,authentication_string,plugin,host FROM mysql.user;

Output
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)


mysql -u root -p
输入密码

删除mysql

sudo apt-get remove --purge 'mysql*'
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean

安全处理

sudo mysql_secure_installation

.启动mysql时,输出No directory, logging in with HOME=/这个是由于mysql日志输出的目录没有权限导致的,使用命令即可解决:

sudo usermod -d /var/lib/mysql/ mysql

更换数据库目录的话,得初始化

mysqld --initialize

允许远程连接

RENAME USER 'root'@'localhost' TO 'root'@'%';
FLUSH PRIVILEGES;

安装redis

  • 安装
sudo apt-get install redis-server
  • 配置远程访问
sudo vim /etc/redis/redis.conf

找到并注释掉下面一行, 或者把127.0.0.1改成0.0.0.0

# bind 127.0.0.1
  • 开启服务
sudo service redis-server start

开机启动



vi ~/start_up.sh 
echo "检测开机启动项"
if [ ! -e "/var/run/sshd.pid" ]; then
    echo '启动sshd'
    service ssh start
fi

if test $( pgrep -f mysql | wc -l ) -lt 1
    then
    echo "启动mysql"
    service mysql start
fi

if test $( pgrep -f redis | wc -l ) -lt 1
    then
    echo "启动redis"
    service redis-server start
fi
sudo visudo
zhepama ALL=(ALL) NOPASSWD: ALL
%sudo   ALL=(ALL:ALL) NOPASSWD: ALL

  • https://zhuanlan.zhihu.com/p/42514711
  • https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
  • https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04

发表评论