Write the Code. Change the World.

分类目录
8月 29

Node.js 官网下载地址:https://nodejs.org/en/download/

注意,这里分两种版本,LTS(长期支持,成熟可靠)和Current(稳定版,最新特性)。选择合适的版本安装。

下载好Mac对应的版本。然后安装。安装完成后,会出现下边提示。

Node.js was installed at

   /usr/local/bin/node

npm was installed at

   /usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

确定,安装完成。

使用

安装完成后,可以在终端中查看版本。

node -v
npm -v

使用国内的淘宝镜像

npm install -g cnpm --registry=https://registry.npm.taobao.org
8月 13

安装redis

brew install redis

安装成功后,有如下提示

zhoulindeMacBook-Pro:~ zhoulin$ brew install redis
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/redis-4.0.1.sierra.bottle.tar.gz 

######################################################################## 100.0%
==> Pouring redis-4.0.1.sierra.bottle.tar.gz
==> Caveats
To have launchd start redis now and restart at login:
  brew services start redis
Or, if you don't want/need a background service you can just run:
  redis-server /usr/local/etc/redis.conf
==> Summary
  /usr/local/Cellar/redis/4.0.1: 13 files, 2.8MB
zhoulindeMacBook-Pro:~ zhoulin$ brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)

然后按照提示,启动redis

开机自启动

sudo cp /usr/local/opt/redis/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist 
sudo launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist #停止使用
8月 13

直接进入主题。

brew install mariadb

安装成功后,会有下边的提示。

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

MySQL is configured to only allow connections from localhost by default

To connect:
    mysql -uroot

To have launchd start mariadb now and restart at login:
  brew services start mariadb
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
  /usr/local/Cellar/mariadb/10.2.7_1: 623 files, 162.2MB

进入安装目录,进行配置。

cd /usr/local/cellar/mariadb/10.2.7_1
mysql_install_db 

经过了上面的若干命令,已经安装好了mariadb数据库,但是mariadb数据库服务并没有启动,你可以通过这个命令来启动mariadb数据库服务:

mysql.server start 

通过上面的启动mariadb数据库服务,你已经可以连接mariadb的数据库了,但是还不够安全,通过如下步骤可以完成更全面的设置,如:重设root用户的密码、移除匿名用户、移除默认的test数据库等等。

zhoulindeMacBook-Pro:10.2.7_1 zhoulin$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

连接mariadb数据:

mysql -u root -p 

这个时候,输入上一步设置的密码,回车,就可以连接到mariadb了。

验证mariadb版本:

MariaDB [(none)]> select @@version;
+----------------+
| @@version      |
+----------------+
| 10.2.7-MariaDB |
+----------------+
1 row in set (0.00 sec)

mariadb基础命令:

下面是mariadb的一些基础使用命令:

显示数据库列表
show databases;

切换到名为mysql的数据库,显示该库中的数据表
use mysql;
show tables;

显示数据表table的结构
desc table;

建数据库A与删数据库A
create database database_A;
drop database database_A;

建表:
use database_A;
create table table_A(字段列表);
drop table table_A;

显示表中的记录:
select * from table_A;

清空表中记录:
delete from table_A;

mariadb 自启动

sudo cp /usr/local/cellar/mariadb/10.2.7_1/homebrew.mxcl.mariadb.plist ~/Library/LaunchAgents/
sudo launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist #启动
sudo launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist #关闭

参考文章

http://blog.csdn.net/zmzwll1314/article/details/52926885

8月 13

通常,域名访问的网站都是外网的。有时候为了方便,使用域名访问本地文件也有必要。要实现这个,做到以下两步即可。

  1. 写host。
  2. 修改服务器配置。这里用的是 nginx

  3. 如果想要使用 https 访问,还需要制作 ssl 证书。

但在 mac 下,要实现这个,必须先实现端口的转发。也就是mac限制root权限才可以访问1024以下端口。所以,你想访问80端口,443端口是不现实的。这个时候,就需要用到 pfctl 转发。

https://blog.vini123.com/166

实现了转发,就继续下边的过程了。
继续阅读

8月 13

mac下,1024以下端口访问需要root权限。这使得在使用的时候很不方便。比如访问本地服务的一个网站,总得带上端口号。这样难看又麻烦。

面对问题,总会有解决的方法。在 mac os 10.10 以前,通过 ipfw 可以实现代理。更新版本系统之后 ipfw 就被弃用了。这个时候用 pfctl 来实现。

实现过程

创建文件 nginx.proxy

sudo vi /etc/pf.anchors/nginx.proxy
i

输入以下内容:

rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 8443

保存修改。
继续阅读

8月 12

需求

mac自带的php版本是5.6,想要使用7.1的特性,就得想办法升级php版本。

过程

  1. 如果存在homebrew安装的旧版本,请先卸载。
  2. 安装php7。

先卸载。

brew services list #查看homebrew安装的程序
brew uninstall php70 #假如之前安装过php70
rm -rf /usr/local/etc/php/7.0 #删除对应的配置文件

继续阅读

8月 12

在安装 nginx 之前,请先安装 Homebrew

安装 nginx

brew install nginx

默认安装最新版本的,当前版本是 1.12.1 。安装完成后,在终端里会显示一些路径信息,如下:

/usr/local/etc/nginx/nginx.conf #配置文件路径
/usr/local/var/www #服务器默认路径
/usr/local/Cellar/nginx/1.12.1 #安装路径

继续阅读

8月 12

介绍

Homebrew是Mac上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件。其类似于centos的yum,ubuntu的apt-get

安装

官网:https://brew.sh/index_zh-cn.html

终端中执行下边命令。

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后会提示安装以及要创建等目录。回车,输入密码,将进行下载安装。
继续阅读