|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: 本地开发环境准备和复盘 |
| 4 | + |
| 5 | +date: 2021-07-13 |
| 6 | +author: HH |
| 7 | +header-img: img/post-bg-debug.png |
| 8 | +catalog: true |
| 9 | +tags: |
| 10 | + - Mac |
| 11 | + - MySQL |
| 12 | +--- |
| 13 | + |
| 14 | +## 本地开发环境准备和复盘 |
| 15 | + |
| 16 | +### Brew |
| 17 | + |
| 18 | +在mac开发和本地测试,少不了要安装一些软件,比如Java常见的依赖:mysql、redis、zookeeper等。 |
| 19 | + |
| 20 | +在mac上安装了brew后,就像Windows下的各类软件管家一样,可以直接拉取软件,避免了去官网下载的麻烦。 |
| 21 | + |
| 22 | +安装brew的方式:进入mac终端,执行下面的命令(不能翻墙者的福音,有gitee的中转) |
| 23 | + |
| 24 | +``` |
| 25 | +/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" |
| 26 | +``` |
| 27 | + |
| 28 | +复盘: |
| 29 | + |
| 30 | +1. zsh,一款用于交互式使用的shell,可以作为脚本解释器来使用。其包含了bash、ksh、tcsh等其他shell中许多优秀功能。macOS Catalina版开始,其默认shell从bash改为zsh。 |
| 31 | +2. -c,Take the first argument as a command to execute, rather than reading commands from a script or standard input. If any futhers arguments are given, the first one is assigned to $0, rather than being used as a positional parameter. |
| 32 | + |
| 33 | +### Zookeeper |
| 34 | + |
| 35 | +安装zookeeper,在终端输入下面的命令 |
| 36 | + |
| 37 | +``` |
| 38 | +brew install zookeeper |
| 39 | +``` |
| 40 | + |
| 41 | +### MySQL |
| 42 | + |
| 43 | +安装MySQL在终端输入下面的命令 |
| 44 | + |
| 45 | +``` |
| 46 | +brew install mysql |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +``` |
| 52 | +==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1k.mojave.bottle.tar.gz |
| 53 | +######################################################################## 100.0% |
| 54 | +==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql%405.7-5.7.34.mojave.bottle.tar.gz |
| 55 | +######################################################################## 100.0% |
| 56 | +==> Installing dependencies for [email protected]: [email protected] |
| 57 | + |
| 58 | + |
| 59 | +Warning: The post-install step did not complete successfully |
| 60 | +You can try again using: |
| 61 | + brew postinstall [email protected] |
| 62 | +==> Summary |
| 63 | +🍺 /usr/local/Cellar/[email protected]/1.1.1k: 8,071 files, 18.4MB |
| 64 | + |
| 65 | + |
| 66 | +==> /usr/local/Cellar/[email protected]/5.7.34/bin/mysqld --initialize-insecure --user=jiawenhao --basedir=/usr/local/Cellar/[email protected]/5.7.34 --datadir=/usr/local/var/mysql --tmpdir=/tmp |
| 67 | +==> Caveats |
| 68 | +``` |
| 69 | + |
| 70 | +通过安装信息,我们能够看到 |
| 71 | + |
| 72 | +> --basedir=/usr/local/Cellar/[email protected]/5.7.34 |
| 73 | +> |
| 74 | +> --datadir=/usr/local/var/mysql |
| 75 | +> |
| 76 | +> --tmpdir=/tmp |
| 77 | +
|
| 78 | +在这里我们扩展一下/usr目录。它的全称可能是Unix System/Software Resources。/usr是unix系统最重要的目录之一,涵盖了二进制文件,各种文档,各种头文件,还有各种库文件,还有诸多程序,如ftp,telnet等等。下面简单罗列一下可能存在的目录的含义: |
| 79 | + |
| 80 | +- /usr/bin:所有可执行文件,如gcc/firefox(指不在/sbin和/bin内的) |
| 81 | +- /usr/include:各种头文件,编译文件等时需要使用 |
| 82 | +- /usr/lib:所有可执行文件需要的库文件 |
| 83 | +- /usr/local:存放手动安装的软件。 |
| 84 | +- /usr/doc:文档,/usr/share/doc的软连接 |
| 85 | +- /usr/share:包含各个程序间的共享文件,如字体,图标,文档等。 |
| 86 | +- /usr/share/man:manual操作手册 |
| 87 | +- /usr/src:Linux内核的源码和说明文档等 |
| 88 | + |
| 89 | +与之相应的还有/var目录,variable的简称,主要针对常态性变动的文件,包括缓存cache、登陆档log file以及某些软件运作所产生的文件。 |
| 90 | + |
| 91 | +- /var/cache:应用程序本身运作过程中会产生一些暂存文档 |
| 92 | +- /var/lib:程序本身执行的过程中,需要使用到的数据文件放置的目录。在此目录下各自的软件应该要有各自的目录。举例来说,MySQL的数据库放置到/var/lib/mysql而rpm的数据则放到/var/lib/rpm去 |
| 93 | +- /var/lock:某些装置或者事文件资源一次只能被一个应用程序所使用哦,如果同时有两个程序使用该装置时,就可能产生一些错误的情况,因此就得要在该装置上锁。 |
| 94 | +- /var/log:非常重要。这是登陆文件放置的目录。里面比较重要的文件,比如/var/log/messages,/var/log/wtmp记录登入者的信息等。 |
| 95 | +- /var/mail:放置个人电子邮件信箱的目录,不过这个目录也被放置到/var/spool/mail目录中,通常这两个目录是互为链接文件。 |
| 96 | +- /var/run:某些程序或者服务启动后,会将他们的PID放置到这个目录下。 |
| 97 | +- /var/spool:这个目录通常放置一些队列数据,所谓队列就是排队等待其他程序使用的数据。这些数据被使用后通常会被删除。举例说明,系统收到新信惠放置到/var/spool/mail中,但使用者收下该信件后原则上会被删除,如果暂时寄不出去会放到/var/spool/mqueue中,等被送出后就要被删除。如果是工作排程数据crontab,就会放到/var/spool/cron目录中。 |
| 98 | + |
| 99 | +在安装之后设置一些环境变量 |
| 100 | + |
| 101 | +```shell |
| 102 | +echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> /Users/jiawenhao/.bash_profile |
| 103 | +echo 'export LDFLAGS="-L/usr/local/opt/[email protected]/lib"'>> /Users/jiawenhao/.bash_profile |
| 104 | +echo 'export CPPFLAGS="-I/usr/local/opt/[email protected]/include"'>> /Users/jiawenhao/.bash_profile |
| 105 | +``` |
| 106 | + |
| 107 | +启动mysql |
| 108 | + |
| 109 | +```shell |
| 110 | +brew services start [email protected] |
| 111 | +if you don't want/need a background service you can just run: |
| 112 | +/usr/local/opt/[email protected]/bin/mysql.server start |
| 113 | +brew services stop [email protected] |
| 114 | +brew services restart [email protected] |
| 115 | +brew services list |
| 116 | +``` |
| 117 | +
|
| 118 | +排查问题 |
| 119 | +
|
| 120 | +> ERROR! The server quit without updating PID file (/usr/local/var/mysql/your_computer_name-Pro.local.pid). |
| 121 | +
|
| 122 | +``` |
| 123 | +ps aux | grep mysqld | grep grep -v |
| 124 | +sudo kill -9 mysqlpid |
| 125 | +``` |
| 126 | +
|
| 127 | +Google了很多文章,都说kill掉重启就会好,发现无法杀掉进程,每次kill掉都会自己起一个新的进程,而且这个无法kill的mysql进程还是_mysql用户起来的,很明显跟我没啥关系,于是开始Google如何kill掉这个mysqld进程,然后看下面的命令 |
| 128 | +
|
| 129 | +``` |
| 130 | +sudo launchctl unload -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist |
| 131 | +``` |
| 132 | +
|
| 133 | +再然后kill -9 mysqldid就可以了,原因这里简述一下,并不深入。简单来说就是:Mac系统在更新OS X之后,加入了 "Rootless机制",也就意味着有一些目录的内容我们无法进行随意的进行读写;即使设置root权限也不能使用。得,总而言之就是坑,把 |
| 134 | +
|
| 135 | +[链接]: https://blog.csdn.net/ws1836300/article/details/108850641?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242 |
| 136 | +
|
| 137 | +贴上来。 |
| 138 | +
|
| 139 | + |
| 140 | +
|
| 141 | +``` |
| 142 | +mysql_secure_installation |
| 143 | +``` |
| 144 | +
|
| 145 | +结束! |
| 146 | +
|
| 147 | +### Redis |
| 148 | +
|
| 149 | +```shell |
| 150 | +brew search redis |
| 151 | + |
| 152 | +echo 'export PATH= "/usr/local/opt/[email protected]/bin:$PATH"' >> /Users/jiawenhao/.bash_profile |
| 153 | +``` |
| 154 | +
|
| 155 | +启动redis |
| 156 | +
|
| 157 | +``` |
| 158 | +brew services start [email protected] |
| 159 | +if you don't want/need a background service you can just run: |
| 160 | +/usr/local/opt/ [email protected]/bin/redis-server /usr/local/etc/redis.conf |
| 161 | +``` |
| 162 | +
|
0 commit comments