分类目录归档:Summary

运维,我想过一个没有故障的春节

在过五天就是春节了,估计心急的小伙伴早已经踏上了回家的火车或者已经吃上了家里的妈妈给做的团圆饭, 现在办公室已经没有干活的气氛了,到处洋溢着喜悦的气氛, 现在在岗位的同事我用手都可以数的过来,旁边的同事回家的箱子已经放到工位了,今天晚上的火车下班直接回家;前面的同事因为是明天走,现在在安静的看新闻打发时间; 还有几个在聊天的,也许每一年只有在这个时候大家才是真正的放松,因为除了工作本身压力减少外,还有马上要跟家里人团聚的喜悦心情,这就是春节的魅力,它跟一年中每个节日都不同。

在互联网公司里,运维岗位春节假期会稍有不同,因为它是一个没有严格意义上休假的概念,因为维护是公司生产环境,分分钟故障都会影响公司收入,必须有着时刻上战场的准备, 所以作为运维人每到节假日心里都总有些不是那么痛快,一方面想的是痛快的过个好假期,另一个方面却担心如果线上出问题,因为只要有问题就要花时间去解决,说个极端的例子:比如大年初一你在家里吃团圆饭,这时你收到一个报警短信告诉你某台机器宕机了,你是不是要马上去处理,等你处理完,估计好心情都没有了。但这是我们运维人的职责,我们不必抱怨,不必自责,要明白这才是我们作为一个运维人的基本价值:保障公司线上业务的稳定。

上面的例子也许太极端,但也反应出我们运维人日常的工作场景,有没有什么办法能减少这样的事情发生,当然最简单的办法就是防患于未然, 放假前检查工作提前做,别被动等问题发生, 那该检查什么呢? 在这里我总结一些点给大家参考:

线上生成环境检查

  • 监控报警可用性检查
  • 业务是否有备机,保证机器坏了可以及时找其他机器替换。
  • 有故障可能性的机器要提前更换,别等着它挂。
  • 如果有业务节假日更新,注意更新日期,别当天一高兴喝高了,给忘记了(这事貌似每年都有)
  • 业务相关人的联系方式,这个很重要,有时候出问题不是你一个人解决的,别到时候找不到人,耽误时间。
  • 了解故障汇报机制,出问题如果不在自己的控制范围内,要及时联系领导去解决,别等着,要知道每耽搁一分钟对公司来说都是致命的。

先总结这么多,欢迎小伙伴们补充,这就马上春节了,请春节期间小伙伴注意自身安全,饮酒适度, 未来二周我讲暂停更新,确保不骚扰大家,让大家过个好年, 最后在这里也祝大家新春快乐,阖家欢乐!

如何过好2017年?

2016匆匆就过去了,除了感叹时间的流逝, 我想我还应该做点什么, 人们都说每个人对待时间的态度最大的区别就是看这个人是否有自己的目标, 星爷也说过一句特别经典的台词“人若没有目标,跟咸鱼有什么区别”,我特别赞同这句话,因为每个人的时间是有限的,如何在有限的时间内完成更多的事而不是碌碌无为的过日子,目标在这里起了决定性作用,如果每天自己都不知道自己要什么的人,我想几年之后他很可能落后于有清晰目标的人,这就跟二个人在大森林里迷了路是一样的,其中一个找到了方向,始终朝着一个方向走,相信自己终有一天能走出去,另一个没有方向的一会东走走,一会西瞅瞅,时间就这么浪费了,自己却终其一生也无法走出自己生命的藩篱。

既然知道目标的重要性,那我接下来我们看怎么定目标,不得不说定目标是件非常复杂的工程,我相信如果有2个工作摆在你面前一个是定目标,一个是写python脚本,作为运维人一般都会选择后者,为什么? 因为我们会觉得它没什么技术含量,它却要花掉你很多时间,貌似也给我们带来不了成就感,但我认为这些投入是非常值得的,如果你不投入这些时间,那么在未来你会浪费掉更多的时间, 当然考虑到这是个复杂的系统工程,为更方便的让每个人能够设定好自己2017年的目标,我列出了几个问题,大家可以根据自己的情况回答这些问题:

第一,你在过去的一年里工作上有什么进步或成果?那在2017年你希望有那些进步?

第二,在过去一年里什么事一直想做没有做?那在新的一年你打算怎么启动?

第三,你家庭或父母在过去的一年你都做了那些事情?在新的一年打算怎么做?

第四,你在过去的一年身体状况如何?那在新的一年有什么打算和爱好,身体毕竟是革命的本钱。

