Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, August 3, 2015

How to upload vhd or file in Azure China

Step 1:

azure storage account connectionstring show --blob-endpoint gfw.blob.core.chinacloudapi.cn mcops

Step 2:

azure storage blob upload -c '<step1 string>' -f /tmp/coreos_production_azure_image.vhd --container test --blobtype page

Step 3:

azure vm image create -f -u https://gfw.blob.core.chinacloudapi.cn/vm-images/coreos_production_azure_image1.vhd -f -v CoreOS-Latest --location "China North" --os Linux https://gfw.blob.core.chinacloudapi.cn/vm-images/coreos_production_azure_image.vhd

azure vm image create myimage --blob-url https://myaccount.blob.core.chinacloudapi.cn/mycontainer/ImageName.vhd --os linux

Step 4:

azure vm create <dnsname> <imagename> -u <vmusername> -p <vmpassword> -l <location>

Friday, July 10, 2015

Starting with Strace

What is strace?

Strace is a “system call trace” program. It attaches to a process and tracks system calls and signals made to and from it (and possibly it’s children). There are limitations to strace, some of which are detailed below. However, strace can be a very valuable tool for determining the root cause of many issues. This post only covers very basic usage of strace. The example used here can be done using jailshell.

What is a process?

For the purposes of this tutorial, a process is a unique instance of program being run, identified on the system by a unique process identifier (pid). For more information seehttp://www.linfo.org/process.html and http://en.wikipedia.org/wiki/Process_identifier

What is a system call?

A system call is how a program requests that the operating system kernel perform a task for it. There are quite a few “normal” tasks that the operating system kernel does for programs regularly, including extremely common file operations like reading and writing. More information regarding system calls can be found at: http://en.wikipedia.org/wiki/System_call

What information can strace capture? Not capture?

Strace can tell you
  • what files and network connections were opened, closed, or attempted
  • what was read from and written to from said files and connections
Strace cannot tell you what is happening inside the process. It is not a debugger and is not aware of the variables used inside the process.

What do I have to know before I can use strace?

Strace is a power tool in your troubleshooting bag. But it’s not the most basic tool. General troubleshooting (checking log files, researching error messages, etc) should be done before attempting to solve a problem with strace. Before using strace, you’ll need to be able to reliably reproduce the issue so that you can catch it with strace. You’ll also need to determine what process to strace (covered later).

When am I not able to use strace?

In addition to there being times when strace will not be helpful, there are a few scenarios when you can not use strace. While most normal processes can be attached to by strace, there are some exceptions.
You cannot attach to a process in these scenarios:
  • when a debugger or other tracing program is already attached
  • when you do not own the process, unless you are running the strace as root
  • when the system has special protections preventing strace from being used to gather information

Resource considerations

Output files created by strace files do get very big very quickly, but more importantly are the numerous writes that strace output produces. This i/o hit is not mitigated (and is frequently made worse) by outputting to the terminal instead of a file.

Before you start to strace

Ensuring strace is installed

You can determine if strace is installed by typing:
strace -V
If strace is installed, you’ll see something like: strace — version 4.5.19. If it’s not installed, you’ll see something like bash: strace: command not found. Install strace with:
yum install strace
This command does require root access, so if you do not have root, you will need to request that your web hosting provider install strace for you.

Sunday, December 1, 2013

A $45 Linux SSD Laptop from China

Last week a Chinese computer company sell a laptop with $45.

There is some english information about the laptop.

Lemote ultra mini-laptop is powered by the latest design-by-China 64-bit Loongson-2F processor which speeds at 900MHz.The integrated DDR 2 and PCI 2 controllers and independently designed Northbridge chipsets.

