Apache Couldn't start ErrorLog process

Geek小A 回复了问题 2 人关注 2 个回复 7692 次浏览 2015-09-20 12:39 来自相关话题

Nginx源码安装错误分析一则

Geek小A 发表了文章 0 个评论 2655 次浏览 2015-09-19 00:19 来自相关话题

    最近跟一个公司合作,要把我们的应用安装在他们的服务器上,不过问题来了。他们为了他们自己服务器安全,不给我们root权限,只给了我们普通用户权限,所有的程序都要装在规定的路径里,限制可不少。没办法装吧~~~       我登录到服 ...查看全部
nginx_logo.png

    最近跟一个公司合作,要把我们的应用安装在他们的服务器上,不过问题来了。他们为了他们自己服务器安全,不给我们root权限,只给了我们普通用户权限,所有的程序都要装在规定的路径里,限制可不少。没办法装吧~~~
 
    我登录到服务器上一看傻了,rpm -qa 一查 需要的包没装几个。一个个下源码包就装吧~~ 到源码站下载了一大堆包开始装,pcre openssl xml mhash mcrypt等等一步步开始装,磕磕绊绊少什么装什么终于装到了nginx 结果make的时候报错了:
make -f objs/Makefile
make[1]: Entering directory `/data/source/nginx'
cd /usr/local/ufo/lib/pcre \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared
/bin/sh: ./configure: No such file or directory
make[1]: *** [/usr/local/services/lib/pcre/Makefile] Error 127
make[1]: Leaving directory `/data/source/nginx-0.7.61'
make: *** [build] Error 2
    我明明指定了 pcre的路径啊 我又仔细看了看路径是不是有问题!没问题啊,奇怪了我指定了路径怎么会 出现这样的过程呢 cd /usr/local/ufo/lib/pcre 他去安装目录 运行什么 ./configure 啊!
 
    这时我的一个同事仔细看了看 ./configure --help 然后让我看看下面这条
    原来是这样啊~~嗨
--with-pcre                     force PCRE library usage
--with-pcre=DIR set path to PCRE library sources
    原来这个路径指定的是 源码包所在的路径啊~~~晕,nginx为什么要去自己重现编译pcre 呢?

    指定源码包的路径吧 ./configure ...... --with-pcre=/data/source/pcre

    再次make OK 一切顺利,终于装上了。
 
    我在网上搜索的时候发现很多朋友遇到了这个问题,但是没有什么好的办法 (当然,因为没有root权限是没法安装rpm包的,其实只要装上pcre-devel包就好了)
    
    呵呵,希望遇到这种情况的朋友能看到我的这篇帖子O(∩_∩)O~
    原文地址:开源技术社区转载分享

Netstat命令详解

koyo 发表了文章 0 个评论 4953 次浏览 2015-09-13 13:48 来自相关话题

简介     Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。   ...查看全部
简介
    Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。
 
输出信息含义
    执行netstat后,其输出结果为
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 2 210.34.6.89:telnet 210.34.6.96:2873 ESTABLISHED
tcp 296 0 210.34.6.89:1165 210.34.6.84:netbios-ssn ESTABLISHED
tcp 0 0 localhost.localdom:9001 localhost.localdom:1162 ESTABLISHED
tcp 0 0 localhost.localdom:1162 localhost.localdom:9001 ESTABLISHED
tcp 0 80 210.34.6.89:1161 210.34.6.10:netbios-ssn CLOSE

Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 1 [ ] STREAM CONNECTED 16178 @000000dd
unix 1 [ ] STREAM CONNECTED 16176 @000000dc
unix 9 [ ] DGRAM 5292 /dev/log
unix 1 [ ] STREAM CONNECTED 16182 @000000df
    从整体上看,netstat的输出结果可以分为两个部分:
        一个是Active Internet connections,称为有源TCP连接,其中"Recv-Q"和"Send-Q"指%0A的是接收队列和发送队列。这些数字一般都应该是0。如果不是则表示软件包正在队列中堆积。这种情况只能在非常少的情况见到。
 
        另一个是Active UNIX domain sockets,称为有源Unix域套接口(和网络套接字一样,但是只能用于本机通信,性能可以提高一倍)。
