本文主要包括:
- 安装并配置
oh my zsh
- 安装并配置java
- mac环境下Sublime使用技巧
- Mac常用快捷键
最近新买了MacBook,但是刚从Windows切换到Mac OS系统感觉很不适应,记录一下适应的过程
Mac下必备软件
- the unarchiver: 无感解压
- 有道云笔记
- IDEA
- 大数据相关软件
- Iterm2 && oh my zsh
- sublime
- 百度云网盘
- Snipaste:截图神器
- Tabby :Xshell的替代工具,有了它可以也不需要Iterm2了
安装并配置oh my zsh
Mac自带的终端界面体验实在不敢恭维。这里记录一下安装oh my zsh
的过程
- 首先确保当前shell是zsh,如果不是,使用
chsh -s /bin/zsh
- 用自己的git fork一下
ohmyzsh/ohmyzsh
,然后从自己的git仓库clone下来,这样快一点
Iterm2快捷键:## clone程序 git clone git@github.com:gujincheng/ohmyzsh.git ~/.oh-my-zsh ## 编辑.zshrc cp ~/.oh-my-zsh/templates ~/.zshrc ## 修改主题为arrow ZSH_THEME="arrow" ## 安装常用插件 plugins=(git zsh-autosuggestions zsh-syntax-highlighting) ## 安装插件的时候,可以把插件fork到自己的git上,然后从自己的git上clone到~/.oh-my-zsh/custom/plugins ``` * .zshrc完整配置: ```shell # If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. export ZSH=$HOME/.oh-my-zsh # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes #ZSH_THEME="robbyrussell" #ZSH_THEME="essembeh" ZSH_THEME="arrow" # Set list of themes to pick from when loading at random # Setting this variable when ZSH_THEME=random will cause zsh to load # a theme from this variable instead of looking in $ZSH/themes/ # If set to an empty array, this variable will have no effect. #ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true" # Uncomment the following line to use hyphen-insensitive completion. # Case-sensitive completion must be off. _ and - will be interchangeable. # HYPHEN_INSENSITIVE="true" # Uncomment the following line to disable bi-weekly auto-update checks. # DISABLE_AUTO_UPDATE="true" # Uncomment the following line to automatically update without prompting. # DISABLE_UPDATE_PROMPT="true" # Uncomment the following line to change how often to auto-update (in days). # export UPDATE_ZSH_DAYS=13 # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS="true" # Uncomment the following line to disable colors in ls. # DISABLE_LS_COLORS="true" # Uncomment the following line to disable auto-setting terminal title. # DISABLE_AUTO_TITLE="true" # Uncomment the following line to enable command auto-correction. # ENABLE_CORRECTION="true" # Uncomment the following line to display red dots whilst waiting for completion. # Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) # See https://github.com/ohmyzsh/ohmyzsh/issues/5765 # COMPLETION_WAITING_DOTS="true" # Uncomment the following line if you want to disable marking untracked files # under VCS as dirty. This makes repository status check for large repositories # much, much faster. # DISABLE_UNTRACKED_FILES_DIRTY="true" # Uncomment the following line if you want to change the command execution time # stamp shown in the history command output. # You can set one of the optional three formats: # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" # or set a custom format using the strftime function format specifications, # see 'man strftime' for details. # HIST_STAMPS="mm/dd/yyyy" # Would you like to use another custom folder than $ZSH/custom? # ZSH_CUSTOM=/path/to/new-custom-folder # Which plugins would you like to load? # Standard plugins can be found in $ZSH/plugins/ # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. plugins=(git zsh-autosuggestions zsh-syntax-highlighting) source $ZSH/oh-my-zsh.sh # User configuration # export MANPATH="/usr/local/man:$MANPATH" #JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home MAVEN_HOME=/opt/modules/apache-maven-3.8.1 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar NODE_HOME=/opt/modules/node-v14.16.1 SCALA_HOME=/opt/modules/scala-2.12.13 HADOOP_HOME=/opt/modules/hadoop-3.2.2 HIVE_HOME=/opt/modules/hive-3.1.2 SPARK_HOME=/opt/modules/spark-3.1.1 HBASE_HOME=/opt/modules/hbase-2.3.5 FLINK_HOME=/opt/modules/flink-1.12.2 ZK_HOME=/opt/modules/zookeeper-3.6.3 export JAVA_HOME=$JAVA_HOME PATH=$JAVA_HOME/bin:$PATH:$MAVEN_HOME/bin:$PATH:$NODE_HOME/bin:$PATH PATH=$SCALA_HOME/bin:$PATH:$HADOOP_HOME/bin:$PATH:$SPARK_HOME/bin:$PATH PATH=$HIVE_HOME/bin:$HBASE_HOME/bin:$PATH:$FLINK_HOME/bin:$PATH:$ZK_HOME/bin:$PATH PATH=$PATH:/usr/local/mysql/bin export PATH export LANG=zh_CN.UTF-8 alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs" # You may need to manually set your language environment # export LANG=en_US.UTF-8 # Preferred editor for local and remote sessions # if [[ -n $SSH_CONNECTION ]]; then # export EDITOR='vim' # else # export EDITOR='mvim' # fi # Compilation flags # export ARCHFLAGS="-arch x86_64" # Set personal aliases, overriding those provided by oh-my-zsh libs, # plugins, and themes. Aliases can be placed here, though oh-my-zsh # users are encouraged to define aliases within the ZSH_CUSTOM folder. # For a full list of active aliases, run `alias`. # # Example aliases # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh"
- Command + N : 新建tab页
- Command + Enter : 全屏/退出全屏
Mac使用ssh-agent登陆远程服务器
该功能类似SecureCRT里的Tools-Manage Agent Keys
eval `ssh-agent`
## id_rsa_work为之前保存的私钥文件
ssh-add ~/.ssh/id_rsa_work
但是,这种方式有一个缺点,每次打开终端都要执行一次,这里把它加载到环境变量里
在.zshrc里添加一下内容:
eval `ssh-agent` > /dev/null
ssh-add ~/.ssh/id_rsa_work > /dev/null
安装并配置java
mac下安装java很简单,但是配置java的环境变量,被恶心到了,找不到java的安装路径
- 首先到官网上下载java安装包,注意,下载那个大的,也就是200多M的文件,下载小的,不包含jdk
- 查找JDK安装目录
## 执行如下命令 /usr/libexec/java_home -V ## 该命令会把机器上所有的java版本都列出来,因为我之前先安装了一个不包含jdk的java,就导致我这里有两个java ## 但是很明显,我需要的jdk是下面的那个 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home ## 自己跟着网上安装了一次jdk11,但是找不到tools.jar和dt.jar,在idea中调试代码的时候,一直报错,最终放弃了 ## 之后有空再试试
有2个java是因为一开始装的java不是jdk,是jre,而且两个的版本不一样。
mac环境下Sublime使用技巧
命令行使用Sublime打开文件
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
Sublime列式编辑
按住鼠标中键,或者按住command
使用鼠标选择文本Sublime查找与替换快捷键
- 查找:
command + F
- 替换:
command +shift + F
,需要注意是否忽略大小写,是否正则匹配
- 查找:
Sublime使用home/end快捷键到行首行尾
[ { "keys": ["ctrl+shift+t"], "command": "toggle_terminus_panel" }, { "keys": ["home"], "command": "move_to", "args": {"to": "bol", "extend": false}}, { "keys": ["end"], "command": "move_to", "args": {"to": "eol", "extend": false} } ]
Sublime配置文件:
{ "theme": "Default.sublime-theme", "translate_tabs_to_spaces": true, "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", "font_face": "Courier New", "font_size": 18, "ignored_packages": [ "Vintage", ], }
Sumblime JSON格式化
安装Pretty JSON插件,command + shift + p,搜索 package install,进入后选择pretty json并安装
在sumblime里添加快捷键配置{ "keys": ["ctrl+command+j"], "command": "pretty_json" },
Sublime Text3 成对括号高亮显示
具体可以参考Sublime Text3 成对括号高亮显示
BracketHighlighter的配置:{ "bracket_styles": { "default": { "icon": "dot", // BH1's original default color for reference "color": "entity.name.class", //"color": "brackethighlighter.default", "style": "block" }, } }
Sublime Text3
关闭vim模式
在使用Sublime Text过程中,如果不小心按下Esc键就会进入command mode(Vim模式),之后就出现不能输入任何东西,关闭当前编辑文件重新打开可以解决。但是很影响连贯性,所以可以通过以下方法解决:// 关闭Vim模式,防止Sublime Text使用过程中进入Vim模式 "ignored_packages": [ "Vintage" ]
这里需要删除ChineseLocalization插件,有个bug,可以改成zam1024t/LocalizedMenu
Sublime Text3 高亮选中的所有文本
安装一个word highlight的插件. 安装插件见其他经验{ "color_scope_name": "wordhighlight", //"case_sensitive": false, "draw_outlined": false, "mark_occurrences_on_gutter" : true, // valid types: dot, circle, bookmark and cross "icon_type_on_gutter" : "circle", "highlight_delay": 0, "highlight_when_selection_is_empty": false, "highlight_word_under_cursor_when_selection_is_empty": false, "highlight_non_word_characters": false, "file_size_limit": 4194304, "when_file_size_limit_search_this_num_of_characters": 20000 }
highlight_non_word_characters
: 这个选项如果为true,只要选定一个单词,就会把全文这个单词都高亮,很干扰人,最好设置为false
默认的颜色不好看,是灰色的,不是很突出,这里可以定制化配色
Prefrence -> 定制配色方案 ->
// Documentation at https://www.sublimetext.com/docs/color_schemes.html
{
"variables":
{
},
"globals":
{
},
"rules":
[
{
"name": "WordHighlight",
"scope": "wordhighlight",
"foreground": "var(orange3)"
},
]
}
mac 安装homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Mac安装mysql
具体参考
mac 安装mysql详细教程
Mac常用快捷键
Mac系统快捷键设置:
系统偏好设置 -> 键盘 -> 快捷键command + 左右方向键
: 到句首/尾(下一个/上一个标点符号)option + 左右方向键
:跳到行首/行尾ctrl + 左右方向键
:切换后台进程(窗口),是直接上一个/下一个窗口ctrl + 上下方向键
: 呼出所有后台进程(窗口)shift + 中/英
:切换大小写command + tab
:切换后台进程,按住command会有所有后台,然后按tab可以切换(只是图标)command + 上下方向键
:进入上层文件夹(在访达里使用)ctrl + command + Q
: 锁屏command + 空格
:聚焦搜索option + command + 空格
:在访达里搜索option + command + D
:显示/隐藏程序坞shift + command + 2
:截图到剪切板option + command + T
:自动生成try catchcommand + 7
: 打开/关闭structurectrl + option + o
: 自动删除java不用了的packageTab
: 所选区域整体后移Shift + Tab
: 所选区域整体前移command + k,command + U
:所选区域全部大写command + k,command + L
:所选区域全部小写
开启 HIDPI,让 2K 显示器更舒适
mac自带的屏幕太小了,自己买的外接显示器是2k的,mac不会自动启动hidpi,所以字特别小,不好看。这里强行让mac知道可以启用hidpi
具体可以参考:
为 macOS 10.15 开启 HiDPI,让 2K 显示器更舒适
Mac安装Hadoop、hive遇到的问题
具体的配置,会放到github上,之后再换电脑,直接从git上clone即可
运行start-all.sh,报异常
golden-02: ssh: connect to host golden-02 port 22: Connection refused
原因: mac原本没有打开远程访问的权限,即ssh到本机不通。
解决方法:系统偏好设置->共享->远程登录golden-02: gujincheng@golden-02: Permission denied (publickey,password,keyboard-interactive).
原因:没有配置ssh免密钥
解决方法:cd ~/.ssh && cat id_rsa.pub >> authorized_keys在HDFS管理页面,查看/tmp目录出现没有权限访问
原因:core-site.xml的默认配置
hadoop.http.staticuser.user=dr.who
解决方法:在core-site.xml添加如下内容:<property> <name>hadoop.http.staticuser.user</name> <value>gujincheng</value> </property>
不需要重新初始化namenode(
hdfs namenode -format
)hive报错:
HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
原因:安装包是直接复制过来的,mysql虽然重新安装了,但是hive的元数据没有重新初始化
解决方法:schematool -dbType mysql -initSchema
Mac终端设置ls颜色
这种方式设置的颜色,会随着终端的颜色变化而变化,很实用。
具体步骤如下:
# 1.下载安装 coreutils
brew install coreutils
# 2.创建颜色配置文件
gdircolors --print-database > ~/.dir_colors
编辑.zshrc
if brew list | grep coreutils > /dev/null ; then
PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
alias ls='ls -F --show-control-chars --color=auto'
eval `gdircolors -b $HOME/.dir_colors`
fi
## 可以省略if条件,直接执行条件语句的内容
PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
alias ls='ls -F --show-control-chars --color=auto'
eval `gdircolors -b $HOME/.dir_colors`
最后source .zshrc
Mac下使用netcat发送消息
直接使用nc命令,不知道为啥不行。
需要使用brew安装一下brew install netcat
netcat -l -p 9999
:发送消息netcat golden-02 9999
:接受消息
9999是端口号,默认是localhost
MAC下设置全局环境变量
当mac的执行环境是zsh的时候,设置环境变量不要在.zshrc
里设置
原因是,.zshrc
的环境变量只是当前用户的,在启动hadoop
相关任务的时候,会报错找不到hadoop的环境变量
这里正确的设置方法是:
- 在
/etc/profile
里配置相应的环境变量 - 在
.zshrc
里source /etc/profile
谷歌浏览器快捷键
快捷键 | 功能 |
---|---|
⌘ + N | 打开新窗口 |
⌘-T | 打开新标签页 |
⌘-Shift-N | 在隐身模式下打开新窗口。 |
按 ⌘-O,然后选择文件。 | 在 Google Chrome 浏览器中打开计算机中的文件。 |
按住 Shift 键,然后点击链接。 | 在新窗口中打开链接。 |
按住 ⌘-Shift 键,然后点击链接。 | 在新标签页中打开链接并切换到刚打开的标签页。 |
同时按 ⌘-Option 和向右箭头键。 | 切换到下一个标签页。 |
同时按 ⌘-Option 和向左箭头键。 | 切换到上一个标签页。 |
⌘-W | 关闭当前标签页或弹出窗口。 |
⌘-Shift-W | 关闭当前窗口。 |
按住⌘ + Q | 关闭浏览器 |