Linux常用库介绍

GCC

GNU编译器套件,全名GNU Compiler Collection。是由 GNU 开发的编程语言编译器。现已被大多数类Unix操作系统(如Linux、BSD、Mac OS X等)采纳为标准的编译器。

1
yum install -y gcc

GCC-C++

GNU的C++编译器

1
yum install -y gcc-c++

PCRE

PCRE(Perl Compatible Regular Expressions,Perl兼容正则表达式)是由Philip Hazel开发的函数库,目前为很多软件所使用,该库支持正则表达式。它由RegEx演化而来,实际上,Perl正则表达式也是源自于Henry Spencer写的RegEx。

1
yum install -y pcre

pcre-devel

pcre-devel是使用PCRE做二次开发时所需要的开发库,包括头文件等,这也是编译Nginx所必须使用的。

1
yum install -y pcre-devel

zlib

zlib库用于对HTTP包的内容做gzip格式的压缩,如果我们在nginx.conf里配置了gzip on,并指定对于某些类型(content-type)的HTTP响应使用gzip来进行压缩以减少网络传输量,那么,在编译时就必须把zlib编译进Nginx。
同理,zlib是直接使用的库,zlib-devel是二次开发所需要的库。

1
yum install -y zlib zlib-devel

openssl

如果我们服务器不只是要支持HTTP,还要在更安全的ssl协议上传输HTTP,那么就需要拥有openssl了。另外,如果需要使用MD5,SHA1等散列函数,也会用到openssl。

1
yum install -y openssl

Mac中的定时任务利器-launchctl

launchctl是一个统一的服务管理框架,可以启动、停止和管理守护进程、应用程序、进程和脚本等。
launchctl是通过配置文件来指定执行周期和任务的。

当然mac也可以像linux系统一样,使用crontab命令来添加定时任务,这里就不赘述,具体可参见:OS X 添加定时任务
下面将手把手教你在mac上创建定时任务。(任务目标:每天晚上十点定时执行/Users/demo/helloworld.py的python程序)

1. 创建run.sh脚本

进入 helloworld.py 程序所在目录
cd /User/demo
创建run.sh脚本
vi run.sh
添加执行helloworld.py的命令

1
2
3
4
5
6
7
8
9
10
#!/bin/sh

# 记录一下开始时间
echo `date` >> /Users/demo/log &&
# 进入helloworld.py程序所在目录
cd /Users/demo &&
# 执行python脚本(注意前面要指定python运行环境/usr/bin/python,根据自己的情况改变)
/usr/bin/python helloworld.py
# 运行完成
echo 'finish' >> /Users/demo/log

:x保存退出
注意,脚本要改成可执行的权限
chmod 777 run.sh

2. 编写plist文件

launchctl 将根据plist文件的信息来启动任务。
plist脚本一般存放在以下目录:

  • /Library/LaunchDaemons –>只要系统启动了,哪怕用户不登陆系统也会被执行
  • /Library/LaunchAgents –>当用户登陆系统后才会被执行

更多的plist存放目录:

1
2
3
4
5
~/Library/LaunchAgents 由用户自己定义的任务项
/Library/LaunchAgents 由管理员为用户定义的任务项
/Library/LaunchDaemons 由管理员定义的守护进程任务项
/System/Library/LaunchAgents 由Mac OS X为用户定义的任务项
/System/Library/LaunchDaemons 由Mac OS X定义的守护进程任务项

进入 ~/Library/LaunchAgents,创建一个plist文件com.demo.plist

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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Label唯一的标识 -->
<key>Label</key>
<string>com.demo.plist</string>
<!-- 指定要运行的脚本 -->
<key>ProgramArguments</key>
<array>
<string>/Users/demo/run.sh</string>
</array>
<!-- 指定要运行的时间 -->
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>00</integer>
<key>Hour</key>
<integer>22</integer>
</dict>
<!-- 标准输出文件 -->
<key>StandardOutPath</key>
<string>/Users/demo/run.log</string>
<!-- 标准错误输出文件,错误日志 -->
<key>StandardErrorPath</key>
<string>/Users/demo/run.err</string>
</dict>
</plist>

3. 加载命令

launchctl load -w com.demo.plist
这样任务就加载成功了。
更多的命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 加载任务, -w选项会将plist文件中无效的key覆盖掉,建议加上
$ launchctl load -w com.demo.plist