Proto显示连接使用的协议,RefCnt表示连接到本套接口上的进程号,Types显示套接口的类型,State显示套接口当前的状态,Path表示连接到套接口的其它进程使用的路径名。
 
常见参数
-a (all)显示所有选项,默认不显示LISTEN相关
-t (tcp)仅显示tcp相关选项
-u (udp)仅显示udp相关选项
-n 拒绝显示别名,能显示数字的全部转化成数字。
-l 仅列出有在 Listen (监听) 的服務状态

-p 显示建立相关链接的程序名
-r 显示路由信息,路由表
-e 显示扩展信息,例如uid等
-s 按各个协议进行统计
-c 每隔一个固定时间,执行该netstat命令。

提示:LISTEN和LISTENING的状态只有用-a或者-l才能看到
实用命令实例


1. 列出所有端口 (包括监听和未监听的)


列出所有端口 netstat -a
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 [i]:[/i] LISTEN
udp 0 0 [i]:bootpc [/i]:*

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 6135 /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 5140 /var/run/acpid.socket
列出所有 tcp 端口 netstat -at
# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 [i]:[/i] LISTEN
tcp 0 0 localhost:ipp [i]:[/i] LISTEN
tcp 0 0 [i]:smtp [/i]:* LISTEN
tcp6 0 0 localhost:ipp [::]:* LISTEN
列出所有 udp 端口 netstat -au
# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 [i]:bootpc [/i]:*
udp 0 0 [i]:49119 [/i]:*
udp 0 0 [i]:mdns [/i]:*


  1. 列出所有处于监听状态的 Sockets


只显示监听端口 netstat -l
# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:ipp [i]:[/i] LISTEN
tcp6 0 0 localhost:ipp [::]:* LISTEN
udp 0 0 *:49119
只列出所有监听 tcp 端口 netstat -lt
# netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 [i]:[/i] LISTEN
tcp 0 0 [i]:smtp [/i]:* LISTEN
tcp6 0 0 localhost:ipp [::]:* LISTEN
只列出所有监听 udp 端口 netstat -lu
# netstat -lu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 [i]:49119 [/i]:*
udp 0 0 [i]:mdns [/i]:*
只列出所有监听 UNIX 端口 netstat -lx
# netstat -lx
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 6294 private/maildrop
unix 2 [ ACC ] STREAM LISTENING 6203 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 6302 private/ifmail
unix 2 [ ACC ] STREAM LISTENING 6306 private/bsmtp


  1. 显示每个协议的统计信息


显示所有端口的统计信息 netstat -s
# netstat -s
Ip:
total packets received
with invalid addresses
forwarded
incoming packets discarded
incoming packets delivered
requests sent out
Icmp:
ICMP messages received
input ICMP message failed.
Tcp:
active connections openings
failed connection attempts
connection resets received
Udp:
packets received
packets to unknown port received.
.....
显示 TCP 或 UDP 端口的统计信息 netstat -st 或 -su
# netstat -st 
# netstat -su


  1. 在 netstat 输出中显示 PID 和进程名称 netstat -p


netstat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 netstat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。
# netstat -pt
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 1 0 ramesh-laptop.loc:47212 192.168.185.75:www CLOSE_WAIT 2109/firefox
tcp 0 0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox

 


  1. 在 netstat 输出中不显示主机,端口和用户名 (host, port or user)


当你不想让主机,端口和用户名显示,使用 netstat -n。将会使用数字代替那些名称。

同样可以加速输出,因为不用进行比对查询。
# netstat -an
如果只是不想让这三个名称中的一个被显示,使用以下命令
# netsat -a --numeric-ports
# netsat -a --numeric-hosts
# netsat -a --numeric-users


  1. 持续输出 netstat 信息


