阿里云ECS这是个大坑

从来不用国内的服务,但是没有办法,为了速度还是只能在国内找,矮子里挑个高的,只能选择阿里云。。。但是随之而来的是各种大坑。。

ECS 封掉了25端口,也就是说你不能在上面创建任何邮件服务器。。。阿里云工单的回答是,只能使用阿里云云邮箱或者第三方,需要修改代码。。。

修改你妹妹啊。。我是直接用bash 调用postfix做发件服务,没有代码。。。

找了一晚上加一上午,目前最好的办法就是使用qq 的免费企业邮箱。。但是qq 比较鬼的是。。他在文档中没有标明有587端口。。但是你确可以使用这个端口。。。465 是ssl 端口,这样配置起来会比较麻烦。。

首先是创建qq的免费企业邮箱,得到smtp 信息

smtp:  smtp.exmail.qq.com:587

TLS

然后在centos 里面安装postfix 和 sasl 模块

sudo yum install postfix cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain -y

编辑 /etc/postfix/main.cf, 然后加上

relayhost = [smtp.exmail.qq.com]:587

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sender_dependent_authentication = yes
smtp_generic_maps = hash:/etc/postfix/generic

在/etc/postfix/sasl_passwd 里面写用户名和密码, 比如说用户名为 [email protected], 密码为iamhippo, 那么就这么写:

[smtp.exmail.qq.com]:587 [email protected]:iamhippo

在/etc/postfix/generic 要重写mail from 的地址,假如你的hostname 是i.iamhippo.com, 那么就可以写成:

@i.iamhippo.com [email protected]

 

最后就是生成hash 数据库了:

postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/generic
chmod 600 /etc/postfix/sasl_passwd*

然后我们只需要重启postfix,就大功告成

service postfix restart

/etc/fstab 详细说明

/etc/fstab 是专门用配置挂载硬盘的文件

语法为:

[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]

详细解释为:

<device>

The device/partition (by /dev location or UUID) that contain a file system.

<mount point>

The directory on your root file system (aka mount point) from which it will be possible to access the content of the device/partition (note: swap has no mount point). Mount points should not have spaces in the names.

<file system type>

Type of file system 

<options>

Mount options of access to the device/partition (see the man page for mount).

<dump>

Enable or disable backing up of the device/partition (the command dump). This field is usually set to 0, which disables it.

<pass num>

Controls the order in which fsck checks the device/partition for errors at boot time. The root device should be 1. Other partitions should be 2, or 0 to disable checking.

第一列和第二列的device 和 mount point 顾名思义,就是你想要挂载的device  和挂载的位置.

device 有两种表示方式,可以用/dev/xdx 之类的location 或者 硬件的UUID 来表示,硬件的UUID 可以用blkid 来查询

第三列的file system type 也很好理解,这里一般有auto, vfat( for FAT partition), ntfs or ntfs-3g( for NTFS partition), ext4 or ext3 or ext2 or jfs,  udf or iso9660 ( for CD/DVD), swap

第四列的option,一般用默认的defaults,但是也可以使用下面的option:

sync/async - All I/O to the file system should be done (a)synchronously.
auto - The filesystem can be mounted automatically (at bootup, or when mount is passed the -a option). This is really unnecessary as this is the default action of mount -a anyway.
noauto - The filesystem will NOT be automatically mounted at startup, or when mount passed -a. You must explicitly mount the filesystem.
dev/nodev - Interpret/Do not interpret character or block special devices on the file system.
exec / noexec - Permit/Prevent the execution of binaries from the filesystem.
suid/nosuid - Permit/Block the operation of suid, and sgid bits.
ro - Mount read-only.
rw - Mount read-write.
user - Permit any user to mount the filesystem. This automatically implies noexec, nosuid,nodev unless overridden.
nouser - Only permit root to mount the filesystem. This is also a default setting.
defaults - Use default settings. Equivalent to rw, suid, dev, exec, auto, nouser, async.
_netdev - this is a network device, mount it after bringing up the network. Only valid with fstype nfs.

第五列 dump,dump 是linux 系统中的一个备份工具,用0 来表示不备份这个区,1 表示备份。这里不适合长篇大论来讨论dump 和 fsck ,但是通过查看/etc/fstab 的例子可以看到,第五列的选项一般为0

第六列 fsck 表示fsck 是否会check这个区,一般用1 来表示根分区, 2 表示其他的分区;0表示不检查

对于第5,6列来说,

/ 一般为1 1

swap 一般为 0 0

其他分区一般为1 2

云硬盘可谓0 2

 

CentOS 开启NFS服务以及在Centos上挂在NFS

