mac笔记

mac系统的一些总结

(1) mac新建用户

() Menu -> System Preferences -> Users & Groups
点 + 号,新建用户

(2) mac修改计算机名和用户名

修改计算机名

() Menu -> System Preferences -> Sharing 然后修改 computer name

修改用户名
  mac修改用户名及对应目录稍微有点麻烦。

  1. 创建一个新用户,授予管理员权限。
  2. 退出登录,使用新用户登录
  3. 在Finder中打开 Go to Floder,输入 /Users ,然后把要修改的用户的目录名修改成你想要的。
  4. () Menu -> System Preferences -> Users & Groups , 按 锁形图标,输入管理员名称和密码。
  5. 然后在左侧用户列表,选中要修改的用户,右键 -> Advanced -> Options , 然后把 Account name 改成自己想要改的名字。
  6. 重启电脑。

(3) mac设置语言

() Menu -> System Preferences ->

(4) mac查看隐藏的文件

# 显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool true 
# 不显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool false 

(5) mac日期显示

brew install coreutils 

修改 ~/.bash_profile 文件

alias ls="gls -G"

alias ll="ls -al"

(6) 安装软件

搜狗输入法
Chrome浏览器

(7) mac配置别名

vi .bash_profile (旧版本) 否则会提示 sh: command not found: ll
vim .zshrc (新版本) 否则会提示 zsh: command not found: ll

修改 .bash_profile 文件

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

mac系统升级到10.15以后,shell由原来的bash变成了zsh
如果系统是 10.15

(9) mac配置环境变量

.bash_profile

# alias
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# config terminal display
export PS1='[%n@%m %c ]$'

# color config
export CLICOLOR=1
# color display format
#export LSCOLORS=GxFxCxDxBxegedabagaced
#export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
#export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
#export LSCOLORS=ExGxFxdaCxDaDahbadeche

# time style config
#export TIME_STYLE='+%Y-%m-%d_%H:%M:%S.%N'

# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin

# JDK config
# jdk 8
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
# jdk 18
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

# maven config
export MAVEN_HOME=/Users/weikeqin/SoftWare/maven/apache-maven-3.8.5
export PATH=$PATH:$MAVEN_HOME/bin

#gradle config
export GRADLE_HOME=/Users/weikeqin/SoftWare/gradle/gradle-7.4.2
export PATH=$PATH:$GRADLE_HOME/bin

# Setting PATH for Python 2.7
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.10
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin":${PATH}

alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10'
alias python=python3


# mysql alias
alias mysql=/usr/local/mysql/bin/mysql


# go config
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/Users/weikeqin/gopath

.zshrc

source ~/.bash_profile

(10) 设置显示行号

vi ~/.vimrc

set nu

(11) mac设置

export PS1='[\u@\h $PWD]\$'

(7) 安装开发工具

  JDK  
  Maven  
  MySQL  
  Eedis  
  ElasticSearch  
  MySQL管理工具sqpuelpro  https://sequelpro.com/download  https://github.com/sequelpro/sequelpro/releases/download/release-1.1.2/sequel-pro-1.1.2.dmg

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at:
[weikeqin@macbook ~ ]$sudo brew install apr
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

              开始执行Brew自动安装程序
             [cunkai.wang@foxmail.com]
           [2020-11-20 14:32:17][11.0]
       https://zhuanlan.zhihu.com/p/111014448


请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不显示下载进度) 5、阿里巴巴下载源(缺少cask源)
请输入序号: 1

  你选择了中国科学技术大学下载源

!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y)Y

--> 脚本开始执行
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
(设置开机密码:在左上角苹果图标->系统偏好设置->"用户与群组"->更改密码)
(如果提示This incident will be reported."用户与群组"中查看是否管理员)
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
   ---备份要删除的文件夹到系统桌面....
   ---/usr/local/Homebrew 备份完成
-> 创建文件夹 /usr/local/Homebrew
此步骤成功
   ---备份要删除的文件夹到系统桌面....
   ---/usr/local/Caskroom 备份完成
-> 创建文件夹 /usr/local/Caskroom
此步骤成功
   ---备份要删除的文件夹到系统桌面....
   ---/usr/local/Cellar 备份完成
-> 创建文件夹 /usr/local/Cellar
此步骤成功
   ---备份要删除的文件夹到系统桌面....
   ---/usr/local/var/homebrew 备份完成
-> 创建文件夹 /usr/local/var/homebrew
此步骤成功
-> 创建文件夹 /usr/local/var/homebrew/linked
此步骤成功
git version 2.24.3 (Apple Git-128)

下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件(32M+)