netstat 将每隔一秒输出网络信息。
# netstat -c
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 ramesh-laptop.loc:36130 101-101-181-225.ama:www ESTABLISHED
tcp 1 1 ramesh-laptop.loc:52564 101.11.169.230:www CLOSING
tcp 0 0 ramesh-laptop.loc:43758 server-101-101-43-2:www ESTABLISHED
tcp 1 1 ramesh-laptop.loc:42367 101.101.34.101:www CLOSING
^C


  1. 显示系统不支持的地址族 (Address Families)


netstat --verbose
在输出的末尾,会有如下的信息
netstat: no support for `AF IPX' on this system.
netstat: no support for `AF AX25' on this system.
netstat: no support for `AF X25' on this system.
netstat: no support for `AF NETROM' on this system.


  1. 显示核心路由信息 netstat -r


# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth2
link-local * 255.255.0.0 U 0 0 0 eth2
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth2
注意: 使用 netstat -rn 显示数字格式,不查询主机名称。
 


  1. 找出程序运行的端口


并不是所有的进程都能找到,没有权限的会不显示,使用 root 权限查看所有的信息。
# netstat -ap | grep ssh
tcp 1 0 dev-db:ssh 101.174.100.22:39213 CLOSE_WAIT -
tcp 1 0 dev-db:ssh 101.174.100.22:57643 CLOSE_WAIT -
找出运行在指定端口的进程
# netstat -an | grep ':80'


  1. 显示网络接口列表


查看连接某服务端口最多的的IP地址
wss8848@ubuntu:~$ netstat -nat | grep "192.168.1.15:22" |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20
221.136.168.36
154.74.45.242
78.173.31.236
62.183.207.98
192.168.1.14
182.48.111.215
124.193.219.34
119.145.41.2
114.255.41.30
75.102.11.99
TCP各种状态列表
wss8848@ubuntu:~$ netstat -nat |awk '{print $6}'
established)
Foreign
LISTEN
TIME_WAIT
ESTABLISHED
TIME_WAIT
SYN_SENT
先把状态全都取出来,然后使用uniq -c统计,之后再进行排序。
wss8848@ubuntu:~$ netstat -nat |awk '{print $6}'|sort|uniq -c
ESTABLISHED
FIN_WAIT1
Foreign
LAST_ACK
LISTEN
SYN_SENT
TIME_WAIT
established)
最后的命令如下:
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
分析access.log获得访问前10位的ip地址
awk '{print $1}' access.log |sort|uniq -c|sort -nr|head -10
参考资料:http://blog.maxiang.net/10-netstat-command-examples/139/
                http://www.ipcpu.com/2011/07/netstat-linux/

Nginx开启HTTP/2

koyo 发表了文章 0 个评论 2900 次浏览 2015-09-13 13:11 来自相关话题

具体操作步骤: []安装oneinstack一键包配置生产环境(步骤略)[/][]获取Nginx原有编辑配置[/][]编译及安装HTTP/2[/][]配置HTTP/2​[/] cd oneinstack/src tar xz ...查看全部
具体操作步骤
    []安装oneinstack一键包配置生产环境(步骤略)[/][]获取Nginx原有编辑配置[/][]编译及安装HTTP/2[/][]配置HTTP/2​[/]

cd oneinstack/src
tar xzf nginx-1.9.4.tar.gz
cd nginx-1.9.4
# /usr/local/nginx/sbin/nginx -V #查看nginx已经编译参数 千万要去除--with-http_spdy_module,与HTTP/2有冲突!
wget http://nginx.org/patches/http2/patch.http2.txt
patch -p1 --dry-run < patch.http2.txt
patch -p1 < patch.http2.txt
make clean
./configure --prefix=/usr/local/nginx --user=www --group=www \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
配置HTTP/2
在.conf文件中添加如下:
server {
listen 443 ssl http2 default_server;

ssl_certificate server.crt;
ssl_certificate_key server.key;
...
}
重启Nginx(service nginx restart)网站就成功开启HTTP/2了。