# 删除任务
$ launchctl unload -w com.demo.plist

# 查看任务列表, 使用 grep '任务部分名字' 过滤
$ launchctl list | grep 'com.demo'

# 开始任务
$ launchctl start com.demo.plist

# 结束任务
$ launchctl stop com.demo.plist

如果任务呗修改了,那么必须先unload,然后重新load
start可以测试任务,这个是立即执行,不管时间到了没有
执行start和unload前,任务必须先load过,否则报错
stop可以停止任务

番外篇

plist支持两种方式配置执行时间:

  • StartInterval: 指定脚本每间隔多长时间(单位:秒)执行一次;
  • StartCalendarInterval: 可以指定脚本在多少分钟、小时、天、星期几、月时间上执行,类似如crontab的中的设置,包含下面的 key:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Minute <integer>
    The minute on which this job will be run.
    Hour <integer>
    The hour on which this job will be run.
    Day <integer>
    The day on which this job will be run.
    Weekday <integer>
    The weekday on which this job will be run (0 and 7 are Sunday).
    Month <integer>
    The month on which this job will be run.

plist部分参数说明:

1
2
3
4
5
6
7
Label:对应的需要保证全局唯一性;
Program:要运行的程序;
ProgramArguments:命令语句
StartCalendarInterval:运行的时间,单个时间点使用dict,多个时间点使用 array <dict>
StartInterval:时间间隔,与StartCalendarInterval使用其一,单位为秒
StandardInPath、StandardOutPath、StandardErrorPath:标准的输入输出错误文件,这里建议不要使用 .log 作为后缀,会打不开里面的信息。
定时启动任务时,如果涉及到网络,但是电脑处于睡眠状态,是执行不了的,这个时候,可以定时的启动屏幕就好了。

mac下 valet 自定义普通域名的解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
listen 80;
server_name iyineng.piian.cn;
root /Users/pan/code/iyineng/public;
index index.php;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/Users/pan/.config/valet/valet.sock;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

xscope精确度量工具介绍

xScope精确度量工具介绍

勤奋的小卫子
1
2018.12.01 23:04:34
字数 677
阅读 1,391
一、xScope简介
这是一款Mac平台的设计精确度量工具,专门为设计师和开发人员创建的一套功能强大的工具,能够检查和测试屏幕上的图形和布局。能够帮助每个设计者快速,精确的完成工作,度量距离,角度的标尺,放大镜,精确垂直,水平标记辅助线,精确阔度,包含以下十个工具:

xScope
Mirro(镜像)
Text(文本)
Dimensions(尺寸)
Ruler(尺子)
Overlay(覆盖)
Screens(屏幕)
Loupe(放大镜)
Guides(指南)
Frames(框架)
Crosshair(十字)
二、功能详解
1.Mirro镜像
Mirro镜像
在Mac上使用这个功能时,可以轻松地在iOS和Apple Watch上查看您的设计和应用程序
这个功能需要从App Store下载配套应用程序才能完成(对开发人员用处不大)

2.Text文本
Text文本
可以使用这个工具来搜索,检查和格式化开发中的字符(感觉对开发人员来说并没什么卵用)

3.Dimensisons外形尺寸
Dimensisons外形尺寸
只需要将鼠标光标放在屏幕上,既可以找到任何屏幕元素的尺寸,非常适合在照片、按钮、界面元素上测量长度(这个功能挺不错)

4.Ruler标尺
Ruler标尺
功能强大的屏幕标尺,用于精确度量像素,包括缩放、旋转和边缘捕捉,可用于测量任何屏幕上的元素

5.Overlay栅格布局检查
Overlay栅格布局检查
适用于web开发,能够检查页面上的元素,支持整页截图,特别是响应式网页设计。

6.UIScreen屏幕
UIScreen屏幕
使用多种屏幕查看你的设计,或者查看在windows平台运行的IE9下的表现,无需将工作转移到其他平台,就能轻松解决这个问题(对设计的同学很有用)

7.放大镜
放大镜
可以精确的放大和检查元素,拾取色值并保存颜色供以后参考,还可以模拟常见的用户视觉问题

8.指南
屏幕快照 2018-12-01 下午10.19.44.png
显示垂直和水平向导,浮动在屏幕上的所有位置,查看是否对齐(不知道为什么我的只显示一根)