未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 167685, done.
remote: Total 167685 (delta 0), reused 0 (delta 0) | 1.62 MiB/s
Receiving objects: 100% (167685/167685), 41.43 MiB | 1.75 MiB/s, done.
Resolving deltas: 100% (124883/124883), done.
此步骤成功
==> 创建brew的替身
此步骤成功
==> 克隆Homebrew Core(224M+)
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 840476, done.
remote: Total 840476 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (840476/840476), 330.77 MiB | 1.69 MiB/s, done.
Resolving deltas: 100% (567964/567964), done.
Updating files: 100% (5615/5615), done.
此步骤成功
==> 克隆Homebrew Cask(248M+) 类似AppStore
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 493729, done.
remote: Total 493729 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (493729/493729), 224.06 MiB | 1.76 MiB/s, done.
Resolving deltas: 100% (351281/351281), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
此步骤成功

==> 安装完成,brew版本

11.0
brew -v

Homebrew 2.5.11-78-g6d850a9-dirty
Homebrew/homebrew-core (git revision c2373f; last commit 2020-11-20)
Homebrew/homebrew-cask (git revision 2fe8b7; last commit 2020-11-20)
Brew前期配置成功

==> brew update

==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (or will be during this `brew` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
Already up-to-date.

        上一句如果提示Already up-to-date表示成功
            Brew自动安装程序运行完成
              国内地址已经配置完成

                初步介绍几个brew命令

        本地软件库列表:brew ls
        查找软件:brew search google(其中google替换为要查找的软件关键字)
        查看brew版本:brew -v  更新brew版本:brew update

现在可以输入命令open ~/.zshrc -e 或者 open ~/.bash_profile -e 整理一下重复的语句(运行 echo $SHELL 可以查看应该打开那一个文件修改)

        https://zhuanlan.zhihu.com/p/111014448  欢迎来给点个赞

[weikeqin@macbook ~ ]$

mac上使用ab测试

[weikeqin@macbook ~ ]$ ab -n 10000 -c 100 -s 100 http://127.0.0.1:8080/demo/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /demo/
Document Length:        22 bytes

Concurrency Level:      100
Time taken for tests:   2.050 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1550000 bytes
HTML transferred:       220000 bytes
Requests per second:    4878.36 [#/sec] (mean)
Time per request:       20.499 [ms] (mean)
Time per request:       0.205 [ms] (mean, across all concurrent requests)
Transfer rate:          738.42 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9   1.6      9      15
Processing:     5   11   7.2     10      86
Waiting:        1   10   6.7      9      82
Total:          7   20   7.4     19      94

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     20
  75%     21
  80%     21
  90%     24
  95%     25
  98%     27
  99%     82
 100%     94 (longest request)
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$ ab -n 10000 -c 100 -s 100 http://127.0.0.1:8080/demo/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
apr_socket_recv: Operation timed out (60)
Total of 6286 requests completed
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$ ab -n 10000 -c 100 -s 100 -r http://127.0.0.1:8080/demo/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /demo/
Document Length:        22 bytes

Concurrency Level:      100
Time taken for tests:   2.276 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1550000 bytes
HTML transferred:       220000 bytes
Requests per second:    4393.83 [#/sec] (mean)
Time per request:       22.759 [ms] (mean)
Time per request:       0.228 [ms] (mean, across all concurrent requests)
Transfer rate:          665.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   11  16.3      9     266
Processing:     5   12  19.6     10     265
Waiting:        4   11  19.3      9     265
Total:         10   23  25.5     19     276

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     21
  75%     22
  80%     23
  90%     24
  95%     26
  98%     34
  99%    271
 100%    276 (longest request)
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$
[weikeqin@macbook ~ ]$ ab -n 10000 -c 100 -s 100 -r http://127.0.0.1:8080/demo/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests

Test aborted after 10 failures

apr_socket_connect(): Operation already in progress (37)
Total of 6332 requests completed
[weikeqin@macbook ~ ]$

端口用完了。

osx上的默认临时端口范围是49152-65535,仅16,383个端口。由于每个ab请求http/1.0(在第一个示例中都没有保留),每个新请求都需要另一个端口。

在使用每个端口时,它将被放入队列中,等待tcp“Maximum Segment Lifetime”(最大段寿命),该值在OSX上配置为15秒。因此,如果在15秒内使用16,383个以上的端口,那么在进一步连接时,您将会受到操作系统的限制。根据首先从哪个进程耗尽端口,将从服务器获得连接错误,或挂起ab。

你可以通过使用一个http/1.1有能力的负载生成器来减轻这个负担wrk,或者使用keepalive(-k)选项ab,这样就可以根据工具的并发设置重新使用连接。

为什么我的HelloWorldGo服务器被ApacheBench压垮了?

References

[1] 更改 macOS 用户帐户和个人文件夹的名称
[2] 在 Mac 上更改电脑的名称或本地主机名
[3] macOS 10.15 修改terminal终端显示
[4] macOS10.14下对终端Terminal的一些修改
[5] os-x-terminal-colors
[6] 13 Prompt Expansion
[7] macOS终端颜色的设定:设定自己的LSCOLOR配色
[8] MacOS 修改 ls 显示年月日的时间格式
[9] 在 Mac 上将 zsh 用作默认 Shell
[10] Mac 下 brew 切换为国内源