ssh远程链接不上

OpenSkill 回复了问题 2 人关注 1 个回复 4084 次浏览 2015-09-12 19:56 来自相关话题

Apache无法解析PHP代码问题分析

Ansible 发表了文章 0 个评论 4643 次浏览 2015-09-11 21:19 来自相关话题

源码安装Apache 和PHP, Apache的版本是httpd-2.2.12.tar.gz,PHP的版本是php-5.3.6.tar.gz Apache编译参数如下:./configure --prefix=/usr/local/apache2 ...查看全部
源码安装Apache 和PHP, Apache的版本是httpd-2.2.12.tar.gz,PHP的版本是php-5.3.6.tar.gz
Apache编译参数如下:
./configure --prefix=/usr/local/apache2 --disable-authn-file --disable-authn-default --disable-authz-groupfile --disable-authz-user --disable-authz-default --disable-auth-basic --disable-include --enable-so --with-mpm=prefork 
PHP编译参数如下:
./configure --prefix=/usr/local/php5.3.6 --with-apxs2=/usr/local/apache2/bin/apxs --enable-mbstring --with-curl --with-openssl  --with-zlib --enable-sockets --enable-ftp  --with-mysql --with-openssl --with-gd --with-png-dir --with-jpeg-dir  --with-freetype-dir --enable-sockets  --enable-pcntl --with-mhash --with-mcrypt --enable-bcmath --with-gettext --enable-zip --with-pdo-mysql
安装完PHP后将安装源文件中的 cp php.ini-dist     /usr/local/php5.3.6/lib/php.ini
 
安装完成后配置Apache,写个php的info页面test.php:

phpinfo();
?>
然后用浏览器访问test.php,页面出现的是test.php文件中的内容,并不是php的info信息。
 
在Apache中的配置文件httpd.conf中添加AddType application/x-httpd-php .php,重启APACHE,还是出现同样的错误。
 
而且Apache的配置文件已经加载了PHP的模块LoadModule php5_module        modules/libphp5.so。最后发现是由于Apache的配置文件缺少如下的配置:
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
然后重启Apache,代码可以正常解析了!
 

PHP编译安装报Cannot find libmysqlclient under /usr错误

Ansible 回复了问题 2 人关注 1 个回复 5090 次浏览 2015-09-10 23:04 来自相关话题

zabbix怎么重置密码

koyo 回复了问题 2 人关注 1 个回复 4844 次浏览 2015-09-10 11:30 来自相关话题

Python编写HDFS Datanode监控进程并自动恢复

OpenSkill 发表了文章 0 个评论 3197 次浏览 2015-09-10 01:17 来自相关话题

    因为hadoop集群中datanode是大量存在的,那么多机器,什么事都可能发生,最通常的大概就是进程挂掉了。所以为了省事,参考别人的代码写了这个监控进程的daemon。当然,稍加修改就可以用来监控别的必须常驻的进程。只需start,不用后面跟&或者前 ...查看全部
    因为hadoop集群中datanode是大量存在的,那么多机器,什么事都可能发生,最通常的大概就是进程挂掉了。所以为了省事,参考别人的代码写了这个监控进程的daemon。当然,稍加修改就可以用来监控别的必须常驻的进程。只需start,不用后面跟&或者前面加nohup。
    
    其实很多人都对进程挂掉很头疼,没事半夜得爬起来上服务器启动进程是一件非常痛苦的事情。
 
    每2秒监测一次进程,发现进程消失就重启进程。主要原理是fork出子进程,然后将子进程挂起,并退出父进程。其程序本身作为被监控进程的外壳程序存在。
#!/usr/bin/env python

import sys, os, time, atexit, string
from signal import SIGTERM