Product characteristics:

  1. Strong computing:
    It employs the latest Loongson-2F processor, 64-bit, four-issue Out-Of-Order structure and integrated memory controller.
  2. Energy saving and environmental friendly:
    Less than 20 W, which is one tenth of an ordinary PC. The materials are ROHS compliant.
  3. Quiet operation:
    Less than 60 db.
  4. security:
    Yeeloong 8089 is a safe computing device. On one hand, the hardware components including chipset and matching motherboard are designed by Lemote wholly, which lowers the risico's being intruded by various viruses. On another hand, by employing GNU Linux operating system, it is almost immune to viruses.
  5. Infinite customization:
    The unique programmable Northbridge provides space for customization; the operation and application of free operating system could adopt a free open-source software (FOSS), which is a powerful software package management mechanism that provides the most convenient methods for users' customization and development demands to exempt from getting into the trouble of software copyright.
  6. low cost:
    The entire product, including processor, system, software and so on, are all designed by Lemote. The cost for software, hardware and synthesized usage cost is only of an ordinary PC.

Specifications

  • Processor: Loongson 2F CPU, 900MGHz, integrated DDR II and PCI 2 controllers;
  • Memory slots: SO-DIMM DDR2, 512MB;
  • South bridge: AMD CS5536;
  • Display: 1024 x 600, 8,9" TFT LCD;
  • Network: Rtl8139 + RTL8187B(wifi);
  • Interface: USB2.0x3, earphone+MIC, SDx1, RJ45x1, VGAx1, DC-inx1; SD reader supports SDHC.
  • Storage: 8G SSD;
  • Graphics: SMI712
  • Webcam: Webcam with 300K pixel
  • SD: Realtek RTS5158E
  • Size: 25,2 x 3 x 18,5cm
  • Weight: 1 kg 
  • Operating Systems: Debian Linux; Loonux; Red Flag Linux;
  • Full power: less than 20 W;
  • USB: 2 x USBBattery: 3 Cell Lithium.

Application field

It could be used as ordinary laptop as well as professional computing device for users who have higher demand for security and software customization such as institutions, prototype product development, government, corporate R & D, high education, financial and security organizations etc.

Thursday, July 4, 2013

Bind livestatus unix socket to TCP socket use Python and twisted

from twisted.internet import protocol, reactor
import socket,os

socket_path = "/var/lib/nagios3/rw/live"

class Echo(protocol.Protocol):
    def dataReceived(self, data):
 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

 s.connect(socket_path)

 s.send(data)
 s.shutdown(socket.SHUT_WR)
 answer = s.recv(100000000)
        self.transport.write(answer)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

reactor.listenTCP(6557, EchoFactory())
reactor.run()

Tuesday, August 28, 2012

如何查看screen下的窗口历史