NFS 服务器这里我称之为Master服务器,IP为192.168.1.2,需要挂载NFS服务器的我称之为client,client服务器的IP为192.168.1.13

A服务器安装CentOS 6.X 64bit,首先需要安装NFS服务并且开启这个服务

yum install nfs-utils nfs-utils-lib

chkconfig nfs on 
service rpcbind start
service nfs start

其次,我们需要在Master服务器上决定我们要共享哪个文件夹,然后把文件夹目录以及符合共享,写入/etc/exports

假如说我们想共享/home目录

那么我们首先需要编辑/etc/exports

vi /etc/exports

加入以下命令:

/home 192.168.1.13(rw,sync,no_root_squash,no_subtree_check)

rw:表示client主机可以对共享的文件夹进行读和写的操作

sync: Sync confirms requests to the shared directory only once the changes have been committed.

编辑完/etc/exports以后,我们需要运行以下command来让配置生效:

exportfs -a

这样我们就完成master服务器的配置

下面我们来配置client服务器,安装nfs服务

yum install nfs-utils nfs-utils-lib

假如说我们需要把NFS挂载到/home/nfs

mkdir -p /home/nfs

mount 192.168.1.2:/home /home/nfs

这样我们就完成了挂载,可以通过df -h或者mount 来查看系统的挂载情况

但是这种挂载只是临时性的,每次我们重启,就需要重新运行一次挂载命令。为了省事,我们可以将挂载写入/etc/fstab

192.168.1.2:/home /home/nfs nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Mysql 无故crash

一入十二月,家里事多.

前几天看统计,无意间发现一个站点没有流量了,缸开始还以为是宕机了,吓我一跳,因为这个服务器上还有几个VM 跑着很重要的数据

查看了半天数据才发现原来是mysql 挂掉了

mysql 在这个VM上稳定了那么长时间,怎么会挂掉??查看了半天的err log,结果上面什么都没有

刚开始以为是innodb 的buffer 出现了问题,仔细查了查也没有问题。。。后来无意间才发现是磁盘满了。。。因为在这台VM上,我单独给mysql 添加了一块SSD硬盘,但是因为数据库读写过于频繁,mysql-bin的日志把整个硬盘都占满了。。。。

解决办法:

肯定就是删除mysql-bin.00XX文件了,但是网上都说不要直接删除,会对mysql-bin.index有损害. 但是目前mysql无法启动,也无法使用purge 来删除mysql-bin

其实解决问题很简单,首先删除mysql-bin.00001 和mysql-bin.00002, 然后打开mysql-bin.index把相应的文件名删掉就可以了,其实就是相当于手动的编辑mysql-bin.index, 和purge 的过程一样

删除一两个mysql-bin以后,就可以正常启动mysql,然后直接flush logs, reset master 就可以了,这样就会删除全部的mysql-bin,然后重新建立mysql-bin.index

最后编辑一些/etc/my.cnf, 把bin-log的失效日期改为3天就可以了

 

The magic behind configure, make, make install

If you’ve used any flavour of Unix for development, you’ve probably installed software from source with this magic incantation:

./configure

make

make install

I know I’ve typed it a lot, but in my early days using Linux I didn’t really understand what it meant, I just knew that if I wanted to install software this was the spell to recite.

Recently I’ve been building my own Unix tools, and I wanted to tap into this standard install process; not only is it familiar to many Unix users, it’s also a great starting point for building a package for Homebrew and the various Linux and BSD package managers. It was time to dig into the Unix Grimoire and find out what the incantation does.更多

ls 命令参数大全

1. List Files using ls with no option

ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.

2 List Files With option –l

Here, ls -l (-l is character not one) shows file or directory, size, modified date and time, file or folder name and owner of file and it’s permission.

3. View Hidden Files with option -a

List all files including hidden file starting with ‘.‘.

4. List Files with Human Readable Format with option -lh

With combination of -lh option, shows sizes in human readable format.

5. List Files and Directories with ‘/’ Character at the end

Using -F option with ls command, will add the ‘/’ Character at the end each directory.

6. List Files in Reverse Order

The following command with ls -r option display files and directories in reverse order.

7. Recursively list Sub-Directories

ls -R option will list very long listing directory trees. See an example of output of the command.

8. Reverse Output Order

With combination of -ltr will shows latest modification file or directory date as last.

9. Sort Files by File Size

With combination of -lS displays file size in order, will display big in size first.

10. Display Inode number of File or Directory

We can see some number printed before file / directory name. With -i options list file / directory with inode number.

11. Shows version of ls command

Check version of ls command.