class Daemon:
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
#需要获取调试信息,改为stdin='/dev/stdin', stdout='/dev/stdout', stderr='/dev/stderr',以root身份运行。
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile

def _daemonize(self):
try:
pid = os.fork()
if pid > 0:
#退出主进程
sys.exit(0)
except OSError, e:
sys.stderr.write('fork #1 failed: %d (%s)\n' % (e.errno, e.strerror))
sys.exit(1)

os.chdir("/")
os.setsid()
os.umask(0)

#创建子进程
try:
pid = os.fork()
if pid > 0:
sys.exit(0)
except OSError, e:
sys.stderr.write('fork #2 failed: %d (%s)\n' % (e.errno, e.strerror))
sys.exit(1)

#重定向文件描述符
sys.stdout.flush()
sys.stderr.flush()
si = file(self.stdin, 'r')
so = file(self.stdout, 'a+')
se = file(self.stderr, 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())

#创建processid文件
atexit.register(self.delpid)
pid = str(os.getpid())
file(self.pidfile,'w+').write('%s\n' % pid)

def delpid(self):
os.remove(self.pidfile)

def start(self):
#检查pid文件是否存在以探测是否存在进程
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
pid = None

if pid:
message = 'pidfile %s already exist. Daemon already running?\n'
sys.stderr.write(message % self.pidfile)
sys.exit(1)

#启动监控
self._daemonize()
self._run()

def stop(self):
#从pid文件中获取pid
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
pid = None

if not pid:
message = 'pidfile %s does not exist. Daemon not running?\n'
sys.stderr.write(message % self.pidfile)
return #重启不报错

#杀进程
try:
while 1:
os.kill(pid, SIGTERM)
time.sleep(0.1)
os.system('/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh stop datanode')
os.system('/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh stop tasktracker')
except OSError, err:
err = str(err)
if err.find('No such process') > 0:
if os.path.exists(self.pidfile):
os.remove(self.pidfile)
else:
print str(err)
sys.exit(1)

def restart(self):
self.stop()
self.start()

def _run(self):
while True:
datanode = os.popen('ps -fe | grep "java" | grep "datanode" | grep -v "grep" | wc -l').read().strip()
tasktracker = os.popen('ps -fe | grep "java" | grep "tasktracker" | grep -v "grep" | wc -l').read().strip()
#选出进程中含有java且含有datanode|tasktracker且不含有grep,计算出现行数。修改上面的进程监控语句以适应其他应用需求
if datanode == '0':
os.system('/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh start datanode')
#修改这里的启动命令
if tasktracker == '0':
os.system('/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh start tasktracker')
#修改这里的启动命令
time.sleep(2)
#修改这里的停留时间



if __name__ == '__main__':
daemon = Daemon('/tmp/watch_process.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print 'Unknown command'
sys.exit(2)
sys.exit(0)
else:
print 'usage: %s start|stop|restart' % sys.argv[0]
sys.exit(2)
    实际使用中还是比较好用的,把该程序加入到启动文件中,重启服务器,服务器重启后会自动启动其所监控的进程。用到的都是python的基本模块,不会存在依赖缺失问题。
#/bin/sh
while true;
do
count=`ps -fe | grep "java" | grep "datanode" | grep -v "grep"`
if [ "$?" != "0" ]; then
/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh start datanode
fi
sleep 2
done
#/bin/sh
while true;
do
count=`ps -fe | grep "java" | grep "tasktracker" | grep -v "grep"`
if [ "$?" != "0" ]; then
/opt/modules/hadoop/hadoop-0.20.203.0/bin/hadoop-daemon.sh start tasktracker
fi
sleep 2
done
其实作用是一样的,只是一个前台,一个后台。一个利用bash,一个利用python。
转载原文地址:原文地址

ubuntu snmpwalk error

Ansible 回复了问题 2 人关注 2 个回复 4807 次浏览 2015-09-09 16:06 来自相关话题