第五,你个人的能力方面,不管是技术方面是否有提升?在新的一年如何去做?

第六,在过去的一年你交了那些新的朋友?人际关系如何?那在新的一年你打算如何去做?如何去混入你想进入的圈子?

为符合每个人的需求,我尽可能用通用的语言来表达,当然这些问题的答案需要抽练,因为目标越简练越好, 你不能把每个问题的答案都写成5000字的作文, 如果总结到最后这一年你要做的事很多,就要排优先级,可以按时间四象限法则来划分,另外最终形成目标的过程一定是要具体的,什么是具体的的目标,我先举个反例:

2017年我要学python

这个就是典型的不具体的目标,真的具体的的目标是我要把“”python运维技术“公众号所有代码例子搞懂并实现一遍,这才是目标。

经过上面抽练,我相信大家的目标也都定出来了,接下来在2017年可以实施了,每个认都知道行动最重要,但每次都不展开行动, 为什么? 除了懒还有你缺少方法, 当然限于篇幅方法问题就不展开说了,如果有兴趣的小伙伴欢迎留言探讨,另外这句话你可打印出来放到你经常能看到的地方: Do it,  Never give up!    这也许是实现目标的最好方法没有之一。

 

看脑图学python

学一门编程语言,个人建议先要把这门语言的最基本的内容搞清楚,然后在这个基础上再逐一深入学习,那如何快速了解这些内容呢,当让用脑图是最方便的了,也是便于理解,通过脑图的学习,能让人快速掌握一门语言,以下是我在浏览国外一个网站的时候看到的,觉得不错,分享给小伙伴,希望对大家学习有些帮助,脑图是画的python3,但对学习python2同意具有借鉴意义,因为思想是一样的,别的不多说了,上图:

python-3-in-one-pic

安装paramiko报错解决

最近通过pip安装一台机器的ansible,真是费劲了周折,总结如下,安装时报

‘ascii’ codec can’t decode byte 0xe2 in position 75: ordinal not in range(128)错误,我没特别管,安装上是装上了,但ansible运行不正常,我在python命令行下,导入paramiko模块,会报这个错误,

ImportError: No module named cryptography.hazmat.backends

明显表示没安装成功cryptography这个模块,然后通过pip install来安装,发现快结束时又报

‘ascii’ codec can’t decode byte 0xe2 in position 75: ordinal not in range(128)

解决如下:

export LC_ALL=C
pip install –upgrade setuptools
以上能解决上一个报错,但再运行,
pip install  cryptography
会出现这个错误,distutils.errors.DistutilsError: Setup script exited with error: command ‘gcc’ failed with exit status 1
解决:
yum install gcc libffi-devel python-devel openssl-devel
然后,就没有问题了。
pip install  cryptography

 

具体export LC_ALL=C含义如下:

LC_ALL is the environment variable that overrides all the other localisation settings (except $LANGUAGE under some circumstances).

Different aspects of localisations (like the thousand separator or decimal point character, character set, sorting order, month, day names, language or application messages like error messages, currency symbol) can be set using a few environment variables.

You’ll typically set $LANG to your preference with a value that identifies your region (like fr_CH.UTF-8if you’re in French speaking Switzerland, using UTF-8). The individual LC_xxx variables override a certain aspect. LC_ALL overrides them all. The locale command, when called without argument gives a summary of the current settings.

For instance, on a GNU system, I get:

I can override an individual setting with for instance:

Or:

Or override everything with LC_ALL.

In a script, if you want to force a specific setting, as you don’t know what settings the user has forced (possibly LC_ALL as well), your best, safest and generally only option is to force LC_ALL.

The C locale is a special locale that is meant to be the simplest locale. You could also say that while the other locales are for humans, the C locale is for computers. In the C locale, characters are single bytes, the charset is ASCII (well, is not required to, but in practice will be in the systems most of us will ever get to use), the sorting order is based on the byte values, the language is usually US English (though for application messages (as opposed to things like month or day names or messages by system libraries), it’s at the discretion of the application author) and things like currency symbols are not defined.

On some systems, there’s a difference with the POSIX locale where for instance the sort order for non-ASCII characters is not defined.

You generally run a command with LC_ALL=C to avoid the user’s settings to interfere with your script. For instance, if you want [a-z] to match the 26 ASCII characters from a to z, you have to set LC_ALL=C.

On GNU systems, LC_ALL=C and LC_ALL=POSIX (or LC_MESSAGES=C|POSIX) override $LANGUAGE, while LC_ALL=anything-else wouldn’t.

