| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
29 | 30 | 31 | 1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
26 | 27 | 28 | 29 | 30 | 1 | 2 | |||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
private volatile long mask = 0xF; @Override public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { if (!isStarted()) { return FilterReply.NEUTRAL; } // for performance reasons, skip change detection (MASK-1) times out of MASK. // Only once every MASK calls is change detection code executed // Note that MASK is a variable itself. if (((invocationCounter++) & mask) != mask) { return FilterReply.NEUTRAL; } long now = System.currentTimeMillis(); synchronized (configurationWatchList) { updateMaskIfNecessary(now); if (changeDetected(now)) { // Even though reconfiguration involves resetting the loggerContext, // which clears the list of turbo filters including this instance, it is // still possible for this instance to be subsequently invoked by another // thread if it was already executing when the context was reset. disableSubsequentReconfiguration(); detachReconfigurationToNewThread(); } } return FilterReply.NEUTRAL; }
這行 if (((invocationCounter++) & mask) != mask) {
mask = 0xf,其實(shí)要每循環(huán) 0xf 次,也就是 15 次,才會(huì)去 check 一次是否要更新,也就是說(shuō),不管過(guò)了多久,如果沒(méi)到這 15 次,也不會(huì)去檢查是否更新配置。
也就是說(shuō),我多打幾次 log,配置文件就生效了。
spring security(下簡(jiǎn)寫(xiě)為 ss)控制的安全主要有兩方面,Web 和 Method Call,這兩個(gè)方面的權(quán)限控制有比較多的相通的設(shè)計(jì),也有一些特別的功能。比如 Method Call 可以做 After Invocation 控制,而 Web 可以做 Ip 地址控制。
這里面有兩個(gè)最基本的概念:authentication manager 和 access decision manager,前者控制認(rèn)證,后都控制鑒權(quán)。
1. 在 ss 的認(rèn)證系統(tǒng)中,默認(rèn)的實(shí)現(xiàn)幫助我們提供了三個(gè)概念,用戶(user),角色(authority,一般存 role)和組(group),三者的關(guān)系是,組、角色與用戶都是多對(duì)多關(guān)系,組和角色間沒(méi)關(guān)系,默認(rèn)是不啟用組的。后續(xù),在 Acl 權(quán)限管理中,可以看到角色之間,是可以有包含(樹(shù)形?)關(guān)系的。
2. 在 ss 的鑒權(quán)系統(tǒng)中,明顯會(huì)比認(rèn)證復(fù)雜得多。有 AccessDecisionManager, AccessDecisionVoter(前置), AfterInvocationProvider(后置), RoleHierarchy, SidRetrievalStrategy, LookupStrategy, PermissionGrantingStrategy, SecurityExpressionHandler, AclService, MutableAclService, AclCache 概念過(guò)多了,要一個(gè)一個(gè)解釋
a) 中心是 AccessDecisionManager,主要負(fù)責(zé) AccessDecisionVoter 的管理,默認(rèn)提供了3種實(shí)現(xiàn):1. AffirmativeBased 如果有任何一個(gè)投票器允許訪問(wèn),請(qǐng)求將被立刻允許,而不管之前可能有的拒絕決定。2. ConsensusBased 多數(shù)票(允許或拒絕)決定了結(jié)果,平局的投票 和空票(全是棄權(quán)的)的結(jié)果是可配置的。3. UnanimousBased 所有的投票器必須全是允許的,否則訪問(wèn)將 被拒絕。
AccessDecisionManager 在用于 Web 和 Method Call 兩種情況下,可能是不一致的,因?yàn)楣δ芤膊灰恢隆?br />
b) Method Call 除了使用 AccessDecisionManager 進(jìn)行權(quán)限判斷外,還可以增加 AfterInvocationProvider 來(lái)進(jìn)行出口數(shù)據(jù)的判斷,默認(rèn)提供了 3 種。
1) PostInvocationAdviceProvider: 需要提供一個(gè) PostInvocationAuthorizationAdvice,默認(rèn)實(shí)現(xiàn)只有一個(gè),就是 ExpressionBasedPostInvocationAdvice,可以通過(guò) spel 來(lái)進(jìn)行權(quán)限判斷。注意 ExpressionBasedPostInvocationAdvice 中需要提供一個(gè) MethodSecurityExpressionHandler,能夠創(chuàng)建出一個(gè) MethodSecurityExpressionOperations,放到 spel context 中,供 spel function 調(diào)用,這樣的方式,在后續(xù)很常見(jiàn)。
2) AclEntryAfterInvocationProvider 和 AclEntryAfterInvocationCollectionFilteringProvider : 這兩種都差不多,主要依賴 AclService, ObjectIdentityRetrievalStrategy, SidRetrievalStrategy 來(lái)配合,檢查返回值的權(quán)限。Collection 版本的,可以把無(wú)權(quán)限的數(shù)據(jù)去掉,只留下有權(quán)限的數(shù)據(jù)。
c) RoleHierarchy 提供了角色之間的關(guān)系,提供了兩個(gè)實(shí)現(xiàn),一個(gè)是沒(méi)關(guān)系的,直接把 user 的 role 返回,另外一個(gè)是有繼承關(guān)系的。繼承關(guān)系實(shí)現(xiàn)挺有意思的,能夠處理多級(jí)的 include 關(guān)系,比較好用。
RoleHierarchy 的使用比較復(fù)雜,會(huì)被 AccessDecisionVoter, SidRetrievalStrategy, SecurityExpressionHandler 用到,SecurityExpressionHandler 又會(huì)被 AccessDecisionVoter 用到,所以還是有點(diǎn)兒混亂。
具體的說(shuō) SecurityExpressionHandler 會(huì)用到 PermissionEvaluator 和 RoleHierarchy,PermissionEvaluator 的一個(gè)實(shí)現(xiàn) AclPermissionEvaluator 會(huì)用到 SidRetrievalStrategy。
d) SidRetrievalStrategy 和 RoleHierarchy 的功能比較接近,比 RoleHierarchy 高一個(gè)抽象層次,功能上也有所區(qū)別,是從一個(gè) authentication 拿到所有相關(guān)的 Sid(包括 Role(GrantedAuthoritySid) 和 User(PrincipalSid)),而 RoleHierarchy 只包括了 Role(GrantedAuthoritySid)的繼承關(guān)系。
e) LookupStrategy 通過(guò) ObjectIdentity 和 Sid 把相關(guān)的 Acl 查詢出來(lái)。可以在 LookupStrategy 擴(kuò)展 Acl 和 Ace 的功能,比如在 Ace 上面加上時(shí)間的條件限制,就需要自己定義 LookupStrategy,把時(shí)間條件從數(shù)據(jù)庫(kù)查詢出來(lái),并放到自定義的 Ace 當(dāng)中。
但這件事情非常麻煩,因?yàn)槟J(rèn)實(shí)現(xiàn)的 BasicLookupStrategy 是個(gè) Final 的類,所以只能自己直接實(shí)現(xiàn)接口,無(wú)法使用現(xiàn)有的功能。
LookupStrategy 會(huì)生成 Acl,而最終的權(quán)限驗(yàn)證是由 Acl 完成的,如果想驗(yàn)證帶時(shí)間條件的 Ace,需要給 Acl 設(shè)置自定義的帶有檢查時(shí)間功能的 PermissionGrantingStrategy,實(shí)際上,這個(gè) PermissionGrantingStrategy 會(huì)首先設(shè)置給 LookupStrategy,LookupStrategy 在創(chuàng)建 Acl 的時(shí)候,再放到 Acl 中去。
f) SecurityExpressionHandler 能夠執(zhí)行 spel,得到是否可以訪問(wèn)的結(jié)果,它的子類都是繼承自 AbstractSecurityExpressionHandler 的,有一個(gè)非常重要的方法是 SecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, T invocation),創(chuàng)建一個(gè) SecurityExpressionOperations 放到 EvaluationContext 中去,提供 spel 中執(zhí)行的方法實(shí)現(xiàn)。比如 SecurityExpressionOperations 的一個(gè)抽象實(shí)現(xiàn) SecurityExpressionRoot 中,就包含了大量的權(quán)限驗(yàn)證方法,如 hasRole, hasPermission 等常用的功能。
g) AclService, MutableAclService, AclCache 概念比較簡(jiǎn)單,AclService 是通過(guò) LookupStrategy 查詢 Acl,自已可以查詢 ObjectIdentity 的父子關(guān)聯(lián)關(guān)系,MutableAclService 提供了修改的能力,AclCache 為 AclService 提供緩存,默認(rèn)的實(shí)現(xiàn)了一個(gè) EhCacheBasedAclCache。
3. ss 的鑒權(quán)模型 Sid, ObjectIdentity, Acl, Ace, Permission
a) Sid: 是中心,所有的授權(quán)會(huì)關(guān)聯(lián)在 Sid 上面,Sid 和之前的 Role Base Permission 會(huì)有些相同的地方,但也明顯不同,Sid 默認(rèn)實(shí)現(xiàn)情況下,分為 GrantedAuthoritySid 和 PrincipalSid,其實(shí)就是 Role 和 User,通過(guò) SidRetrievalStrategy 拿到一個(gè) Authentication 的 Sid。
b) ObjectIdentity: 可以理解成 Resource,就是可訪問(wèn)的目標(biāo)資源,有 id 和 type 兩個(gè)字段,默認(rèn)實(shí)現(xiàn)的 ObjectIdentityImpl 會(huì)直接調(diào)用目標(biāo) domainObject 的 getClass 和 getId 方法拿到兩個(gè)參數(shù)。在 PermissionEvaluator, AfterInvocationProvider 中,會(huì)用到 ObjectIdentityRetrievalStrategy 和 ObjectIdentityGenerator,ObjectIdentityRetrievalStrategy 會(huì)根據(jù) domainObject 拿到 ObjectIdentity,然后使用 Acl 進(jìn)行鑒權(quán),ObjectIdentityGenerator 會(huì)在系統(tǒng)提供的不是 domainObject,而是 type, id 的時(shí)候,拿到 ObjectIdentity,然后進(jìn)行 Acl 鑒權(quán),這兩個(gè)接口有一個(gè)共同的實(shí)現(xiàn) ObjectIdentityRetrievalStrategyImpl,如果需要在 ObjectIdentity 進(jìn)行新的抽象,需要用新的實(shí)現(xiàn),到得不同的 ObjectIdentity,比如將業(yè)務(wù)對(duì)象分類鑒權(quán)這樣的需求。
c) Acl, 每個(gè) ObjectIdentity 最多對(duì)應(yīng)一條 Acl,Acl 中包含了很多,包括 parental,說(shuō)明 Acl 是有繼承關(guān)系的?其實(shí)不是,呵呵,是 ObjectIdentity 有繼承關(guān)系而已。有一個(gè) ObjectIdentity,有很多 Sid,還有一個(gè)叫做 Owner 的 Sid,有從 LookupStrategy 傳過(guò)來(lái)的 PermissionGrantingStrategy,進(jìn)行實(shí)際的鑒權(quán),還有 AclAuthorizationStrategy 檢查有沒(méi)有權(quán)限進(jìn)行 Acl security check。實(shí)現(xiàn)時(shí)間條件檢查,就擴(kuò)展 PermissionGrantingStrategy。
為什么沒(méi)有 RoleHierarchy 或是 SidRetrievalStrategy 存在呢?是因?yàn)檎{(diào)用 Acl 進(jìn)行權(quán)限檢查之前,已經(jīng)把相關(guān)的 Sid 得到了,再給 Acl 的。
d) Ace, Permission: Ace 存儲(chǔ) Sid, Permission,提供給 Acl 鑒權(quán)用。增加時(shí)間條件的話,最基本的,就是要在 Ace 中,增加時(shí)間條件字段。Permission 是用二進(jìn)制存儲(chǔ)的,但默認(rèn)實(shí)現(xiàn)的數(shù)據(jù)庫(kù)存儲(chǔ)并不是,是一個(gè)一條,存在數(shù)據(jù)庫(kù)里面的。
好吧,概念還是非常多的,不過(guò)鑒于權(quán)限控制本身就是個(gè)復(fù)雜的話題,ss 這些設(shè)計(jì)的我覺(jué)得已經(jīng)非常好,也基本夠用了。
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); Security.setProperty("ssl.SocketFactory.provider", "com.datayes.cloud.util.TrustAllSSLSocketFactory");主要完成了下面4個(gè)工作
1. 創(chuàng)建一個(gè)本地的目錄結(jié)構(gòu),以存放 rpm 包
2. 啟動(dòng)一個(gè) apache,使這些文件能夠遠(yuǎn)程訪問(wèn)
3. 寫(xiě)一個(gè) spec,并且用 rpmbuild 做成一個(gè)安裝包,用來(lái)在機(jī)器上安裝新的 repository 位置
4. 使用 yum downloadonly plugin 將需要的 rpm 包放到本地目錄下,然后使用 createrepo 命令創(chuàng)建 metadata
本來(lái)是希望能有一個(gè)類似于 nexus 這樣的 proxy host server 將遠(yuǎn)程的 package cache 下來(lái),找來(lái)找去,也找到了一個(gè) nexus yum plugin,但這個(gè) plugin 只支持手工的 deploy rpm package 到 nexus 上面,不能做 proxy 方式的。
寫(xiě)寫(xiě)步驟和遇到的問(wèn)題吧。
[haha] name=haha baseurl=http://192.168.157.131/yum/centos/$releasever/$basearch/ enabled=1 gpgcheck=0
Summary: haha Name: haha Version: 0.1 Release: 1 Source0: haha Group: Applications/Internet License: GPLv2+ URL: http://192.168.157.131/yum/ #BuildRoot: %{_tmppath}/%{name}-%{version}-root BuildArch: noarch
%description The haha yum repo #%prep #%setup -q %install mkdir -p $RPM_BUILD_ROOT/etc/yum.repos.d install -m 0644 -p %{SOURCE0} $RPM_BUILD_ROOT/etc/yum.repos.d
%clean rm -rf ${RPM_BUILD_ROOT} %files /etc/yum.repos.d/haha.repo
參考了
1. 自建yum源與制作RPM安裝包yum源
2. yum只下載rpm包不自動(dòng)安裝方法
3. Installing Chef Server 0.10 in RHEL 6
ResultSet
By default, ResultSets are completely retrieved and stored in memory. In most cases this is the most efficient way to operate, and due to the design of the MySQL network protocol is easier to implement. If you are working with ResultSets that have a large number of rows or large values, and cannot allocate heap space in your JVM for the memory required, you can tell the driver to stream the results back one row at a time.
To enable this functionality, create a Statement
instance in the following manner:
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE);
The combination of a forward-only, read-only result set, with a fetch size of Integer.MIN_VALUE
serves as a signal to the driver to stream result sets row-by-row. After this, any result sets created with the statement will be retrieved row-by-row.
There are some caveats with this approach. You must read all of the rows in the result set (or close it) before you can issue any other queries on the connection, or an exception will be thrown.
The earliest the locks these statements hold can be released (whether they be MyISAM
table-level locks or row-level locks in some other storage engine such as InnoDB
) is when the statement completes.
If the statement is within scope of a transaction, then locks are released when the transaction completes (which implies that the statement needs to complete first). As with most other databases, statements are not complete until all the results pending on the statement are read or the active result set for the statement is closed.
Therefore, if using streaming results, process them as quickly as possible if you want to maintain concurrent access to the tables referenced by the statement producing the result set.
在 Eclipse 中執(zhí)行下面代碼。
byte[] bytes = new byte[]{-16, -97, -116, -70};
String s = new String(bytes, "UTF-8");
System.out.println(s);
結(jié)果打印出了一朵花,呵呵,實(shí)在是太有意思了。
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); Picasa 像冊(cè)真的很給力,2048 像素以下(包含)的照片不計(jì)算空間,據(jù)說(shuō) 15 分鐘以內(nèi)的也不算空間,除了這些,有1G的空間可以使用。SELinux全稱是Security Enhanced Linux,由美國(guó)國(guó)家安全部(National Security Agency)領(lǐng)導(dǎo)開(kāi)發(fā)的GPL項(xiàng)目,它擁有一個(gè)靈活而強(qiáng)制性的訪問(wèn)控制結(jié)構(gòu),旨在提高Linux系統(tǒng)的安全性,提供強(qiáng)健的安全保證,可防御未知攻擊,據(jù)稱相當(dāng)于B1級(jí)的軍事安全性能。比MS NT所謂的C2等高得多。
應(yīng)用SELinux后,可以減輕惡意攻擊或惡意軟件帶來(lái)的災(zāi)難,并提供對(duì)機(jī)密性和完整性有很高要求的信息很高的安全保障。 SELinux vs Linux 普通Linux安全和傳統(tǒng)Unix系統(tǒng)一樣,基于自主存取控制方法,即DAC,只要符合規(guī)定的權(quán)限,如規(guī)定的所有者和文件屬性等,就可存取資源。在傳統(tǒng)的安全機(jī)制下,一些通過(guò)setuid/setgid的程序就產(chǎn)生了嚴(yán)重安全隱患,甚至一些錯(cuò)誤的配置就可引發(fā)巨大的漏洞,被輕易攻擊。
而SELinux則基于強(qiáng)制存取控制方法,即MAC,透過(guò)強(qiáng)制性的安全策略,應(yīng)用程序或用戶必須同時(shí)符合DAC及對(duì)應(yīng)SELinux的MAC才能進(jìn)行正常操作,否則都將遭到拒絕或失敗,而這些問(wèn)題將不會(huì)影響其他正常運(yùn)作的程序和應(yīng)用,并保持它們的安全系統(tǒng)結(jié)構(gòu)。
SELinux的配置相關(guān)文件都在/etc/selinux下,其中/etc/selinux/targeted目錄里就包含了策略的詳細(xì)配置和context定義,以下是主要文件及功用:
/etc/selinux/targeted/contexts/*_context 默認(rèn)的context設(shè)置
/etc/selinux/targeted/contexts/files/* 精確的context類型劃分
/etc/selinux/targeted/policy/* 策略文件
Apache under SELinux - 讓Apache跑得順起來(lái)!
對(duì)于剛使用Redhat Enterprise Linux 4 或Fedora Core 2以上/CentOS 4的用戶,一定會(huì)為Apache經(jīng)常無(wú)法正常運(yùn)轉(zhuǎn),報(bào)以"Permission denied"等錯(cuò)誤而大為不解,甚至大為惱火。
其實(shí)這是因?yàn)檫@些系統(tǒng)里激活了SELinux,而用戶的apache配置與SELinux的配置策略有抵觸產(chǎn)生的,只有通過(guò)適當(dāng)調(diào)整,使apache的配置和訪問(wèn)符合策略才能正常使用。
現(xiàn)在下面來(lái)分析一下SELinux中有關(guān)httpd(apache)的context定義(略有刪節(jié))
/home/[^/]+/((www)|(web)|(public_html))(/.+)? system_u:object_r:httpd_user_content_t
/var/www(/.*)? system_u:object_r:httpd_sys_content_t
/var/www/cgi-bin(/.*)? system_u:object_r:httpd_sys_script_exec_t
/usr/lib/cgi-bin(/.*)? system_u:object_r:httpd_sys_script_exec_t
/var/www/perl(/.*)? system_u:object_r:httpd_sys_script_exec_t
/var/www/icons(/.*)? system_u:object_r:httpd_sys_content_t
/var/cache/httpd(/.*)? system_u:object_r:httpd_cache_t
/etc/vhosts -- system_u:object_r:httpd_config_t
/usr/sbin/httpd -- system_u:object_r:httpd_exec_t
/usr/sbin/apache(2)? -- system_u:object_r:httpd_exec_t
/usr/sbin/suexec -- system_u:object_r:httpd_suexec_exec_t
/var/log/httpd(/.*)? system_u:object_r:httpd_log_t
/var/log/apache(2)?(/.*)? system_u:object_r:httpd_log_t
/var/log/cgiwrap\.log.* -- system_u:object_r:httpd_log_t
/var/cache/ssl.*\.sem -- system_u:object_r:httpd_cache_t
/var/cache/mod_ssl(/.*)? system_u:object_r:httpd_cache_t
/var/run/apache(2)?\.pid.* -- system_u:object_r:httpd_var_run_t
/var/lib/httpd(/.*)? system_u:object_r:httpd_var_lib_t
/var/lib/php/session(/.*)? system_u:object_r:httpd_var_run_t
/etc/apache-ssl(2)?(/.*)? system_u:object_r:httpd_config_t
/usr/lib/apache-ssl(/.*)? -- system_u:object_r:httpd_exec_t
/usr/sbin/apache-ssl(2)? -- system_u:object_r:httpd_exec_t
/var/log/apache-ssl(2)?(/.*)? system_u:object_r:httpd_log_t
/var/run/apache-ssl(2)?\.pid.* -- system_u:object_r:httpd_var_run_t
/var/run/gcache_port -s system_u:object_r:httpd_var_run_t
/var/lib/squirrelmail/prefs(/.*)? system_u:object_r:httpd_squirrelmail_t
/usr/bin/htsslpass -- system_u:object_r:httpd_helper_exec_t
/usr/share/htdig(/.*)? system_u:object_r:httpd_sys_content_t
/var/lib/htdig(/.*)? system_u:object_r:httpd_sys_content_t
針對(duì)上述的內(nèi)容,可以對(duì)如下的幾個(gè)常見(jiàn)問(wèn)題進(jìn)行簡(jiǎn)單處理:
1.phpmyadmin在非默認(rèn)/var/www/html目錄下無(wú)法運(yùn)轉(zhuǎn)
通常類似的情況都是在配置了虛擬主機(jī)時(shí),訪問(wèn)/phpmyadmin等提示403訪問(wèn)拒絕,日志里也提示Permission denied,這是因?yàn)閜hpmyadmin防止的目錄及文件本身屬性不符合context要求。
假設(shè)phpmyadmin放在/web目錄下,那么執(zhí)行:
chcon -R -t httpd_user_content_t /web
則會(huì)令/web及其下所有子目錄/文件,包括phpmyadmin文件都獲得了httpd_user_content_t的屬性,如果其傳統(tǒng)的Unix屬性對(duì)httpd來(lái)說(shuō)是可讀的話,再重新訪問(wèn)一下就應(yīng)該可以了。
2./home目錄下的虛擬主機(jī)無(wú)法運(yùn)轉(zhuǎn)
與問(wèn)題1也是類似的,不過(guò)根據(jù)上文中context的定義,/home目錄下必須是用戶的$HOME/www或public_html或web目錄才是 httpd_user_content_t類型,因此建議將要作為web頁(yè)面的內(nèi)容放置在用戶的$HOME/www或web或public_html里,并確保其屬性是httpd_user_content_t,使用如下命令查看:
ls -Z /home/abc/
drwxr-xr-x abc abc user_u:object_r:user_home_dir_t tmp
drwxrwxr-x abc abc user_u:object_r:httpd_user_content www
如不是,則可通過(guò)chcon來(lái)逐級(jí)目錄及文件更改,直至最后能訪問(wèn):
chcon -R -t httpd_user_content_t /home/abc/web
chcon -t user_home_dir_t /home/abc
3.CGI程序無(wú)法運(yùn)行
如果cgi程序放在/var/www/cgi-bin/里也無(wú)法執(zhí)行,遇到403或500錯(cuò)誤的話,可以檢查cgi程序的屬性,按SELinux contexts文件里定義的,/var/www/cgi-bin/里必須是httpd_sys_script_exec_t 屬性。通過(guò)ls -Z查看,如果不是則通過(guò)如下命令更改:
chcon -t httpd_sys_script_exec_t /var/www/cgi-bin/*.cgi
如果是虛擬主機(jī)里的cgi,則參考問(wèn)題2使之能正常使用普通的功能后,再通過(guò)chcon設(shè)置cgi文件的context為httpd_sys_script_exec_t即可。
4.Setuid/gid 程序無(wú)法運(yùn)行
例如早期的SqWebMail及qmailadmin等,需要setuid/gid的支持,但在SELinux下這將受到嚴(yán)格限制。第一種方法是比較徹底的辦法,能保留系統(tǒng)的安全性,通過(guò):
audit2allow -l -i /var/log/messages
將SELinux拒絕的信息轉(zhuǎn)換為相應(yīng)的policy allow指令,將這些指令添加到SELinux policy 的src里相應(yīng)的配置文件,重新生成policy并加載。但這樣做相對(duì)比較麻煩。
另一個(gè)方法最簡(jiǎn)單,但將使apache得不到保護(hù)。首先確定SELinux 類型是targeted的:
cat /etc/selinux/config|grep SELINUXTYPE
然后,使apache脫離SELinux保護(hù):
setsebool -P httpd_disable_trans 1
然后重啟動(dòng)apache:
/etc/init.d/httpd restart
這樣所有apache強(qiáng)制的檢查都失效,需要setuid/gid的程序可以正常使用。但這樣帶來(lái)了增加漏洞的危險(xiǎn),對(duì)于迫切需要運(yùn)行而又很急的情況,本方法是一個(gè)最大限度減少系統(tǒng)安全缺失的最后辦法。對(duì)于取消SELinux 未必是一個(gè)好方法。
一.
ps -Z
ls -Z
id -Z
例:
[root@ljj cgi-bin]# ls -Z
-rwxrwxrwx root root root:object_r:httpd_sys_script_exec_t a.cgi
-rw-r--r-- root root root:object_r:httpd_sys_script_exec_t a.txt
二. chcon
修改文件的屬性 fild1:fild2:fild3
chcon -u fild1 file
chcon -l fild2 file
chcon -t fild3 file
例:
chcon -u root file1
三.getsebool
獲取se相關(guān)的bool值
例:
[root@ljj cgi-bin]# getsebool -a | grep httpd
httpd_builtin_scripting --> inactive
httpd_disable_trans --> active
httpd_enable_cgi --> active
httpd_enable_homedirs --> active
httpd_ssi_exec --> active
httpd_tty_comm --> inactive
httpd_unified --> inactive
得到了一些與httpd相關(guān)的bool值,配置httpd.conf中的user_dir時(shí),要保證這里的httpd_enable_homedirs是 active的,還要保證:
chcon -R -t httpd_sys_content_t ~user/public_html;
四. togglesebool
給se的相關(guān)bool值取反
例:
togglesebool httpd_enable_homedirs
本次操作環(huán)境:
Ubuntu Server 10.10
SCSI Harddisk:/dev/sda 500GB
U盤(pán):/dev/sdb 8GB(模擬成USB Harddisk,安裝OS)
介紹2種分區(qū)表:
MBR分區(qū)表:(MBR含義:主引導(dǎo)記錄)
所支持的最大卷:2T (T; terabytes,1TB=1024GB)
對(duì)分區(qū)的設(shè)限:最多4個(gè)主分區(qū)或3個(gè)主分區(qū)加一個(gè)擴(kuò)展分區(qū)。
GPT分區(qū)表:(GPT含義:GUID分區(qū)表)
支持最大卷:18EB,(E:exabytes,1EB=1024TB)
每個(gè)磁盤(pán)最多支持128個(gè)分區(qū)
所以如果要大于2TB的卷或分區(qū)就必須得用GPT分區(qū)表。
Linux下fdisk工具不支持GPT,得使用另一個(gè)GNU發(fā)布的強(qiáng)大分區(qū)工具parted。
fdisk工具用的話,會(huì)有下面的警告信息:
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.
下面是用parted工具對(duì)/dev/sda做GPT分區(qū)的過(guò)程:
root@node01:/mnt# parted /dev/sda
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk
will be lost. Do you want to continue?
Yes/No? yes
(parted) print
Model: DELL PERC 6/i Adapter (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
(parted)mkpart primary 0KB 500GB
Warning: You requested a partition from 0.00B to 500GB.
The closest location we can manage is 17.4kB to 500GB.
Is this still acceptable to you?
Yes/No? yes
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) print
Model: DELL PERC 6/i Adapter (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 500GB 500GB primary
(parted)quit
Information: You may need to update /etc/fstab.
root@node01:/#fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sda: 499.6 GB, 499558383616 bytes
255 heads, 63 sectors/track, 60734 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 1 60735 487849983+ ee GPT
root@node01:/#mkfs.ext4 /dev/sda1
mke2fs 1.41.12 (17-May-2010)
文件系統(tǒng)標(biāo)簽=
操作系統(tǒng):Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
30490624 inodes, 121962487 blocks
6098124 blocks (5.00%) reserved for the super user
第一個(gè)數(shù)據(jù)塊=0
Maximum filesystem blocks=4294967296
3722 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
正在寫(xiě)入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@node01:/#mount /dev/sda1 /export/glusterfs01/
root@node01:/# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/node01-root
6.8G 987M 5.5G 16% /
none 7.9G 208K 7.9G 1% /dev
none 7.9G 0 7.9G 0% /dev/shm
none 7.9G 32K 7.9G 1% /var/run
none 7.9G 0 7.9G 0% /var/lock
/dev/sdb1 228M 21M 196M 10% /boot
/dev/sda1 458G 198M 435G 1% /export/glusterfs01
root@node01:/#vi /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
/dev/mapper/node01-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdb1 during installation
UUID=c21707ff-ba0f-43ee-819a-8e72fa0f8500 /boot ext2 defaults 0 2
/dev/mapper/node01-swap_1 none swap sw 0 0
/dev/sda1 /export/glusterfs01 ext4 defaults 0 2
重啟就可以自動(dòng)掛載了!至此完成。
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 1. cross join 就是笛卡爾積
private void queryGroupSorted(int columnCount, ResultTarget result) {
int rowNumber = 0;
setCurrentRowNumber(0);
Value[] previousKeyValues = null;
while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
rowNumber++;
Value[] keyValues = new Value[groupIndex.length];
// update group
for (int i = 0; i < groupIndex.length; i++) {
int idx = groupIndex[i];
Expression expr = expressions.get(idx);
keyValues[i] = expr.getValue(session);
}
if (previousKeyValues == null) {
previousKeyValues = keyValues;
currentGroup = New.hashMap();
} else if (!Arrays.equals(previousKeyValues, keyValues)) {
addGroupSortedRow(previousKeyValues, columnCount, result);
previousKeyValues = keyValues;
currentGroup = New.hashMap();
}
currentGroupRowId++;
for (int i = 0; i < columnCount; i++) {
if (groupByExpression == null || !groupByExpression[i]) {
Expression expr = expressions.get(i);
expr.updateAggregate(session);
}
}
}
}
if (previousKeyValues != null) {
addGroupSortedRow(previousKeyValues, columnCount, result);
}
}
http://en.wikipedia.org/wiki/Category:Unix_signals 1.SIGHUP信號(hào) UNIX中進(jìn)程組織結(jié)構(gòu)為 session (會(huì)話)包含一個(gè)前臺(tái)進(jìn)程組及一個(gè)或多個(gè)后臺(tái)進(jìn)程組,一個(gè)進(jìn)程組包含多個(gè)進(jìn)程。一個(gè)session可能會(huì)有一個(gè)session首進(jìn)程,而一個(gè)session首進(jìn)程可能會(huì)有一個(gè)控制終端。一個(gè)進(jìn)程組可能會(huì)有一個(gè)進(jìn)程組首進(jìn)程。進(jìn)程組首進(jìn)程的進(jìn)程ID與該進(jìn)程組ID相等。這兒是可能會(huì)有,在一定情況之下是沒(méi)有的。與終端交互的進(jìn)程是前臺(tái)進(jìn)程,否則便是后臺(tái)進(jìn)程。
SIGHUP會(huì)在以下3種情況下被發(fā)送給相應(yīng)的進(jìn)程:
1、終端關(guān)閉時(shí),該信號(hào)被發(fā)送到session首進(jìn)程以及作為job提交的進(jìn)程(即用 & 符號(hào)提交的進(jìn)程)
2、session首進(jìn)程退出時(shí),該信號(hào)被發(fā)送到該session中的前臺(tái)進(jìn)程組中的每一個(gè)進(jìn)程
3、若父進(jìn)程退出導(dǎo)致進(jìn)程組成為孤兒進(jìn)程組,且該進(jìn)程組中有進(jìn)程處于停止?fàn)顟B(tài)(收到SIGSTOP或SIGTSTP信號(hào)),該信號(hào)會(huì)被發(fā)送到該進(jìn)程組中的每一個(gè)進(jìn)程。
系統(tǒng)對(duì)SIGHUP信號(hào)的默認(rèn)處理是終止收到該信號(hào)的進(jìn)程。所以若程序中沒(méi)有捕捉該信號(hào),當(dāng)收到該信號(hào)時(shí),進(jìn)程就會(huì)退出。
下面觀察幾種因終端關(guān)閉導(dǎo)致進(jìn)程退出的情況,在這兒進(jìn)程退出是因?yàn)槭盏搅薙IGHUP信號(hào)。login shell是session首進(jìn)程。
首先寫(xiě)一個(gè)測(cè)試程序,代碼如下:
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 程序中捕捉SIGHUP信號(hào)后打印一條信息,pause()使程序暫停。
編譯后的執(zhí)行文件為sigtest。
1、命 令:sigtest front > tt.txt
操 作:關(guān)閉終端
結(jié) 果:tt.txt文件的內(nèi)容為front : sighup received
原 因: sigtest是前臺(tái)進(jìn)程,終端關(guān)閉后,根據(jù)上面提到的第1種情況,login shell作為session首進(jìn)程,會(huì)收到SIGHUP信號(hào)然后退出。根據(jù)第2種情況,sigtest作為前臺(tái)進(jìn)程,會(huì)收到login shell發(fā)出的SIGHUP信號(hào)。
2、命 令:sigtest back > tt.txt &
操 作:關(guān)閉終端
結(jié) 果:tt.txt文件的內(nèi)容為 back : sighup received
原 因: sigtest是提交的job,根據(jù)上面提到的第1種情況,sigtest會(huì)收到SIGHUP信號(hào)。
3、命 令:寫(xiě)一個(gè)shell,內(nèi)容為[sigtest &],然后執(zhí)行該shell
操 作:關(guān)閉終端
結(jié) 果:ps -ef | grep sigtest 會(huì)看到該進(jìn)程還在,tt文件為空
原 因: 執(zhí)行該shell時(shí),sigtest作為job提交,然后該shell退出,致使sigtest變成了孤兒進(jìn)程,不再是當(dāng)前session的job了,因此sigtest即不是session首進(jìn)程也不是job,不會(huì)收到SIGHUP。同時(shí)孤兒進(jìn)程屬于后臺(tái)進(jìn)程,因此login shell退出后不會(huì)發(fā)送SIGHUP給sigtest,因?yàn)樗粚⒃撔盘?hào)發(fā)送給前臺(tái)進(jìn)程。第3條說(shuō)過(guò)若進(jìn)程組變成孤兒進(jìn)程組的時(shí)候,若有進(jìn)程處于停止?fàn)顟B(tài),也會(huì)收到SIGHUP信號(hào),但sigtest沒(méi)有處于停止?fàn)顟B(tài),所以不會(huì)收到SIGHUP信號(hào)。
4、命 令:nohup sigtest > tt
操 作:關(guān)閉終端
結(jié) 果:tt文件為空
原 因: nohup可以防止進(jìn)程收到SIGHUP信號(hào)
至此,我們就清楚了何種情況下終端關(guān)閉后進(jìn)程會(huì)退出,何種情況下不會(huì)退出。
要想終端關(guān)閉后進(jìn)程不退出有以下幾種方法,均為通過(guò)shell的方式:
1、編寫(xiě)shell,內(nèi)容如下
trap "" SIGHUP #該句的作用是屏蔽SIGHUP信號(hào),trap可以屏蔽很多信號(hào)
sigtest
2、nohup sigtest 可以直接在命令行執(zhí)行,
若想做完該操作后繼續(xù)別的操作,可以 nohup sigtest &
3、編寫(xiě)shell,內(nèi)容如下
sigtest &
其實(shí)任何將進(jìn)程變?yōu)楣聝哼M(jìn)程的方式都可以,包括fork后父進(jìn)程馬上退出。
2.SIGCHLD信號(hào) 子進(jìn)程死后,會(huì)發(fā)送SIGCHLD信號(hào)給父進(jìn)程。 一個(gè)進(jìn)程在調(diào)用exit命令結(jié)束自己的生命的時(shí)候,其實(shí)它并沒(méi)有真正的被銷毀,而是留下一個(gè)稱為僵尸進(jìn)程(Zombie)的數(shù)據(jù)結(jié)構(gòu)(系統(tǒng)調(diào)用exit,它的作用是使進(jìn)程退出,但也僅僅限于將一個(gè)正常的進(jìn)程變成一個(gè)僵尸進(jìn)程,并不能將其完全銷毀)。在Linux進(jìn)程的狀態(tài)中,僵尸進(jìn)程 是非常特殊的一種,它已經(jīng)放棄了幾乎所有內(nèi)存空間,沒(méi)有任何可執(zhí)行代碼,也不能被調(diào)度,僅僅在進(jìn)程列表中保留一個(gè)位置,記載該進(jìn)程的退出狀態(tài)等信息供其他進(jìn)程收集,除此之外,僵尸進(jìn)程不再占有任何內(nèi)存空間。它需要它的父進(jìn)程來(lái)為它收尸,如果他的父進(jìn)程沒(méi)安裝SIGCHLD信號(hào)處理函數(shù)調(diào)用wait或waitpid()等待子進(jìn)程結(jié)束,又沒(méi)有顯式忽略該信號(hào),那么它就一直保持僵尸狀態(tài),如果這時(shí)父進(jìn)程結(jié)束了,那么init進(jìn)程自動(dòng)會(huì)接手這個(gè)子進(jìn)程,為它收尸,它還是能被清除的。但是如果如果父進(jìn)程是一個(gè)循環(huán),不會(huì)結(jié)束,那么子進(jìn)程就會(huì)一直保持僵尸狀態(tài),這就是為什么系統(tǒng)中有時(shí)會(huì)有很多的僵尸進(jìn)程。 2.SIGTERM信號(hào) kill() 可以發(fā) SIGTERM 過(guò)去;kill 命令默認(rèn)也使用 SIGTERM 信號(hào)。 |
$ kill -l 列表中,編號(hào)為1 ~ 31的信號(hào)為傳統(tǒng)UNIX支持的信號(hào),是不可靠信號(hào)(非實(shí)時(shí)的),編號(hào)為32 ~ 63的信號(hào)是后來(lái)擴(kuò)充的,稱做可靠信號(hào)(實(shí)時(shí)信號(hào))。不可靠信號(hào)和可靠信號(hào)的區(qū)別在于前者不支持排隊(duì),可能會(huì)造成信號(hào)丟失,而后者不會(huì)。 下面我們對(duì)編號(hào)小于SIGRTMIN的信號(hào)進(jìn)行討論。 1) SIGHUP 登錄Linux時(shí),系統(tǒng)會(huì)分配給登錄用戶一個(gè)終端(Session)。在這個(gè)終端運(yùn)行的所有程序,包括前臺(tái)進(jìn)程組和后臺(tái)進(jìn)程組,一般都屬于這個(gè) Session。當(dāng)用戶退出Linux登錄時(shí),前臺(tái)進(jìn)程組和后臺(tái)有對(duì)終端輸出的進(jìn)程將會(huì)收到SIGHUP信號(hào)。這個(gè)信號(hào)的默認(rèn)操作為終止進(jìn)程,因此前臺(tái)進(jìn) 程組和后臺(tái)有終端輸出的進(jìn)程就會(huì)中止。不過(guò)可以捕獲這個(gè)信號(hào),比如wget能捕獲SIGHUP信號(hào),并忽略它,這樣就算退出了Linux登錄,wget也 能繼續(xù)下載。 此外,對(duì)于與終端脫離關(guān)系的守護(hù)進(jìn)程,這個(gè)信號(hào)用于通知它重新讀取配置文件。 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 如果父進(jìn)程沒(méi)有處理這個(gè)信號(hào),也沒(méi)有等待(wait)子進(jìn)程,子進(jìn)程雖然終止,但是還會(huì)在內(nèi)核進(jìn)程表中占有表項(xiàng),這時(shí)的子進(jìn)程稱為僵尸進(jìn)程。這種情 況我們應(yīng)該避免(父進(jìn)程或者忽略SIGCHILD信號(hào),或者捕捉它,或者wait它派生的子進(jìn)程,或者父進(jìn)程先終止,這時(shí)子進(jìn)程的終止自動(dòng)由init進(jìn)程來(lái)接管)。 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 在以上列出的信號(hào)中,程序不可捕獲、阻塞或忽略的信號(hào)有:SIGKILL,SIGSTOP 此外,SIGIO在SVR4是退出,在4.3BSD中是忽略;SIGCONT在進(jìn)程掛起時(shí)是繼續(xù),否則是忽略,不能被阻塞。 |
轉(zhuǎn)自:http://xok.la/2010/01/mysqlslap_test.html
mysqlslap是官方提供的壓力測(cè)試工具之一,官方介紹如下:
下面介紹一些常見(jiàn)參數(shù):
下面是一個(gè)完整的例子:
具體的慢慢看手冊(cè)吧,mysqlslap在mysql的目錄的bin目錄內(nèi)。
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);