9.Framework框架
框架
创建一个自定义标记框,能够将框中内容进行截图,可以设置网格线以及固定比例窗口(一句话来说就是没卵用)

10.十字线
十字线
快速轻松地位和对齐屏幕上可见的任何点,显示当前鼠标位置相对于屏幕左上角的位置

CentOS 系统 安装与升级ruby方法

  • TOC
    {:toc}

    背景

    在做redis集群时,所需要的使用ruby工具进行操作,发现在线安装的Ruby版本过低,redis支持的版本最少为2.2.2.

 

在线安装ruby

使用yum在线安装ruby,安装的版本为2.0.0。

1
yum install ruby
1
ruby -v

添加ruby仓库

添加aliyun镜像并检测Ruby版本

1
2
3
gem sources -a http://mirrors.aliyun.com/rubygems/

ruby -v

安装RAM

RAM(Ruby Version Manager )是一款RAM的命令行工具,可以使用RAM轻松安装,管理Ruby版本。RVM包含了Ruby的版本管理和Gem库管理(gemset)

可以使用如下命令进行安装RAM:

1
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

2019-01-30 2.27.58.png{: .no-resize.center}

1
curl -sSL https://get.rvm.io | bash -s stable

出现如下信息代表安装成功: 

更新配置文件,使其立马生效:

1
source /etc/profile.d/rvm.sh

查看RVM版本信息,如果可以代表安装成功。

1
rvm -v

接下来查看Ruby版本:

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
$rvm list known

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.0.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.100]
rbx-head

# TruffleRuby
truffleruby[-1.0.0-rc2]

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]

安装Ruby,从上面查到的信息随便找一个比2.2.2版本要高的就行:

1
rvm install 2.5

出现如下信息,代表安装成功: 

验证版本:
成功升级。
 注意:
如果使用rvm安装发现下载缓慢,可以考虑删除原来的仓库地址,只保留阿里云镜像。

1
gem sources --remove https://rubygems.org/

docker 常用命令列表

1、常用命令列表

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
// 搜索镜像
docker search ubuntu

// 下载镜像
docker pull ubuntu:latest

// 列出镜像
docker images

// 创建容器
docker run -i -t --name hello ubuntu /bin/bash

// 查看容器列表 -a 所有的包括已停止
docker ps -a

// 重启
docker restart hello

// 连接容器
docker attach hello

// 容器外执行容器的命令
docker exec hello echo '你好'

// 停止容器
docker stop hello

// 删除容器
docker rm hello

// 删除镜像
docker rmi ubuntu:latest

2、创建docker

1
2
3
4
5
// 在当前目录创建镜像
docker build --tag hello:0.1 .

// 运行
docker run --name hello-nginx -d -p 80:80 -v /root/data:/data hello:0.1

3、查看docker

1
2
3
4
5
6
7
8
9
10
11
// 查看docker的镜像历史
docker history hello:0.1

// 从修改中提交镜像
docker commit -a 'ppiian<ppiian@126.com>' -m 'this is commit' hello-nginx hello:0.2

// 查看镜像的修改
docker diff hello-nginx

// 查看镜像详情
docker inspect

4 不常用命令

1
2
3
4
5
6
7
// 重新构建
docker-compose build
// 启动
docker-composer up -d

// 批量删除三个月前的容器
docker rm `docker ps -a | grep '3 months' | awk '{print $1}'`

linux镜像源改为阿里云镜像源

Centos

  1. 备份
    1
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  2. 下载新的 CentOS-Base.repo/etc/yum.repos.d/

    CentOS 6

    1
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
    或者
    1
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

    CentOS 7

    1
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    或者
    1
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    CentOS 8

    1
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
    或者
    1
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  3. 运行 yum makecache 生成缓存
  4. 其他
    非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置: eg:
    1
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    阿里云镜像站 Centos 镜像链接

Ubuntu

首先编辑sources.list这个文件

1
vi /etc/apt/sources.list

把sources.list文件内容替换成如下

1
2
3
4
5
6
deb http://mirrors.aliyun.com/debian wheezy main contrib non-free
deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free
deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free

ubunto 16.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

ubuntu 18.04(bionic) 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

更新软件列表

1
apt-get update

阿里云镜像站 Ubuntu 镜像链接