Mac 和 Ubuntu server 配合,开发环境准备

需求

新买的 mac 作为主要办公电脑,老旧联想电脑安装 ubuntu server 版,实现 mac 远程连接 ubuntu 服务器,在 ubuntu 服务上搭建基本的开发环境,在 mac 上开发代码,且代码在 Ubuntu 服务上跑起来,mac 可访问我们开发的服务。

前置条件

Macbook 安装好了 brew,并通过 brew 安装好了 telnet,ssh 等必要软件。

步骤

制作 u 盘启动盘

准备一个 u 盘,下载 ultraISO 工具,我是在 windows 环境里做的。

UltraISO(软碟通)制作U盘启动盘完整教程

安装 u 盘系统至电脑中

Ubuntu20详细安装步骤

使用 mac 远程连接 ubuntu 服务器,配置 ubuntu 系统

一开始还不能连上 ubuntu 电脑,ubuntu 电脑需要装一些程序。

# ifconfig 命令查看 ubuntu 服务器 ip

sudo apt install net-tools

# 使得 mac 可以 ssh 登录访问 ubuntu

sudo apt install openssh-server

# 防火墙相关设置

sudo apt-get install ufw

# 打开防火墙

sudo ufw enable

# 允许 22 端口被外部访问

sudo ufw allow 22

# 查看是否开启自动休眠

sudo systemctl status sleep.target

# 关闭自动休眠

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

Mac 上安装 nuoshell。https://www.nuoshell.com,远程连接 Ubuntu 服务器。

Ubuntu 分区

xiaobaiyang@ubuntu2004server:~$ sudo fdisk --listDisk /dev/loop0: 61.98 MiB, 64966656 bytes, 126888 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop1: 67.83 MiB, 71106560 bytes, 138880 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop2: 46.98 MiB, 49242112 bytes, 96176 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sda: 232.91 GiB, 250059350016 bytes, 488397168 sectorsDisk model: Samsung SSD 860 Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: A2E93EDD-38EE-46B6-BE79-AA584ABC309FDevice      Start      End  Sectors  Size Type/dev/sda1    2048      4095      2048    1M BIOS boot/dev/sda2    4096  4198399  4194304    2G Linux filesystem/dev/sda3  4198400 488394751 484196352 230.9G Linux filesystemDisk /dev/mapper/ubuntu--vg-ubuntu--lv: 100 GiB, 107374182400 bytes, 209715200 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesxiaobaiyang@ubuntu2004server:~$ sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv  New size (59105 extents) matches existing size (59105 extents).xiaobaiyang@ubuntu2004server:~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

ubuntu  虚拟机磁盘扩容

在 mac 上进行操作,安装 Python 环境

安装 virtualenv,Python,生成 ssh 公钥,拉取代码,然后安装环境,运行 web 服务,并在 mac 上访问。

VS  Code 远程登录 ubuntu server

前提条件是 mac 上安装好了 VS Code 和 Remote-SSH 插件

#1 先在 mac 上生成 ssh 公钥

xiaobaiyang@192 ~ % ssh-keygen

#2 打开 id_rsa.pub,拷贝出 ssh 公钥

xiaobaiyang@192 .ssh % ls

config                id_rsa                id_rsa.pub        known_hosts        known_hosts.old

#3 将 mac 的 ssh 公钥复制到 ubuntu server 的 .ssh 目录下的 authorized_keys 中

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容