Apr23

配置Trac+Apache小记

Author: leeon  Click: 9437   Comments: 0 Category: 其他  Tag: trac,python,apache

trac-admin在initenv环境的时候提示如下错误:

[code="plain"]
Trac Error: Cannot load Python bindings for SQLite
[/code]

重新下载pysqlite重新安装即可

http://code.google.com/p/pysqlite/downloads/list

 

另外在编译mod_python的时候提示:
connobject.c: 在函数‘_conn_read’中:
connobject.c:142: 错误: 在非结构或联合中请求成员‘next’
apxs:Error: Command failed with rc=65536

类似错误
解决方案:

修改src/connobject.c第142行
把!(b == APR_BRIGADE_SENTINEL(b) || 改为!(b == APR_BRIGADE_SENTINEL(bb) ||

 

启动trac其实有多种方式,如果追求性能最好让trac运行在webserver上,那么apache就派上用场了,给apache安上mod_python,这里有些可以记录的:



DocumentRoot /data/trac/ 
ServerName trac.example.com
#让解析根的时候就后台去运行trac的cgi,这个cgi在trac目录cgi-bin下
alias / /install_bak/trac/cgi-bin/trac.cgi

#开启python支持
SetHandler mod_python
PythonInterpreter main_interpreter
#把请求交给trac去执行
PythonHandler trac.web.modpython_frontend
#trac项目所在目录
PythonOption TracEnv /data/trac
#trac项目url访问目录
PythonOption TracUriRoot /

如何给Trac加上验证?

答:我这里给绑定的是http的验证,只要在apache的httpd.conf里面配置:

    
        AuthType Basic
        AuthName MemNote
        AuthUserFile /data/trac/trac.passwd
        Require valid-user
       

注意location的访问路径,另外authuserfile中的文件使用htpasswd命令创建,注意最好不要用-p参数,加了p参数后密码是明文,trac验证会失败。

创建用户的命令:

[code="bash"]
htpasswd -c trac.passwd admin
[/code]

具体的权限操作可以通过trac-admin来绑定admin的权限组

Trac汉化问题解决:

1. 安装babel
sudo easy_install babel
或者
sudo easy_install babel

如果自己的centos升级过python的话自带的python-setuptools有可能有问题,不能用rpm包的,需要自己重新安装easy_install,这时候easy_install命令有可能不再/usr/bin的目录下,有可能安装在自己安装的python版本的bin目录下,例如:/usr/local/python2.7/bin
2. 生成pot
python setup.py extract_messages
3. 编译po(这里可以指定编译为哪种语言,不指定就是全部)
python setup.py update_catalog
4. 检查你要的语言装了没
python setup.py update_catalog -l zh_CN
5. 编译为mo
setup.py compile_catalog -f
6. 安装trac
python setup.py install

这时用中文浏览器访问,显示的就是中文了

Apr23

【转载】Linux常用服务ACL规则详解

Author: 匿名  Click: 9162   Comments: 0 Category: linux  Tag: linux,acl,http,tcp,nfs,mail

前几年学的不用也忘的差不多了,重新记录一下。

-------------------------------------------------------------------------------------------------------

本文主要讲解服务程序有:apache、tcp_wapper、sendmail、samba、nfs、squid、ssh的访问控制。

实验中可以用修改/etc/hosts文件加

127.0.0.1 student.example.com student localhost.localdomain localhost
192.168.100.102 student1.example.com student1
192.168.100.103 abc.crack.org abc

apache测试
----------回顾
deny from 192.168.100.
deny from 192.168.100
deny from 192.168.100.101/24
都可以


域名用.example.com

Order allow,deny
allow from .example.com
表示只允许.example.com访问。
果加上deny from all,表示全部都拒绝,

order deny,allow
deny from .example.com
表示只拒绝.example.com
如果加上allow from all 表示全部都允许,


Deny,Allow
Deny指令在 Allow指令之前被评估。缺省允许所有访问。 任何不匹配Deny指令或者匹配 Allow指令的客户都被允许访问服务器。
Allow,Deny
Allow指令在 Deny指令之前被评估。缺省禁止所有访问。 任何不匹配Allow指令或者匹配 Deny指令的客户都将被禁止访问服务器。

用户登陆认证

directory中加
AllowOverride AuthConfig

在限制的目录下
.htaccess 这个名字固定 千万注意不要写错
写入
AuthName "Auth service"
AuthType basic
AuthUserFile /etc/httpd/conf/.htpasswd 这个名字和位置都不固定,
require valid-user


用htpasswd -c /etc/httpd/conf/.htpasswd 用户名


\\\\\\\\\小结\\\\\\\\\\
只允许.example.com的域访问。
Order allow,deny
allow from .example.com

只不允许.example.com访问
Order deny,allow
deny from .example.com


********************************************************************************************
tcp_wapper
----回顾

1。tcpd先检查hosts.allow再检查hosts.deny,如果前者允许的IP或者域名 后者即使有也不起作用


2。写法不支持24/32/8等mask的写法,必须把掩码写全
如:
sshd: 192.168.0.0/255.255.255.0
单个IP可以不写。
域名用 .example.com


还可以写sshd: all except .example.com

3。rhel3里常用
sshd
vsftpd
ipop3d


例题:
ssh可以被本地子网访问,但是不能让其他网段的用户访问
/etc/hosts.deny
sshd :ALL EXCEPT 192.168.0.

\\\\\\\\\小结\\\\\\\\\\
只允许example.com访问
hosts.allow
sshd:ALL EXCEPT .example.com
hosts.deny无

只不允许example.com访问
hosts.deny
sshd:ALL EXCEPT .example.com
hosts.allow无

**以上的理解是错误的,在tcp_wrapper中,拒绝只能用host.deny**

如果只允许example.com访问
hosts.allow 写sshd:.example.com
hosts.deny 写sshd:all

如果只不允许example.com访问
hosts.allow不写
hosts.deny 写sshd:.example.com

所以:
对于sshd:ALL EXCEPT .example.com这一句,表示的是hosts.allow中对sshd 都允许进入但是除了example.com不运用这个规则,但不表示拒绝,只是表示不进入,如果想拒绝还需要在 hosts.deny中加规则。


***********************************************************************************************
sendmail
写入文件
access中

192.168.0 拒绝是REJECT
无最后的点

域名

******************************************************************************************

ssh限制
如果限制用户登陆
在sshd_config中加入
AllowUsers root 那么除了这个用户都不可以登陆
DenyUsers sshtest 那么对这个用户拒绝登陆
************************************************************************************************


samba限制
------回顾
机制和tcp_wrapper一样,先看allow再看deny

hosts deny = 150.203.4. badhost.mynet.edu.au

hosts allow = 150.203. EXCEPT 150.203.6.66

hosts deny = all except .crack.org

hosts allow = 192.168.100.

Where the lists conflict, the allow list takes precedence.
如果冲突以allow优先。


\\\\\\\\\小结\\\\\\\\\\
只允许example.com访问
hosts allow = .example.com(如果同时不写hosts deny,默认deny all)
或者
hosts deny = all except .example.com

只拒绝example.com访问
hosts deny = .example.com

注意:这里也不能加hosts allow =all,不需要如果有了hosts.deny默认允许其他,加了反而允许全部访问,因为allow优先,和apache里的设置类似。


************************************************************************************
nfs限制


/var/smbtest *.example.com(ro,no_root_squash,async) *.crack.org(rw,root_squash,sync)
注意这里域名前要用 * 号

ip写法:
192.168.100.* == 192.168.100.0/24

/usr/src *.siyongc.domain(ro,root_squash,sync) 192.168.100.*(ro,root_squash,sync)
/var/ftp/pub/incoming 192.168.100.24(rw,all_squash,anonuid=50,anongid=50)


只允许example.com访问
/var/smbtest *.example.com(ro,no_root_squash,async)

**************************************************************************************
squid限制


和sendmail一样默认是deny all

他的规则和tcp_wrapper一样,如果allow通过,那么将不在检查deny

写法 需要先定义,然后在使用


搜索acl all,在之前定义
acl example src 192.168.100.0/24

acl spams dstdomain .hotmail.com

然后 搜索YOUR,使用
http_access deny spams
http_access allow example


只为.example.com的域提供代理,拒绝允许代理的域访问 .hotmail.com的页面
acl allowdomain srcdomain .example.com
acl spams dstdomain .hotmail.com
http_access deny spams
http_access allow example

Apr23

【原创】Linux常用服务domain写法

Author: leeon  Click: 7082   Comments: 0 Category: linux  Tag: domain,service

一、tcp_wrapper 中表示网段的方法

192.168.0.               or   192.168.0.0/255.255.255.0

  域的表示方法为:

   .example.com

 

二、NFS 中网段的表示方法

  192.168.0.0/24     192.168.0.0/255.255.255.0

  域的表示方法

  *.example.com

 

三、samba  中表示网段的方法

  192.168.0.        192.168.0.0/255.255.255.0  192.168.0.0/24

  .example.com

 

四、sendmail 中表示网段的方法

  192.168.0   /etc/mail/access 中的写法     192.168.0. or 192.168.0.0/255.255.255.0

  example.com

 

五、iptables

  192.168.0.0/24 or   192.168.0.0/255.255.255.0

  

 

六、http

  192.168.0.0/24      192.168.0.0/255.255.255.0

  .example.com     

 

 

注:

0.0.0.0/255.255.255.0 的网段表示法只在xinetd telnet中不生效其它服务均能适用。

 

Apr8

【转载】MySQL中主从复制重复键问题修复

Author: 老汤  Click: 8777   Comments: 0 Category: 数据库  Tag: mysql,master,slave

-------------------quote begin------------------------
3. If you decide that you can skip the next statement from the master, issue the following
statements:
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n;
mysql> START SLAVE;
The value of n should be 1 if the next statement from the master does not use
AUTO_INCREMENT or LAST_INSERT_ID(). Otherwise, the value should be 2. The
reason for using a value of 2 for statements that use AUTO_INCREMENT or
LAST_INSERT_ID() is that they take two events in the binary log of the master.

-------------------quote end------------------------

MySQL文档中的意思是当master传到slave的语句中要用到auto_increment,或者last_insert_id()时,需要skip两个event. 但实际情况并非如此

测试过程如下:
172.16.161.26 为master
172.16.161.15 为slave
同步c2cdb,初始状态ok

1. 在master上创建测试表

[code="sql"]
mysql> create table tmp_test_0208(id int not null auto_increment,name varchar(30),primary key(id)) engine=innodb;
Query OK, 0 rows affected (0.20 sec)
[/code]
2, 在salve上insert 3条记录

[code="sql"]
mysql> insert into tmp_test_0208 values(1,'a'),(2,'b'),(3,'c');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)
[/code]
3, 在master上insert 3条记录
[code="sql"]
mysql> insert into tmp_test_0208(name) values('a'),('b'),('c');
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)
[/code]
4,  slave 的sql thread 中止

