JiaHe's Blog

读万卷书,行万里路

一、介绍

/etc/profile

此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。并从 /etc/profile.d 目录的配置文件中收集 shell 的设置。如果你有对 /etc/profile 有修改的话必须得 source 一下你的修改才会生效,此修改对每个用户都生效。

/etc/bashrc(ubuntu为 /etc/bash.bashrc)

为每一个运行 bash shell 的用户执行此文件。当 bash shell 被打开时,该文件被读取。如果你想对所有的使用 bash 的用户修改某个配置并在以后打开的 bash 都生效的话可以修改这个文件,修改这个文件不用重启,重新打开一个 bash 即可生效。
Ubuntu没有此文件,与之对应的是/ect/bash.bashrc。

~/.bash_profile(ubuntu为 ~/.profile)

每个用户都可使用该文件输入专用于自己使用的 shell 信息,当用户登录时,该文件仅仅执行一次!默认情况下,它设置一些环境变量,执行用户的~/ .bashrc 文件。 此文件类似于 /etc/profile,也是需要需要 source 才会生效,/etc/profile 对所有用户生效,~/.bash_profile 只对当前用户生效。~/.profile(由Bourne Shell和Korn Shell使用)和.login(由C Shell使用)两个文件是.bash_profile的同义词,目的是为了兼容其它Shell。

阅读全文 »

PROBLEM

While migrating a portion of my Java code to Groovy code, I got bitten by the Groovy operator loading feature that I should have known better… and my pride hurts, but hey, I admit I write shitty code.

Consider this simple POGO with custom equals() and hashCode(), both implemented using Google Guava libraries:-

@Canonical
class Person {
String firstName
String lastName
String email

@Override
boolean equals(Object o) {
if (this == o) {
return true
}
if (o == null || getClass() != o.getClass()) {
return false
}

final Person other = (Person) o

return Objects.equal(email, other.email)
}

@Override
int hashCode() {
return Objects.hashCode(email)
}
}

What is wrong with the above code? Well, if you are mostly a Java developer like me, this look pretty much correct. However, when I perform an equality check, I get java.lang.StackOverflowError exception. I tend to see this exception when I write my too-smart-for-production recursion API that couldn’t seem find its way to end the recursion, causing the JVM stack to blow up.

SOLUTION

The reason we are getting java.lang.StackOverflowError exception is because Groovy overloads == with equals(). So, if (this == o) { ... } becomes if (this.equals(o)) { ... }. When we perform an equality check, it will call itself again and again until it chokes itself and dies.

To fix this, we have to use if (this.is(o)) { ... } to perform an identity check:-

@Canonical
class Person {
String firstName
String lastName
String email

@Override
boolean equals(Object o) {
if (this.is(o)) {
return true
}
if (o == null || getClass() != o.getClass()) {
return false
}

final Person other = (Person) o

return Objects.equal(email, other.email)
}

@Override
int hashCode() {
return Objects.hashCode(email)
}
}

.git/config
[alias]
logg = log --color --graph --decorate -M --pretty=oneline --abbrev-commit -M
sbtime = !"for k in `git branch|perl -pe s/^..//`;do echo `git show --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset\" $k|head -n 1`\\\t$k;done|sort"
sbrtime = !"for k in `git branch -r|perl -pe s/^..//`;do echo `git show --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset\" $k|head -n 1`\\\t$k;done|sort"

log

git config --global alias.logg 'log --color --graph --decorate -M --pretty=oneline --abbrev-commit -M'

原文地址:https://zhuanlan.zhihu.com/p/384752564

本文将会从:安装 -> 全局配置 -> 常用的各种配置 来书写,其中常用配置写的炒鸡详细,需要的童鞋可以直接滑倒相应的位置查看。

安装 nginx

下载 nginx 的压缩包文件到根目录,官网下载地址:https://nginx.org/download/

yum update #更新系统软件
cd /
wget nginx.org/download/nginx-1.17.2.tar.gz

解压 tar.gz 压缩包文件,进去 nginx-1.17.2

tar -xzvf nginx-1.17.2.tar.gz
cd nginx-1.17.2

进入文件夹后进行配置检查

./configure

通过安装前的配置检查,发现有报错。检查中发现一些依赖库没有找到,这时候需要先安装 nginx 的一些依赖库

yum -y install pcre* #安装使nginx支持rewrite
yum -y install gcc-c++
yum -y install zlib*
yum -y install openssl openssl-devel

再次进行检查操作 ./configure 没发现报错显示,接下来进行编译并安装的操作

# 检查模块支持
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-threads --user=www --group=www

这里得特别注意下,你以后需要用到的功能模块是否存在,不然以后添加新的包会比较麻烦。

查看默认安装的模块支持

命令 ls nginx-1.17.2 查看 nginx 的文件列表,可以发现里面有一个 auto 的目录。

在这个 auto 目录中有一个 options 文件,这个文件里面保存的就是 nginx 编译过程中的所有选项配置。

通过命令:cat nginx-1.17.2/auto/options | grep YES就可以查看

nginx 编译安装时,怎么查看安装模块

编译并安装

make && make install

这里需要注意,模块的支持跟后续的 nginx 配置有关,比如 SSL,gzip 压缩等等,编译安装前最好检查需要配置的模块存不存在。

查看 nginx 安装后在的目录,可以看到已经安装到 /usr/local/nginx 目录了

whereis nginx
$nginx: /usr/local/nginx

启动 nginx 服务

cd /usr/local/nginx/sbin/
./nginx

服务启动的时候报错了:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) ,通过命令查看本机网络地址和端口等一些信息,找到被占用的 80 端口 netstat -ntpl 的 tcp 连接,并杀死进程 (kill 进程 pid)

netstat -ntpl
kill 进程PID

继续启动 nginx 服务,启动成功

./nginx

在浏览器直接访问 ip 地址,页面出现 Welcome to Nginx! 则安装成功。

阅读全文 »