紫牙的博客

彼亦一是非,此亦一是非

0%

安装 zsh

1
2
3
4
5
6
7
brew install zsh
# 安装完成后
zsh --version
# 显示类似zsh 5.1.1,则表示安装成功
# 切换默认的shell为zsh
chsh -s $(which zsh)
# 重启下终端

安装 Oh My Zsh

1
2
3
4
5
# 如果没有安装 git,要先安装
brew install git
# 安装完后,开始安装 oh my zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# 安装完后,应该能看到终端窗口内容显示的变化

安装 angtigen

A plugin manager for zsh, inspired by oh-my-zsh and vundle.

1
2
curl -L git.io/antigen > antigen.zsh
# or use git.io/antigen-nightly for the latest version

安装完成后,删除原来的 .zshrc 文件,新建一个

1
2
rm ~/.zshrc
touch ~/.zshrc

将下列内容复制后粘贴到新的 .zshrc 中并保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
source ~/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# Bundles from the default repo (robbyrussell's oh-my-zsh).
antigen bundle brew
antigen bundle command-not-found
antigen bundle docker
antigen bundle docker-compose
antigen bundle gem
antigen bundle git
antigen bundle golang
antigen bundle ng
antigen bundle osx
antigen bundle pip

# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle zsh-users/zsh-apple-touchbar

# Load the theme.
# antigen theme robbyrussell
antigen theme https://github.com/denysdovhan/spaceship-prompt spaceship

# Tell Antigen that you're done.
antigen apply

保存后,执行下该文件

1
source ~/.zshrc

为 spaceship 主题安装字体 Powerline fonts

1
2
3
4
5
6
7
8
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

安装完成打开终端的 偏好设置 -> 描述文件 -> 字体,并选择 Meslo LG 系列字体中的一个,这个时候终端里面的乱码问题就解决了。

改字体

这样就大功告成了😎

ohmyzsh

下载并安装 MongoDB

  • 直接下载安装

MongoDB 提供了 OSX 平台上 64 位的安装包,你可以在官网下载安装包。

1
下载地址:https://www.mongodb.com/download-center#community
  • 通过mac自带的curl安装
1
2
3
4
5
6
7
8
9
10
11
12
# 进入 /usr/local
cd /usr/local

# 下载
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.3.tgz

# 解压
sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.3.tgz

# 重命名为 mongodb 目录

sudo mv mongodb-osx-ssl-x86_64-4.0.3 mongodb
  • 通过 brew 安装
1
sudo brew install mongodb

安装中需要稍等一会儿,完成后输入下列命令

1
2
mongod --version
mongo --version

出现下列提示,则表示可以使用 mongod 和 mongo 命令

1
2
3
4
5
6
7
db version v4.0.3
git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
allocator: system
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
1
2
3
4
5
6
7
MongoDB bush version v4.0.3
git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
allocator: system
modules: none
build environment:
distarch: x86_64
target_arch: x86_64

否则,要配置环境变量

1
2
cd ~
vim .bash_profile

将下列代码复制粘贴进去,保存后即可。

1
2
export MONGO_PATH=/usr/local/Cellar/mongodb
export PATH=$PATH:$MONGO_PATH/bin

配置 MongoDB

新建数据库存放路径、配置文件和日志文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#进入 mac 根目录
cd /

#新建文件夹 mongoData
mkdir mongoData

#新建三个文件夹分别是 db(存放数据库数据),etc(mongodb配置文件),logs(日志文件)
mkdir db etc logs

在etc和log下分别创建配置文件和日志文件
cd etc
touch mongo.conf
cd logs
touch mongo.log

接下来修改 mongodb 的配置文件

1
2
#vim编辑配置文件
vim mongo.conf

mongdb的配置,参考链接 Run-time Database Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #日志输出文件路径
logpath=/mongoData/logs/mongo.log

#错误日志采用追加模式,配置这个选项后mongodb的日志会追加到现有的日志文件,而不是从新创建一个新文件
logappend=true

#启用日志文件,默认启用
journal=true

#这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet=false

#是否后台启动,有这个参数,就可以实现后台运行
fork=true

#端口号 默认为27017
port=27017

#指定存储引擎(默认不需要指定)
#storageEngine=mmapv1