ctrl+a [ 然后使用上下箭头,或者翻页查看。

Wednesday, June 20, 2012

Python and Linux Command

import commands
out = commands.getoutput("ls")
print out

Friday, April 6, 2012

批量下载某个网站 0001.jpg 到 0999.jpg 图片的shell脚本

for i in {1..999}; do curl -L -O http://baidu.com/images/pic_$(printf "%0.4d" $i).jpg; done

Monday, April 2, 2012

Linux版本Google Chrome更改字体方法

在Linux下的Google自然可以通过设置更改字体,不过不能选择像“sans-serif”,“monospace”这样的字体。

你需要用编辑器手工编辑 .config/google-chrome/Default/Preferences

"webkit": {
"webprefs": {
"global": {
"fixed_font_family": "monospace",
"sansserif_font_family": "sans-serif",
"serif_font_family": "serif",
"standard_font_family": "sans-serif"
},
"uses_universal_detector": true
}
}

dejavu是我一直使用的字体。

Wednesday, March 14, 2012

在哪里找Google Chrome播放的Flv缓存

这里只是 Linux上的方法

  1. 先找到PID
    ps ax | grep -i chrome | grep -i flash  

  2. 再找到文件
    file /proc/Flash_Plugin_PID/fd/* | grep -i deleted
    或者
    lsof -p Flash_plugin_pid | grep -i deleted

  3. 拷贝文件 /proc/[pid]/fd/[fileno] 到 recovered_file.flv

Tuesday, February 28, 2012

内网服务器使用SSH端口转发访问外网



很多使用我们不能在内网防火墙中的服务器上使用yum等工具,不过我们可以使用SSH来映射本地端口到服务器完成。

在你的笔记本电脑上使用以下Python(twisted)来做一个代理,当然你也可以用nodejs,Perl,或者直接用Squid等。

from twisted.web import proxy, http
from twisted.internet import reactor


class ProxyFactory(http.HTTPFactory):

    def buildProtocol(self, addr):
        return proxy.Proxy()


reactor.listenTCP(8080, ProxyFactory())
reactor.run()

 

然后把这个8080端口映射到内网服务器上的8083端口上

ssh -g -R 8083:localhost:8080 remote-server

最后在内网服务器上使用代理

export http_proxy="http://localhost:8083"

Monday, January 30, 2012

Filezilla 3.5.3 连接VsFTPd TLS问题

Response arg: error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher

/etc/vsftpd/vsftpd.conf
ssl_ciphers=HIGH

原因是
The default is DES-CBC3-SHA which seems that is not supported anymore by FileZilla

Friday, December 16, 2011

NFS quick howto for centos 5

NFS quick howto for centos 5


To use nfs successfully, you have to configure the server and the client. In this example, the client is 192.168.0.3 and the server is 192.168.0.1. The folder to be shared is /home/sharing, and to be mounted to /mnt on the client

On the server

  1. Make directory that you want to use.


    • # mkdir /home/sharing


  2. Edit /etc/exports, insert the client machine's ip


    • # vi /etc/exports


      • Add this line:




        • /home/sharing 192.168.0.3/255.255.255.255(rw,sync)


      • Save



  3. Edit /etc/hosts.allow


    • # vi /etc/hosts.allow


      • Add this line:


        • portmap: 192.168.0.0/255.255.255.0


      • Save



  4. Start nfs and portmap


    • # /etc/init.d /nfs start

    • # /etc/init.d/portmap start



On the client


  1. Start portmap


    • # /etc/init.d/portmap start


  2. Mount the nfs folder


    • # mount 192.168.0.1:/home/sharing /mnt


  3. Check /var/log/messages for any error that might occur


    • # tailf /var/log/messages


  4. Use mount to check if the folder is mounted properly


    • # mount 


      • This should be the output:


        • 192.168.0.1:/home/sharing on /mnt type nfs (rw,addr=192.168.0.1)




  5. Edit /etc/fstab to mount the shared folder on boot


    • # vi /etc/fstab


      • Add this line


        • 192.168.0.1:/mnt/sdb1/backup /mnt nfs rw,hard,intr 0 0


      • Save




You can use 'man exports' to see the options available for /etc/exports

Wednesday, October 26, 2011

Squid 2.7 通过域名反向代理多个服务器配置

[cc lang='apache' line_numbers='false']visible_hostname squid1.abc.com

#设定squid的主机名,如无此项squid将无法启动

http_port 80 accel vhost vport

#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,访问时就会出现无法找到主机头的错误

cache_peer 192.168.1.88 parent 80 0 no-query originserver name=contentchina

cache_peer 192.168.1.88 parent 80 0 no-query originserver name=bbs

cache_peer 192.168.1.1 parent 80 0 no-query originserver name=ihompy

#定义不同的父节点,将节点设为no-query以及originserver说明这些节点是实际服务器

cache_peer_domain contentchina aaa.abc.com

cache_peer_domain bbs bbb.abc.com

cache_peer_domain ihompy ccc.abc.com

#设定不同域名转发到不同的cache_peer上,如果没有这项.不同域名的域名可能被分发到同一台服务器上.

acl all src 0.0.0.0/0.0.0.0

no_cache deny all

http_access allow all

#允许所有客户端访问

cache_log /var/log/squid/cache.log

#记录日志

#***********ACL存取控制*************

#acl QueryString url_regex .php?

#***********缓冲存取控制*************

#no_cache deny QueryString

#不对符合QueryString的ACL内容进行缓冲

#***********性能优化配置*************

maximum_object_size 320010 KB

#大于此容量的对象将不会被保存在磁盘上,默认大小是4M,如果squid服务器用于缓冲flash等大型文件,建议将此值变大.否则过大的文件在下次重启后将需要重新获取

maximum_object_size_in_memory 100 KB

#最大位于内存中的对象的大小,默认大小是8K,如果服务器内存很大.可以适当提高此值的大小,建议根据网站的80%图片的大小来定.或者根据WEB服务器实际存取文件中最常访问的文件大小来定制

#***********其他可选配置*************

#dns_nameservers 10.0.0.1 192.172.0.4

#配置DNS服务器地址.获取后端时将从此dns获取IP地址

#cache_mgr ggg_g@tom.com

#在错误日志中出现的webmaster地址.

[/cc]

Monday, September 19, 2011

thinkpad只插电源适配器会锁频

在Gentoo上捣鼓 cpufreq-info 时发现只插电源适配器会锁频,可能是电源适配器只有65W 的原因。

Thursday, September 8, 2011

使用expect自动登录SSH脚本

[cc lang="bash"]#!/usr/bin/expect -f
set server [lindex $argv 0]

trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

switch -- $server \
"mail" {
spawn ssh -p 51 root@mail
expect "password:"
send "A)Q11dDuh^.\n"
interact
} "win1" {
exec rdesktop -u administrator -p "aU\$B_C%K" 192.168.111.3
} default {
puts "input a server name"
}

expect eof[/cc]

Saturday, July 9, 2011

Google chrome pac auto proxy file

don't use only exts. Swithy will broken on chrome 12. so use pac file is a good way.

[cc lang='javascript' ]
function FindProxyForURL(url, host)
{
var regexpr = /(google|googleusercontent|gmodules|chromium|linkedin|filesonic|hotfile|fbcdn|wp|scanlover|android|pusherapp|jqueryui|wordpress|tornadoweb|angrybirds|28tube|goo|fc2|youtube|twitter|facebook|ytimg).com$/;
if(regexpr.test(host))
return "SOCKS5 127.0.0.1:7070; DIRECT";
return "DIRECT";
}

[/cc]

start google chrome in command line [cci]google-chrome --proxy-pac-url=file:///home/fred/.proxy.pac[/cci]

work on debian linux.

Friday, May 20, 2011

Nagios监控报警安装

一.Nagios简介



Nagios是一款遵循GPLv2的开源网络监控软件,可用来监控指定的多种系统的主机、服务,并可在它们的工作状态发生变化时通知管理员。

  1. 监控网络服务(HTTP、POP3、SMTP、PING、MySQL等)

  2. 监控主机资源(磁盘空间利用率、内存利用率、CPU负载等)

  3. 简洁的插件设计接口,使得用户可以轻松开发所需的检测脚本

  4. 并行服务模式

  5. 轻松描述网络结构,并且能够区辨“宕机”和“主机不可达”

  6. 通过邮件或用户自定义的方式将主机或服务的工作状态变化情况通知给管理员6)当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式) ?可以通过飞信,等方式实现时,既可传递给管理员,可高效的保证服务器的维护。

  7. 自动日志滚动

  8. 支持以冗余方式进行主机监控

  9. 可以通过web方式直观的查看当前网络状态、通知和问题历史、日志文件等等,此组件为可选



Wednesday, December 22, 2010

Nginx上ETag支持

[cc lang="text"]
location ~* ^.+.(gif|jpg|css|js|png)$ {
root /var/web/static;
FileETag on;
etag_format \"%X%X\";
add_header Cache-Control max-age=0;
}
[/cc]
这样就可以返回304啦。

Thursday, September 30, 2010

让Google Chrome模拟各种手机浏览器


  • 谷歌Android:
    [cc lang='text' ]google-chrome --user-agent="Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"[/cc]

  • 苹果iPhone:
    [cc lang='text' ]google-chrome --user-agent="Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10"[/cc]

  • 诺基亚N97:
    [cc lang='text' ]google-chrome --user-agent="Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124"[/cc]

Tuesday, September 21, 2010