A few cases where you typically need to set LC_ALL=C:

  • sort -u or sort ... | uniq.... In many locales other than C, on some systems (notably GNU ones), some characters have the same sorting order. sort -u doesn’t report unique lines, but one of each group of lines that have equal sorting order. So if you do want unique lines, you need a locale where characters are byte and all characters have different sorting order (which theC locale guarantees).
  • the same applies to the = operator of POSIX compliant expr or == operator of POSIX compliant awks (mawk and gawk are not POSIX in that regard), that don’t check whether two strings are identical but whether they sort the same.
  • Character ranges like in grep. If you mean to match a letter in the user’s language, use grep '[[:alpha:]]' and don’t modify LC_ALL. But if you want to match the a-zA-Z ASCII characters, you need either LC_ALL=C grep '[[:alpha:]]' or LC_ALL=C grep '[a-zA-Z]'. [a-z] matches the characters that sort after a and before z (though with many APIs it’s more complicated than that). In other locales, you generally don’t know what those are. For instance some locales ignore case for sorting so [a-z] in some APIs like bash patterns, could include [B-Z] or [A-Y]. In many UTF-8 locales (including en_US.UTF-8 on most systems), [a-z] will include the latin letters from a to y with diacritics but not those of z (since z sorts before them) which I can’t imagine would be what you want (why would you want to include é and not ź?).
  • floating point arithmetic in ksh93. ksh93 honours the decimal_point setting in LC_NUMERIC. If you write a script that contains a=$((1.2/7)), it will stop working when run by a user whose locale has comma as the decimal separator:

    Then you need things like:

    As a side note: the , decimal separator conflicts with the , arithmetic operator which can cause even more confusion.
  • When you need characters to be bytes. Nowadays, most locales are UTF-8 based which means characters can take up from 1 to 6 bytes. When dealing with data that is meant to be bytes, with text utilities, you’ll want to set LC_ALL=C. It will also improve performance significantly because parsing UTF-8 data has a cost.
  • a corollary of the previous point: when processing text where you don’t know what character set the input is written in, but can assume it’s compatible with ASCII (as virtually all charsets are). For instance grep '<.*>' to look for lines containing a <, > pair will no work if you’re in a UTF-8 locale and the input is encoded in a single-byte 8-bit character set like iso8859-15. That’s because . only matches characters and non-ASCII characters in iso8859-15 are likely not to form a valid character in UTF-8. On the other hand, LC_ALL=C grep '<.*>' will work because any byte value forms a valid character in the C locale.
  • Any time where you process input data or output data that is not intended from/for a human. If you’re talking to a user, you may want to use their convention and language, but for instance, if you generate some numbers to feed some other application that expects English style decimal points, or English month names, you’ll want to set LC_ALL=C:

    That also applies to things like case insensitive comparison (like in grep -i) and case conversion (awk‘s toupper(), dd conv=ucase…). For instance:

    is not guaranteed to match on I in the user’s locale. In some Turkish locales for instance, it doesn’t as upper-case i is İ (note the dot) there and lower-case I is ı (note the missing dot).

 

公有云会淘汰那些运维职业?

在现在,公有云的发展,绝对不容我们每个运维人忽视,它带给我们运维人翻身便利的同时,也对我们运维的某些岗位带来了冲击,以下以我个人理解随着公有云的发展那些岗位会被影响:

第一,IDC基础运维岗位,就是负责在公司安装机器、上架插线的岗位,会被逐渐替换掉,因为IAAS,即基础实施即服务,公有云现在基本都在做的这块,人家都把这块做出服务卖了,如果价格便宜,所以公司是在没必要自己做这些毫无价值的内容了。

第二,网络工程师岗位,网络工程师一直以来市场需求就不高,那随着公有云的成熟,就更不要网络工程师的存在了,因为公有云都帮你实现好了,而且超出你的期望满足你的需求,所以这些岗位会慢慢缩减,但不会消失,一些高手还可以去BAT发展,但要趁早了。

第三,服务器硬件评测工程师,就是在物理机时代,公司为了更好的选择好机器不出问题,保证业务的稳定,所以在公司设立对各个厂家服务器评测的工程师,因为使用云了,基本的硬件内容就不需要去考虑了,性能也不用考虑了,公有云可以随时动态调整云主机配置,这部分岗位会大大缩减,但不会消失,因为BAT还是需要的。

以上只是个人的一些理解,不代表权威, 同时做运维的兄弟进行交流。