[code="bash"]
/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: No
[/code]
5,  skip next statemate后start slave正常
[code="sql"]
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 ;
Query OK, 0 rows affected (0.00 sec)

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[/code]
slave端errlog如下:
070208 16:07:59[ERROR] Slave: Error 'Duplicate entry '1' for key 1' on query. Default database: 'c2cdb'. Query: 'insert into tmp_te
st_0208(name) values('a'),('b'),('c')', Error_code: 1062

070208 16:07:59 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE
 START". We stopped at log 'db_auction1-bin.000203' position 14215101

070208 16:09:59 [Note] Slave SQL thread initialized, starting replication in log 'db_auction1-bin.000203' at position 14215101, rela
y log './db_auction1_b-relay-bin.000457' position: 200682931

 

master羰binlog中相应的记录如下:

# at 14215101
#070208 16:08:00 server id 1  log_pos 14215101  Intvar
SET INSERT_ID=1;
# at 14215129
#070208 16:08:00 server id 1  log_pos 14215129  Query   thread_id=2744782       exec_time=0     error_code=0
SET TIMESTAMP=1170922080;
insert into tmp_test_0208(name) values('a'),('b'),('c');

总结:使用SET GLOBAL SQL_SLAVE_SKIP_COUNTER 命令跳过失败的SQL

分类

标签

归档

最新评论

Abyss在00:04:28评论了
Linux中ramdisk,tmpfs,ramfs的介绍与性能测试
shallwe99在10:21:17评论了
【原创】如何在微信小程序开发中正确的使用vant ui组件
默一在09:04:53评论了
Berkeley DB 由浅入深【转自架构师杨建】
Memory在14:09:22评论了
【原创】最佳PHP框架选择(phalcon,yaf,laravel,thinkphp,yii)
leo在17:57:04评论了
shell中使用while循环ssh的注意事项

我看过的书

链接

其他

访问本站种子 本站平均热度:9360 c° 本站链接数:1 个 本站标签数:464 个 本站被评论次数:94 次