Category: Linux

  • nginx常用配置及操作

    此博文意味着已经安装好了nginx php mysql : http://jpuyy.com/?p=764

    0.nginx配制文件 /usr/local/nginx/conf/nginx.conf
    1.启动nginx # /usr/local/nginx/sbin/nginx
    2.Nginx 配置文件测试:#/usr/local/nginx/sbin/nginx -t //Debug 配置文件的关键命令需要重点撑握
    3.使用ngx_http_access_module限制ip访问
    location / {
    deny 192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    deny all;
    }
    4.Nginx 配置文件修改重新加载
    方法一:
    首先查看进程PID值
    #ps aux |grep nginx
    root 2643 0.0 0.0 4804 664 ? Ss 16:36 0:00 nginx: master process /usr/local/nginx/sbin/nginx
    平滑重启,输入 kill -HUP 2643

    方法二:
    可以reload配置文件,也等于动态加载了。
    #/usr/local/nginx/sbin/nginx -s reload

    5.把nginx弄为开机启动

    Go to /etc/init.d and run sudo vim ngnix-passenger.sh
    在里面写入

    #!/bin/bash
    # this script starts the nginx process attached to passenger
    sudo /usr/local/nginx/sbin/nginx
    sudo chmod +x /etc/init.d/ngnix-passenger.sh.
    sudo /etc/init.d/ngnix-passenger.sh this will run all the code in the script.
    Verify that it launches nginx before continuing.

    Then run sudo update-rc.d ngnix-passenger.sh defaults while still in the /etc/init.d directory.
    Once all of this is in place, reboot your server and ngnix should now be automatically spawned on startup

  • nginx安装| lnmp | apache换为nginx | 禁用apache

    办公室的电脑,拿来用用,试试nginx的特性
    初步觉得要是卸载可能比较麻烦,反正电脑空间也大

     

    • 采取不卸载,停止apache服务,并禁止其开机启动的方法

    先查看apache服务

    #ps -ef | grep apache2

    root 1243 1 0 19:50 ? 00:00:00 /usr/sbin/apache2 -k start
    www-data 1264 1243 0 19:50 ? 00:00:00 /usr/sbin/apache2 -k start
    www-data 1265。。。。。。apache2 -k start
    root 3154 2796 0 20:30 pts/0 00:00:00 grep –color=auto apache2
    停止apache2

    #service apache2 stop

    * Stopping web server apache2 … waiting [ OK ]
    重启了果真又出现了,那么说明要在启动上下手

    It works!
    This is the default web page for this server.

    网上查找例子(其他都类似):
    删除apache2随机器启动的服务

    #update-rc.d -f apache2 remove

    Removing any system startup links for /etc/init.d/apache2 …
    /etc/rc0.d/K09apache2
    /etc/rc1.d/K09apache2
    /etc/rc2.d/S91apache2
    /etc/rc3.d/S91apache2
    /etc/rc4.d/S91apache2
    /etc/rc5.d/S91apache2
    /etc/rc6.d/K09apache2
    奏效

    接下来想安装nginx
    也不知道是从源里直接安装好还是编译安装好
    编译了后没成功,缺少格物致知精神
    后来用的lnmp 脚本
    nginx是起来了,但是还是有权根问题
    对各个文件目录不太熟
    导致还是请ihipop来帮忙
    经过多次实验,完整安装过程如下(以下内容 added at 2011-8-7):

    以下安装在debian下进行(ubuntu下自己有php,不需要,ubuntu的安装方法http://wiki.ubuntu.org.cn/Nginx)

    安装基本环境:

    apt-get install build-essential
    • 编译安装nginx:

    先下载好最新版本的nginxhttp://nginx.org/en/download.html

    wget http://nginx.org/download/nginx-0.8.54.tar.gz
     tar vxzf nginx-0.8.54.tar.gz
     cd nginx-0.8.54
     ./configure --with-http_ssl_module
     make && make install

    下面为编译里遇到的问题,缺少了某些库,apt-get以后就没有问题了:

    ./configure: error: the HTTP rewrite module requires the PCRE library.
    这时要执行下面命令(因为rewrite模块需要)
    apt-get install libpcre3-dev

    ./configure: error: the HTTP gzip module requires the zlib library.
    这时要执行下面命令(因为gzip模块需要)
    apt-get install zlib1g-dev

    在./configure –with-http_ssl_module时提示如下信息
    ./configure: error: SSL modules require the OpenSSL library.
    这时要执行下面命令(因为OpenSSL模块需要)
    apt-get install libssl-dev

    • 安装mysql:

    apt-get install mysql-server  php5-mysql

    过程中会提示输入mysql根用户密码

    • 安装php:

    php5-fpm的源

    deb http://packages.dotdeb.org stable all
    deb-src http://packages.dotdeb.org stable all
    deb http://php53.dotdeb.org stable all

    为省力执行下面命令:

    echo "deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.list;echo "deb-src http://packages.dotdeb.org stable all" >> /etc/apt/sources.list;echo "deb http://php53.dotdeb.org stable all" >> /etc/apt/sources.list

    加入后apt-get update出现以下提示

    正在读取软件包列表… 完成
    W: GPG 错误:http://packages.dotdeb.org stable Release: 由于没有公钥,无法验证下列签名: NO_PUBKEY E9C74FEEA2098A6E
    W: GPG 错误:http://php53.dotdeb.org stable Release: 由于没有公钥,无法验证下列签名: NO_PUBKEY E9C74FEEA2098A6E

    故通过下面命令导入公钥

    wget http://www.dotdeb.org/dotdeb.gpg
    cat dotdeb.gpg | apt-key add -

    apt-get update

    apt-get install php5-fpm

    至此,lnmp安装完成。

    要想成功解译出php,在nginx.conf 里相应 server 部分做如下修改:

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {
    root           /web/;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /web/$fastcgi_script_name;
    include        fastcgi_params;
    }

    :)EOT

  • 在ubuntu下自动pppoe拨号

    原理是当网络不通时,自动拨号

    #!/bin/bash
    #This program dial via pppoe
    #History jpuyy 2011/01/20
    # add ip / hostname separated by white space
    
    HOSTS="g.cn"
    
    # no ping request
    
    COUNT=1
    
    for myHost in $HOSTS
    do
    count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
    if [[ $count -eq 0 ]]; then
    # 100% failed
    poff
    pon dsl-provider
    fi
    done
  • Ubuntu Grub2 修复Grub2方法

    Recover Grub 2 via LiveCD

    *

    First, grab a copy of the latest Ubuntu LiveCD and boot it.
    * Open a terminal and type

    # —————————————-quick recovery begin———————–
    # $ sudo fdisk -l
    # $ sudo mount /dev/sda1 /mnt ##注意使用 你的 root分区所在的位置,也就是 / 所在的分区,可以使用 Ubuntu自带的磁盘实用工具查看
    # $ sudo mount /dev/sda2 /mnt/boot ##如果有专用的启动分区的话 挂载它
    # $ sudo mount –bind /dev /mnt/dev #这3个 比较必要,参数不用改
    $ sudo mount –bind /proc /mnt/proc
    $ sudo mount –bind /sys /mnt/sys
    # $ sudo chroot /mnt
    # # update-grub #已经是root了
    # # grub-install –recheck /dev/sda #一般一块硬盘的话,不用改了
    # # reboot #重启 就可以了

    Restore GRUB2 – Recovering from a Windows XP / Vista / 7 Reinstallation

    Fire up a terminal from the Live CD for Ubuntu 10.04.
    $ sudo fdisk -l (Note the partition number on which Linux resides)
    $ sudo mount /dev/sdaX /mnt (Replace X with the partition number housing Linux)
    $ sudo grub-install –root-directory=/mnt/ /dev/sda
    $ sudo update-grub
    $ sudo reboot

    Credits to
    http://mundogeek.net/archivos/2009/12/08/recuperar-grub-2/ for the enlightening post &
    http://www.webupd8.org/2009/12/how-to-recover-grub2-linux.html for the awesome translation.

    重点推荐 Ubuntu Grub2 完全手册:https://help.ubuntu.com/community/Grub2#Reinstalling%20GRUB%202

  • Ubuntu系统上轻松截图的几种方法介绍

    相信大家对于屏幕截图(或称抓图)应该不会陌生,在Windows平台上,我们可以使用许多第三方的专业抓图软件如SnagIt等来实现抓取屏幕图像的功能。在Ubuntu系统中,实现抓图功能的开源工具很多,用好这些工具可以让我们轻松获取任何所需的屏幕图像。本文介绍基于Ubuntu desktop 8.10(i386),GNOME集成桌面环境。
    1.使用键盘快捷键抓图
    在GNOME集成桌面环境下,我们可以使用键盘功能键Print Screen或Alt+Print Screen组合键来抓图,前者可以抓取整个屏幕的图像,而后者可以抓取当前活动窗口的图像。例如抓取整个屏幕的图像,则按下Alt+Print Screen组合键,不一会儿将弹出“保存抓图”对话框,对话框中显示截图的文件名以及图像存储的目标路径(这里我们使用默认存储路径),如点击“复制到剪贴板”按钮则将截图复制到系统剪贴板中,在其他程序中使用时只要“粘贴”过去就可以了;如点击“保存”按钮则将抓取的屏幕图像保存为文件,文件名由系统自动生成,如Screenshot.png。使用键盘快捷键来抓图,优点是快捷、方便,适用于只需要抓取全屏或某个活动窗口图像的情况。

    2.用gnome-screenshot抓图
    GNOME集成桌面环境自带了抓图工具“抓图(gnome-screenshot)”。在菜单“应用程序”→“附件”下找到“抓图”项,单击该项则运行 “抓图”程序。“抓图”程序提供了抓取整个桌面或当前活动窗口图像的功能,可以设定抓取前的延迟时间。另外,抓图程序也支持一些简单的特效,如是否包括鼠标箭头、窗口边框以及是否带有阴影效果或方框。

    需要指出的是,在GNOME集成桌面环境下,使用功能键Print Screen或组合键Alt+Print Screen来抓取屏幕图像,在后台调用的正是gnome-screenshot程序。与用键盘快捷键抓图相比,“抓图”程序增加了一些特效功能,适合于对截图有特定需求的用户。

    3.用GIMP自带的抓图功能抓图
    GIMP是Linux平台上可与Adobe Photoshop媲美的图像处理软件,该软件也自带截图的功能。在系统菜单“应用程序→图形”下找到“GIMP图片编辑器”项,单击该项运行GIMP程序。在打开的GIMP应用程序窗口的菜单“文件→Create”下找到“屏幕抓图”项,单击该项则出现“屏幕抓图”窗口。

    使用GIMP的抓图工具可以抓取整个屏幕或当前活动窗口的图像或屏幕上的选定区域。当用户点击“抓取”按钮后,抓取的图像自动出现在GIMP图像编辑器中,我们既可以利用GIMP强大的图像编辑功能直接对抓取的图像进行处理,也可以将抓取的图像以某种图像文件格式保存。

    4.功能强大的KSnapshot
    KSnapshot是KDE集成桌面环境自带的截图工具,不过在GNOME集成桌面环境下也可以安装和使用它。我们可以通过新立得软件包管理器或使用apt-get命令来安装它。假设使用命令行方式来安装,打开一个GNOME终端窗口,在终端窗口中输入如下命令:
    sudo apt-get install ksnapshot
    命令执行后,将在线下载并安装KSnapshot。安装完毕后,在菜单“应用程序”→“图像”下找到“KSnapshot”项,点击该项则运行KSnapshot程序。

    KSnapshot功能非常强大,提供的截图模式有全屏(Full Screen)、光标下的窗体(Window under cursor)、任意区域(Region)和窗体部件(Section of Window)四种。其中“光标下的窗体”抓取模式可以在不激活要抓取的窗体的情况下,只要将鼠标移动到该窗体的某个区域即可抓取该窗体。
    在输出所抓取的图像方面,KSnapshot增加了复制到剪贴板和直接打印的功能。KSnapshot应该算得上是一款较为专业的抓图工具,使用KSnapshot几乎可以轻松抓取屏幕上的任意图像,笔者推荐大家安装和使用这款软件。

    5.(2012年10月更新)安装deepin-scrot

    使用Ctrl+Alt+A截取任意大小的图,安装设置方法如下:

    http://wowubuntu.com/ubuntu-debian-install-linux-deepin-scrot.html

    apt-get install python-xlib

    dpkg -i /home/jpuyy/ubuntu_software/deepin-scrot_2.0-0deepin_all.deb

    系统设置-键盘-快捷键-添加command为deepin-scrot的快捷键 Ctrl + Alt + A

    延迟截图(Ctrl+PrintScreen)
    快速抓取屏幕(PrintScreen)
    抓取光标所在窗口(Alt+PrintScreen)

  • daemon

    daemon(发音为DEE-muhn),是一段连续运行的程序,用于处理计算机系统希望接收到的阶段性的服务需求的。Daemon程序段将请求提交给其他合适的程序(或者进程)。网络上每个页面的服务器都有一个HTTPD或者是超文本传输协议daemon,持续地等待从网络客户端及其用户发送来的请求。
    Daemon程序,又称为守护进程,通常在系统后台长时间运行,由于没有控制终端而无法与前台交互。Daemon程序一般作为系统服务使用.
    据韦伯斯特词典记载,在神话里面,daemon是“一种从事服务的力量或者精灵”。
    很可能与Daemon相混淆的还有一个demon,这个demon的含义相似,但是不同。 New Hacker的字典中说,daemon是在操作系统下直接自动运行的一段程序,而demon则是较大的应用程序中的一部分。
    在Unix等很多系统中,一般以d为结尾的程序就是一个daemon程序,它们是在后台运行的进程。
    Daemon(英语单词)
    /ˈdiːmən; `dimən/ n
    1 (esp in Greek mythology) supernatural being that is half god, half man (尤指希腊神话中的)半人半神的精灵.
    2 spirit that inspires sb to action or creativity 守护神.

    linux下直接运行daemon

    daemon –respawn –attempts=3 –delay=10 –limit=5 –name=project-sync.sh –chdir=/data/www-data –pidfiles=/data/www-data –errlog=/data0/log-data/script.err.log –output=/data0/log-data/script.out.log — php /data/www-data/script.php