#开启认证
auth = true

将上面的配置字段复制进去并且保存

启动mongodb

1
2
#通过配置文件的方式启动mongdb
mongod -f /mongoData/etc/mongo.conf

如果出现 successfully, 则表示成功

1
2
3
4
2018-11-24T17:17:03.968+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 2299
child process started successfully, parent exiting

配置超级用户和用户

1
2
3
4
5
6
7
8
#进入mongodb
mongo

#使用admin数据库
use admin

#查看有所有数据库
show dbs

不出意外的话会提示没有权限,因为我们是以配置文件启动的mongodb,并且配置文件中我们开启了认证将auth字段设置成了true

这个时候我们就应该开始配置用户

  • 创建超级管理员用户
1
2
3
4
5
6
use admin
db.createUser({user:"admin",pwd:"password",roles:["root"]}) //admin这个数据库是系统自带的数据库,他的用户可以访问任何其他数据库的数据,也叫做超级管理员

db.auth("admin","password") // => 1 表示验证通过 0表示验证失败

show dbs //=>admin 0.000GB blog 0.000GB config 0.000GB

这样就展示出所有的数据库了

  • 创建普通用户(某个数据库的用户)
1
2
3
4
5
6
7
8
9
use admin //=>进入admin数据库

db.auth("admin","password") //=> 通过超级管理员验证

use blog

db.createUser({user: "blog", pwd: "password", roles: [{ role: "dbOwner", db: "blog" }]})

show dbs => admin 0.000GB blog 0.000GB config 0.000GB local 0.000GB

这样就创建了单独关于blog这个数据库的账户了,账号是blog,密码是password
这里我们要注意一点,给创建普通数据库用户的时候要是在超级管理员验证完之后创建

原文链接: https://segmentfault.com/a/1190000014740252

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

/**
* 保存到本地 localStorage
* @param {String} key 键
* @param {any} value 值
* @returns {Boolean} 是否成功
* @description 保存到本地 localStorage
*/
export const setLocalStorage = (key, value) => {
// key 值必须为有效字符串,尽管其值的类型不限于 String,但是为了统一,还是规范下。
if (typeof key !== 'string') {
return false;
}
localStorage.setItem(key, JSON.stringify(value));
return true;
};

/**
* 从 localStorage 中取出保存的值
* @param {String} key 键
* @returns {any} value 值
* @description 从 localStorage 中取出保存的值
*/
export const getLocalStorage = key => {
// key 值必须为有效字符串,尽管其值的类型不限于 String,但是为了统一,还是规范下。
if (typeof key !== 'string') {
return;
}
const str = localStorage.getItem(key);
try {
return JSON.parse(str);
} catch (error) {
return str === 'undefined' ? undefined : str;
}
};

/**
* 保存到本地 sessionStorage
* @param {String} key 键
* @param {any} value 值
* @returns {Boolean} 是否成功
* @description 保存到本地 sessionStorage
*/
export const setSessionStorage = (key, value) => {
// key 值必须为有效字符串,尽管其值的类型不限于 String,但是为了统一,还是规范下。
if (typeof key !== 'string') {
return false;
}
sessionStorage.setItem(key, JSON.stringify(value));
return true;
};

/**
* 从 sessionStorage 中取出保存的值
* @param {String} key 键
* @returns {any} value 值
* @description 从 sessionStorage 中取出保存的值
*/
export const getSessionStorage = key => {
// key 值必须为有效字符串,尽管其值的类型不限于 String,但是为了统一,还是规范下。
if (typeof key !== 'string') {
return;
}
const str = sessionStorage.getItem(key);
try {
return JSON.parse(str);
} catch (error) {
return str === 'undefined' ? undefined : str;
}
};

编辑 .bash_profile 文件

1
2
3
4
5
6
# 编辑 .bash_profile
vi .bash_profile

# 若不存在,则新建
touch .bash_profile
vi .bash_profile

将下列代码复制粘贴到 .bash_profile 的末尾,保存后重启终端即可。

1
2
3
4
5
6
7
8
9
10
11
12
# Git branch in prompt.
function git_branch {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo " ($branch)"
fi
}

export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '

显示效果
分支显示