A. SElinux許可權
在了解SELinux之前,我們先來了解一下Linux的兩種訪問控制策略:DAC和MAC
DAC,自主訪問控制(Discretionary Access control)。系統只提供基本的驗證, 完整的訪問控制由開發者自己控制。
DAC將資源訪問者分成三類:Owner、Group、Other 。
將訪問許可權也分成三類:read、write、execute
資源針對資源訪問者設置不同的訪問許可權。訪問者通常是各個用戶的進程,有自己的uid/gid,通過uid/gid 和文件許可權匹配, 來確定是否可以訪問。DAC機制下,每一個用戶進程默認都擁有該用戶的所有許可權。
DAC 有兩個嚴重問題:
問題一:
因為Root用戶是擁有所有許可權的,所以DAC對Root用戶的限制是無效的。並且在Linux Kernel 2.1以後,Linux將Root許可權根據不同的應用場景劃分成許多的Root Capabilities, 普通用戶也可以被設置某個Root Capability。普通用戶如果被設置了CAP_DAC_OVERRIDE, 也可以繞過 DAC 限制。
問題二:
用戶進程擁有該用戶的所有許可權,可以修改/刪除該用戶的所有文件資源, 難以防止惡意軟體。
可見,DAC 有明顯的缺陷,一旦被入侵,取得Root許可權的用戶進程就可以無法無天,胡作非為,早期android版本就深受其害。
MAC, 強制性訪問控制(Mandatory Access control)。 系統針對每一項訪問都進行嚴格的限制, 具體的限制策略由開發者給出。
Linux MAC 針對DAC 的不足, 要求系統對每一項訪問, 每訪問一個文件資源都需要根據已經定義好了的策略進行針對性的驗證。系統可以針對特定的進程與特定的文件資源來進行許可權的控制。即使是root用戶,它所屬的不同的進程,並不一定能取得root許可權,而得要看事先為該進程定義的訪問限制策略。如果不能通過MAC 驗證,一樣無法執行相關的操作。
與DAC相比,MAC訪問控制的「主體」變成了「進程」而不是用戶。這樣可以限制了Root 許可權的濫用,另外要求對每一項許可權進行了更加完整的細化, 可以限制用戶對資源的訪問行為。
SELinux就是目前最好的MAC機制,也是目前的行業標准。
SELinux,安全增強Linux(Security-Enhanced Linux),是由美國國家安全局(NSA)發起, 多個非營利組織和高校參與開發的強制性安全審查機制(Mandatory Access control,簡稱MAC)。SELinux最早於2000年12月採用GPL許可發布。目前,Linux Kernel 2.6 及以上的版本都已經集成了SELinux。
SELinux 分成三種模式:
Android 5.x及以上強制開啟,因此,disabled(關閉)模式並沒有什麼用了。 通常在調試時,我們會啟用Permissve(寬容模式), 以便盡可能的發現多的問題, 然後一次修正。 在量產時啟用Enfocing mode(強制模式)來保護系統。
查看SELinux模式:adb shell getenforce
設置SELinux模式:adb shell setenforce 1 //0是Permissve,1是Enfocing
SELinux 的訪問控制示意圖:
通常我們開發的過程中,就是配置Subject、Object、Security Policy。
SELinux 給Linux 的所有對象都分配一個安全上下文(Security Context), 描述成一個標準的字元串。
安全上下文的標准格式: user:role:type[:range]
Security Label 用來綁定被訪問資源和安全上下文,描述它們的對應關系。標准格式為:resource security_context。即:res user:role:type[:range]。這里也可以使用通配符,例如 net.就可以綁定所有以net.開頭的屬性,除此之外,還有類似正則表達式的*、?等等通配符。Security Label 都定義在type_contexts當中,例如file的定義在file_contexts中,service定義在service_contexts中,property定義在property_contexts中。
舉例:
file_contexts:
service_contexts:
查看進程安全上下文: ps -AZ 。例如,查看Settings進程的安全上下文,ps -AZ | grep settings:
u:r:system_app:s0 system 1381 585 4234504 201072 0 0 S com.android.settings
查看文件安全上下文: ls -Z 。例如,查看文件build.prop的安全上下文:
u:object_r:system_file:s0 build.prop
Type Enforcement (TE) 是根據Security Context中的 type 進行許可權審查, 審查 subject type 對 object type 的某個class 類型中某種permission 是否具有訪問許可權,是目前使用最為廣泛的MAC 審查機制, 簡單易用。
TE控制語句格式 : rule_name source_type target_type : class perm_set
Type Enforcement規則說明:
舉個例子,logd.te、tombstoned.te中定義的TE規則:
allow logd runtime_event_log_tags_file:file rw_file_perms;
dontaudit domain runtime_event_log_tags_file:file { open read };
auditallow tombstoned anr_data_file:file { append write };
neverallow logd { app_data_file system_data_file }:dir_file_class_set write;
SELinux 中每一個進程或者文件都對應一個type, 而每一個type 都對應有一個或幾個attribute。所有常見的attribute定義在以下文件中:
system/sepolicy/public/attributes
system/sepolicy/prebuilts/api/[build version]/public/attributes
system/sepolicy/prebuilts/api/[build version]/private/attributes
其中的[build version]即為android版本號,例如android O為28.0。常見的attribute定義:
Type對應一個或者幾個attribute,Type的定義格式:
type type_name, attribute1, attribute2;
Type的定義通常分散在各個te文件中。例如,常用普通文件的type定義在file.te中:
SEAndroid對於不同的資源類型,定義了不同的Class。比如普通的file、socket等等,比如SELinux 使用的security, 比如針對每個process 參數的process 等定義相關的class。這些class,每一個class 都有相對應的permissions。 比如file 就有 read, write, create, getattr, setattr, lock, ioctl 等等. 比如process 就有fork, sigchld, sigkill, ptrace, getpgid, setpgid 等等。這些相關的class, 以及他們具有那些Permissions都定義在以下文件中:
system/sepolicy/private/access_vectors
system/sepolicy/reqd_mask/access_vectors
system/sepolicy/prebuilts/api/版本號/private/access_vectors
例如:
定義完之後,在以下對應的security_classes 文件中聲明定義的classes。
system/sepolicy/private/security_classes
system/sepolicy/reqd_mask/security_classes
system/sepolicy/prebuilts/api/版本號/private/security_classes
例如:
注意,Classes 和Permissions的定義與Kernel 中相關API是強相關的,普通用戶嚴禁修改。
在SELinux 中, 我們通常稱一個進程是一個domain, 一個進程fork 另外一個進程並執行(exec) 一個執行檔時, 我們往往會涉及到domain 的切換. 比如init 進程, SELinux 給予了它很大的許可權, 而它拉起的服務, 我們要限制這個服務的許可權,於是就涉及到從一個domain 切換到另外一個domain, 不然默認就使用init 進程的domain.
在SELinux 裡面有專門的一條語法: type_transition statement.
在准備切換前我們先要確保有相關的許可權操作:
如下面的demo, init 拉起apache 並且切換到 apache 的domain.
(1). 首先,你得讓init_t域中的進程能夠執行type為apache_exec_t的文件
allow init_t apache_exec_t : file {read getattr execute};
(2). 然後,你還得告訴SELinux,允許init_t做DT切換以進入apache_t域
allow init_t apache_t : process transition;
(3). 然後,你還得告訴SELinux,切換入口(對應為entrypoint許可權)為執行apache_exec_t類型 的文件
allow apache_t apache_exec_t : file entrypoint;
(4).最後,Domain Transition
type_transition init_t apache_exec_t : process apache_t;
可以看到,整個domain切換過程寫起來非常麻煩。因此,Google 為了使用方便, 在system/sepolicy/public/te_macros 文件中定義了宏:
我們可以使用這些宏來完成domain切換。
舉例:
kernel啟動init進程切換domain:
domain_auto_trans(kernel, init_exec, init)
init啟動netd、vold、zygote、installd切換domain:
init_daemon_domain(netd)
init_daemon_domain(vold)
init_daemon_domain(zygote)
init_daemon_domain(installd)
一個進程創建在一個目錄下創建文件時, 默認是沿用父目錄的Security Context, 如果要設置成特定的Label, 就必須進行Object Transitions.
同樣是使用:type_transition statement.
對應的必須有兩個前提條件:
下面是一個demo, ext_gateway_t 這個domain 在類型為in_queue_t 的目錄下,創建類型為 in_file_t 的文件.
(1). 首先,你得讓ext_gateway_t 對in_queue_t 目錄具備訪問許可權
allow ext_gateway_t in_queue_t : dir { write search add_name };
(2). 然後,你還得告訴SELinux,允許ext_gateway_t 訪問in_file_t的文件
allow ext_gateway_t in_file_t : file { write create getattr };
(3).最後,Object Transition
type_transition ext_gateway_t in_queue_t : file in_file_t;
同樣的,為了方便使用,Google 也在system/sepolicy/public/te_macros 文件中定義了宏:
使用舉例:
file_type_auto_trans(factory, system_data_file, factory_data_file)
android O 以前sepolicy 集中放在boot image 。前面提到SELinux在Android的主要變更歷史時,有提到android O 開始,Google將system image 和 vendor image 分離。因此,sepolicy 也相應的被分離存放到system image 以及 vendor image。與system 相關的sepolicy 就存放system image, 與SoC vendor 相關的sepolicy 就存放在vendor image。
對於原生AOSP,Google 設定了不同的存放目錄, 以便進行分離, 以Google 默認的sepolicy 為例,sepolicy主目錄為 /system/sepolicy,我們主要關注三個子目錄:
對於不同的平台,不同平台廠商也設定了不同的存放目錄,以MTK平台為例:
首先,根據不同的platform共用sepolicy、platform獨有、project獨有,分為:
對應的,不同版本會導入不同目錄下的sepolicy配置
以mt6763平台為例,導入時:
[common] 路徑為:/device/mediatek/sepolicy
[platfrom] 路徑為:/device/mediatek/mt6763/sepolicy/
具體的定義在BoardConfig.mk文件中:
然後,basic、bsp、full又可以主要細分為:
Google 在system/sepolicy 中定義了相關的neverallow 規則, 對SELinux Policy 的更新進行了限制, 以防止開發者過度開放許可權,從而引發安全問題。並且還會通過CTS測試檢測開發者是否有違法相關的規則。
因此,我們需要注意以下幾點:
出現SELinux Policy Exception時常見的兩種解決方案:
(1). 修改對應節點的SELinux Security Label, 為特定的Subject,如system_app、platform_app、priv_app,例如Settings,SystemUI等內置APP開啟許可權, 但嚴禁為untrsted app 開啟許可權。
(2). 通過system server service 或者 init 啟動的service 讀寫操作, 然後app 通過binder/socket 等方式連接訪問. 此類安全可靠, 並且可以在service 中做相關的安全審查, 推薦這種方法.
情景: 定義由 init 進程啟動的service, factory, 其對應的執行檔是 /vendor/bin/factory。
(1). 在device/mediatek/mt6763/sepolicy/basic/non_plat 目錄下創建一個factory.te , 然後將te文件加入編譯,如放到這種指定目錄下不需要額外配置,sytem/sepolicy/Android.mk中定義的build_policy函數會遍歷指定目錄導入te文件。
(2). 在factory.te 中定義factory類型,init 啟動service 時類型轉換,
type factory, domain;
type factory_exec, exec_type, file_type, vendor_file_type;
init_daemon_domain(factory)
(3). 在file_contexts中綁定執行檔
/(system/vendor|vendor)/bin/factory u:object_r:factory_exec:s0
(4). 根據factory需要訪問的文件以及設備, 定義其它的許可權在factory.te 中.
#Purpose: For key and touch event
allow factory input_device:chr_file r_file_perms;
allow factory input_device:dir rw_dir_perms;
情景: 添加一個自定義的system property: persist.demo,並為platform_app設置讀寫許可權
(1). 在property.te中定義system property類型
type demo_prop, property_type
(2). 在property_contexts中綁定system property的安全上下文。
persist.demo u:object_r:demo_prop:s0
(3). 在platform_app.te 中新增寫許可權,可以使用set_prop宏。
set_prop(platform_app, demo_prop)
(4). 在platform_app.te 中新增讀許可權,可以get_prop 宏。
get_prop(platform_app, demo_prop)
情景: 有一個設備節點/dev/demo,有一個platform_app進程需要讀寫這個設備節點。
(1). 在device.te中定義device 類型
type demo_device dev_type;
(2). 在 file_contexts中綁定demo_device
/dev/demo u:object_r:demo_device:s0
(3). 在platform_app.te中,允許platform_app使用demo device 的許可權
allow platform_app demo_device:chr_file rw_file_perms;
情景: 有一個擴展的系統服務demo_service供APP調用。
(1). 在service.te 中定義service 類型
type demo_service, app_api_service, system_server_service, service_manager_type;
(2). 在service_contexts 中綁定service
demo u:object_r:demo_service:s0
(3). 在frameworks/base/core/java/android/content/Context.java中定義服務常量
public static final String DEMO_SERVICE = "demo";
(4). 在frameworks/base/core/java/android/app/SystemServiceRegistry.java中,參照其它系統服務注冊demo_service
(5). 在frameworks/base/services/java/com/android/server/SystemServer.java中,啟動DemoService,添加到service_manager進行管理。
(6). 最後一步,參考其它系統服務,實現DemoManager、DemoService,並定義如IDemoService等等的AIDL介面。
情景: 一個native service 通過init 創建一個socket 並綁定在 /dev/socket/demo, 並且允許某些process 訪問.
(1). 在file.te中定義socket 的類型
type demo_socket, file_type;
(2). 在file_contexts中綁定socket 的類型
/dev/socket/demo_socket u:object_r:demo_socket:s0
(3). 允許所有的process 訪問,使用宏unix_socket_connect(clientdomain, socket, serverdomain)
unix_socket_connect(appdomain, demo, demo)
(1). 在device/mediatek/mt6763/sepolicy/basic/non_plat目錄下創建一個demo.te。
(2). 在demo.te 中定義demo 類型,init 啟動service 時類型轉換。並可以根據demo 需要訪問的文件以及設備, 定義其它的許可權在demo.te 中。
type demo, domain;
type demo_exec, exec_type, file_type;
init_daemon_domain(demo)
(3). 綁定執行檔 file_context 類型
/vendor/bin/demo u:object_r:demo_exec:s0
(4). 創建demo的入口執行檔demo_exec、並配置相應的許可權。
(1). 將SELinux 調整到Permissive 模式復測
使用eng/userdebug 版本,adb shell setenforce 0 將SELinux 模式調整到Permissive 模式,然後復測。如果還能復現問題,則與SELinux 無關; 如果原本很容易復現, 而Permissive mode 不能再復現, 那麼就可能與SELinux相關。
(2). 查看LOG 中是否有標準的SELinux Policy Exception.
在Kernel LOG / Main Log 中查詢關鍵字 "avc: denied" 看看是否有與目標進程相關的SELinux Policy Exception, 並進一步確認這個異常是否與當時的邏輯相關。
一般情況我們在符合Google sepolicy策略及neverallow策略的前提下,根據LOG中的內容,需要什麼許可權就加什麼許可權。例如LOG:
2020-03-27 14:11:02.596 1228-1228/com.android.systemui W/FaceIdThread: type=1400 audit(0.0:481): avc: denied { read } for name="als_ps" dev="tmpfs" ino=10279 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:als_ps_device:s0 tclass=chr_file permissive=0
LOG說明如下:
一般我們需要重點關注的是四個:permission、source type、target type、target class
根據這四個就可以配置出的所需要的selinux許可權:
allow [source type] [target type]: [target class] [permission]
例1:
03-27 03:45:22.632 2958 2958 W Camera: type=1400 audit(0.0:314): avc: denied { read } for name="u:object_r:graphics_debug_prop:s0" dev="tmpfs" ino=2649 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:graphics_debug_prop:s0 tclass=file permissive=0
解決方案:
按正常的套公式,應該是這樣修改platform_app.te,增加:
allow platform_app graphics_debug_prop:file r_file_perms;
這里我們利用system/sepolicy/te_macros中定義的宏get_prop:
更多相關的宏定義請參考:system/sepolicy/public/te_macros。
所以最終簡化後,修改platform_app.te,增加:
get_prop(platform_app, graphics_debug_prop)
例2:
03-27 14:11:02.596 1228-1228/com.android.systemui W/BackThread: type=1400 audit(0.0:481): avc: denied { read } for name="als_ps" dev="tmpfs" ino=10279 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:als_ps_device:s0 tclass=chr_file permissive=0
解決方案:
修改platform_app.te增加:
allow platform_app als_ps_device:chr_file r_file_perms;
(1). 不符合neverallow規則或者修改了neverallow規則
編譯報錯:
neverallow check failed at xxx
CTS測試項failed:
android.cts.security.SELinuxNeverallowRulesTest#testNeverallowRulesXXX
這類問題在android O vendor和system分離之後,尤其容易出現。基本上這類問題都是因為修改或者增加的te配置不符合neverallow規則,導致編譯報錯。而為了解決編譯報錯,又修改了neverallow規則,最終在跑CTS時,沒法通過相關的測試項。
解決思路:
(2). init進程fork新進程沒有做domain切換
CTS測試項failed:
android.security.cts.SELinuxDomainTest # testInitDomain
解決思路:
fork進程時,參考3.4節中做domain切換。
本文主要參考了MTK-Online的Quick-start中《SELinux 問題快速分析》的內容,感謝原作者們的辛勤付出。另外,結合源碼和自身開發實踐,增加了一些自身理解和實踐內容。
B. linux中安裝了一個插件,這個插件裝完後正常的情況在終端輸入./phpxujh -p pid可查看當前PID的運行情況,
目錄
開始之前
系統環境
監控內容
所需軟體包
CentOS7重要變化
配置開發環境
同步時間
關閉Selinux
使用CRT上傳軟體包
安裝郵件服務
監控主機安裝
常用到的命令
安裝nagios所需要的運行環境
增加用戶
安裝nagios
配置許可權
安裝插件
安裝nrpe
遠程主機安裝
常用到的命令
配置運行環境
安裝nagios-plugin
安裝nrpe
啟動nrpe
監控主機安裝PNP
配置開發環境
安裝pnp4nagios (版本號為0.6)
配置pnp4nagios
圖表展示
問題集合
在首次配置了nagios監控端後,在瀏覽器輸入地址後連接不上
啟動nrpe後卻不能互相通信
安裝pnp4nagios後出現The requested URL /pnp4nagios/graph was not found on this server.
出現「CHECK_NRPE: Error - Could not complete SSL handshake.」的錯誤
執行 ./configure時報錯:configure error cannot find ssl headers
解壓./configure 後,在nagios-4.0.8進行make all報錯
安裝nrpe時執行.configure出錯
錯誤:perfdata directory "/usr/local/pnp4nagios/var/perfdata/" is empty
開始之前
聲明:本文中的命令都經過了測試,但難免有所紕漏,如果你發現命令粘貼後運行有錯,可能是由於符號的格式(尤其是破折號)導致的,此時你應該自己手打一遍命令。對於本文中發現的錯誤和建議,請發送郵件給我:
[email protected],請在郵件主題里註明「關於nagios的問題(建議)」。
--------------------------------------分割線 --------------------------------------
在Ubuntu下配置Mrtg監控Nginx和伺服器系統資源 http://www.linuxidc.com/Linux/2013-08/88417.htm
使用 snmp+Mrtg 監控 Linux 系統 http://www.linuxidc.com/Linux/2012-11/73561.htm
Mrtg伺服器搭建(監控網路流量) http://www.linuxidc.com/Linux/2012-07/64315.htm
網路監控器Nagios全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm
Nagios搭建與配置詳解 http://www.linuxidc.com/Linux/2013-05/84848.htm
Nginx環境下構建Nagios監控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm
在RHEL5.3上配置基本的Nagios系統(使用Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm
CentOS 5.5+Nginx+Nagios監控端和被控端安裝配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm
Ubuntu 13.10 Server 安裝 Nagios Core 網路監控運用 http://www.linuxidc.com/Linux/2013-11/93047.htm
--------------------------------------分割線 --------------------------------------
系統環境
一共3台機器,全都按照CentOS7最小化模式安裝系統
系統版本號
[root@localhost ~]# cat /etc/RedHat-release
CentOS Linux release 7.0.1406 (Core)
監控主機
(一台)
IP地址:192.168.1.204
主機名稱:nagios_server_204
遠程主機
(兩台)
IP地址:192.168.1.112
主機名稱:nagios_slave_112
IP地址:192.168.1.113
主機名稱:nagios_slave_113
分區情況
安裝時使用默認分區(使用 df 命令來查看)
[root@localhost ~]# df -h
監控內容
要監控的服務
監控命令
cpu負載
(check_linux_state.pl -C)
當前用戶登錄數量
(check_users)
磁碟使用情況
(check_disk)
總進程數
(check_procs)
內存使用情況
(check_linux_stats.pl -M)
負載均衡
(check_load)
磁碟IO
(check_linux_stats.pl -I)
網路流量
(check_linux_stats.pl -N)
打開的文件數量
(check_linux_stats.pl -F)
socket連接數
(check_linux_stats.pl -S)
進程使用的內存和CPU
(check_linux_stats.pl -T)
指定的網站是否可連接
(check_http)
系統在線時長
(check_uptime)
所需軟體包
監控主機
軟體包
下載地址
nagios-4.0.8.tar.gz
請到我的github地址里下載:
https://github.com/Kylinlin/install_nagios_automatically/tree/master/nagios_tools_for_server
註明:我的github項目install_nagios_automatically是一個一鍵自動化安裝nagios的項目(能運行,但還在完善中)
nagios-plugins-2.0.3.tar.gz
nrpe-2.15.tar.gz
pnp4nagios-0.6.25.tar.gz
Sys-Statistics-Linux-0.66.tar.gz
libxml2-2.7.1.tar.gz
遠程主機
軟體包
下載地址
nagios-plugins-2.0.3.tar.gz
請到我的github地址里下載:
https://github.com/Kylinlin/install_nagios_automatically/tree/master/nagios_tools_for_client
nrpe-2.15.tar.gz
Sys-Statistics-Linux-0.66.tar.gz
Centos7重要變化
Centos7相比較以前的Centos有一些涉及到常用命令的變化,如果不事先了解,會在使用命令的時候造成巨大的困擾
Centos7默認沒有ifconfig和netstat兩個命令了,ip addr命令代替了ifconfig,只要安裝上net-tools包就可以繼續使用ifconfig和netstat兩個命令了
systemctl命令的出現(systemctl可以看作是service和chkconfig的組合),雖然仍然可以使用以前的命令,但是會重定向到新的命令中,下面以http服務為例
job
以前的系統
CentOS7
服務開機啟動
chkconfig --level 3 httpd on
systemctl enable httpd.service
服務不開機啟動
chkconfig --level 3 httpd off
systemctl disable httpd
服務狀態
service httpd status
systemctl status httpd
所有服務的啟動狀態
chkconfig --list
systemctl
啟動服務
service httpd start
systemctl start httpd.service
停止服務
service httpd stop
systemctl stop httpd.service
重啟服務
service httpd restart
systemctl restart httpd.service
配置開發環境
同步時間
把監控系統里的所有機器都同步一次網路時間(非常重要)
[root@localhost ~]timedatectl #該命令用來檢查當前時間和時區
如果發現所有機器的時區不一致,此時就要使用命令
[root@localhost ~]timedatectl list-timezones #該命令列出了所有的時區
[root@localhost ~]timedatectl set-timezone Asia/Shanghai #該命令把時區設置為上海
ntpdate time.nist.gov #該命令同步網路當前的時間
如果提示沒有ntpdate命令,則安裝ntp,並且配置系統自動更新時間
[root@localhost ~]# yum install ntp -y
[root@localhost ~]# /usr/sbin/ntpdate time.nist.gov
[root@localhost ~]# echo '#time sync'>>/var/spool/cron/root
[root@localhost ~]# echo '*/10**** /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1'>>/var/spool/cron/root
關閉Selinux
不關閉selinux可能會導致一些難以察覺的錯誤,為了保險起見,首先關閉selinux:
[root@localhost ~]vi /etc/selinux/config
重啟機器
檢查selinux是否關閉:
[root@localhost ~]getenforce #如果顯示enforcing則沒有關閉
使用SecureCRT上傳軟體包
我在這里使用的SSH連接工具是SecureCRT7.2,通過這個工具上傳文件到Linux的步驟如下:
1. 首先在Linux中安裝傳送文件命令:
[root@localhost ~] yum install lrzsz -y
2. 然後在Linux中跳轉到/usr/local/src目錄下
[root@localhost ~] cd /usr/local/src
3. 運行CRT的傳送文件命令
安裝郵件服務
因為郵件報警服務需要安裝mail功能
[root@localhost ~]yum install –y mailx
[root@localhost ~]yum install –y sendmail
[root@localhost ~]systemctl restart sendmail.service
[root@localhost ~]mail –s Test [email protected](你的郵箱地址)
#此時進入輸入模式,輸入完郵件內容後按ctrl + d退出並且發送
監控主機安裝
常用到的命令
命令內容
命令格式
檢查nagios的配置文件是否有錯
/etc/init.d/nagios checkconfig
或者
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
啟動nagios
systemctl start nagios.service
或者
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
修改了nagios的配置文件後重新載入配置文件
/etc/init
安裝nagios所需要的運行環境
[root@localhost ~]# yum install gcc glibc glibc-common -y
[root@localhost ~]# yum install php php-gd perl -y
[root@localhost ~]# yum install httpd gd gd-devel openssl openssl-devel -y
[root@localhost ~]# systemctl enable httpd.service #設置CentOS開機啟動服務
增加用戶
[root@localhost ~]useradd -m nagios
並將nagios以及apache用戶加入到nagcmd組中
[root@localhost ~]groupadd nagcmd
[root@localhost ~]usermod -G nagcmd nagios
[root@localhost ~]usermod -a -G nagcmd apache #把apace用戶添加到與nagios的一個組(apache用戶會在安裝apache時自動創建)
安裝nagios
[root@localhost src]# tar -zxvf nagios-4.0.8.tar.gz
[root@localhost src]# cd nagios-4.0.8
首先初始化和建立編譯的環境
[root@localhost nagios-4.0.8]#./configure --with-command-group=nagcmd
如果能看到下面的基本配置信息則說明初始的環境已經成功配置完成:
之後按照提示執行命令來進行編譯:
[root@localhost nagios-4.0.8]# make all
[root@localhost nagios-4.0.8]# make install
[root@localhost nagios-4.0.8]# make install-init
[root@localhost nagios-4.0.8]# make install-config
[root@localhost nagios-4.0.8]# make install-commandmode
[root@localhost nagios-4.0.8]# make install-webconf
安裝完成之後,在/usr/local/nagios目錄下如果能夠看到這些目錄:
就表示Naigos安裝成功了。
Nagios的樣例配置文件默認安裝在/usr/local/nagios/etc目錄下,配置這些文件就可以使得nagios按要求運行(詳細的配置過程請參考我的另一篇博文:nagios服務配置詳解)
此時應該為email指定您想用來接收nagios警告信息的郵件地址,默認是本機的nagios用戶:
[root@localhost]# vi /usr/local/nagios/etc/objects/contacts.cfg
email nagios@localhost #把描紅的地方修改為你的email地址
創建一個登錄nagios web程序的用戶(用戶名配置為nagiosadmin則不需要配置許可權,設置為其他用戶名就要配置許可權),我在這里把用戶名設置為kylinlin,密碼為123456,這個用戶帳號在以後通過web登錄nagios認證時所用:
[root@localhost ~]# htpasswd -bc /usr/local/nagios/etc/htpasswd.users kylinlin 123456 #把描紅的地方修改為你的用戶名和密碼
配置許可權
如果在上面創建登陸nagios web程序的用戶名不是nagiosadmin(我在上面已經設置為kylinlin),在登陸nagios的web界面後(此時我們還不能登錄,但如果你忽略了這一小節的配置,那麼在後面的登陸中就會看到如下的界面),點擊Hosts或Services會顯示圖片紅色的錯誤提示
是因為nagios默認把全部的許可權給nagiosadmin,所以可以通過修改cgi.cfg文件賦予kylinlin許可權,切換到/usr/local/nagios/etc目錄下
[root@localhost etc]# sed -i 's#nagiosadmin#kylinlin#g' cgi.cfg #這條命令將nagiosadmin用戶名替換為kylinlin
[root@localhost etc]# grep kylinlin cgi.cfg #這條命令檢查是否修改成功
以上過程配置結束以後需要重新啟動httpd:
[root@localhost etc]# systemctl restart httpd.service
檢查其主配置文件的語法是否正確:
[root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
或者使用下面這個命令來檢查語法
[root@localhost etc]# /etc/init.d/nagios checkconfig
顯示錯誤數為0才正確
配置成功
安裝插件
剛才已經提到Nagios主程序只是一個控制中心,而能夠起到服務監測和系統監測等功能的是眾多Nagios的插件,沒有插件的Nagios系統其實只是一個空殼。因此在安裝了Nagios平台之後我們還需要安裝插件。
Nagios插件同樣是在其官方網站下載,目前版本是1.4.15。我將下載的源碼包放到/usr/local目錄下,按照下面的步驟進行解壓,編譯和安裝:
[root@localhost src]# tar zxf nagios-plugins-2.0.3.tar.gz
[root@localhost src]# cd nagios-plugins-2.0.3
[root@localhost nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost nagios-plugins-2.0.3]#make
[root@localhost nagios-plugins-2.0.3]#make install
通過下面的命令查看安裝了多少個插件
[root@localhost nagios-plugins-2.0.3]#ls /usr/local/nagios/libexec/|wc -l
然後把Nagios加入到服務列表中以使之在系統啟動時自動啟動:
[root@localhost nagios-plugins-2.0.3]# chkconfig --add nagios
[root@localhost nagios-plugins-2.0.3]# chkconfig nagios on
執行下面的命令來驗證Nagios的樣例配置文件:
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
C. (追加100分!)誰能幫我找到linux/unix系統下創建文件夾的C語言源碼
去下載busybox的源碼,在busybox-XXXX/coreutils/mkdir.c
/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 2001 Matt Kraai <[email protected]>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
/* Mar 16, 2003 Manuel Novoa III ([email protected])
*
* Fixed broken permission setting when -p was used; especially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <[email protected]>: Add SELinux Support.
*/
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const char mkdir_longopts[] ALIGN1 =
"mode\0" Required_argument "m"
"parents\0" No_argument "p"
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
;
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
unsigned opt;
char *smode;
#if ENABLE_SELINUX
security_context_t scontext;
#endif
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts;
#endif
opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) {
mode = 0777;
if (!bb_parse_mode(smode, &mode)) {
bb_error_msg_and_die("invalid mode '%s'", smode);
}
}
if (opt & 2)
flags |= FILEUTILS_RECUR;
#if ENABLE_SELINUX
if (opt & 4) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
#endif
if (optind == argc) {
bb_show_usage();
}
argv += optind;
do {
if (bb_make_directory(*argv, mode, flags)) {
status = EXIT_FAILURE;
}
} while (*++argv);
return status;
}
D. 求教selinux源代碼獲取
linux下的內核頭文件放在/usr/include/linux/和/usr/include/sys/ linux目錄樹: scripts目錄 該目錄中不包含任何核心代碼,該目錄下存放了用來配置內核的腳本和應用程序源碼。 lib目錄 該目錄主要包含兩部分內容:gnuzip解壓縮演算法,用於在系統.
E. Linux系統下如何一次性創建多個文件夾
1、首先,連接相應linux主機,進入到linux命令行狀態下,等待輸入shell指令。回
F. 求小紅帽Linux下載地址及源碼下載地址
在經歷了兩次跳票以後, Red Hat於2007年3月14日正式發布了RHEL5. RHEL 5將是Red Hat的商業伺服器操作系統版本的第四次重要版本發布, Red Hat醞釀發布RHEL 5已經超過了兩年, 主要變化包括Linux內核由2.6.9升級為2.6.18, 支持Xen虛擬化技術, 集群存儲等.
RHEL5的版本主要分為Sever和Desktop兩個版本。
具體來說,Server版本分為:
· Red Hat Enterprise Linux Advanced Platform - 對應以前的· Red Hat Enterprise Linux AS
· Red Hat Enterprise Linux - 對應以前的Red Hat Enterprise Linux AS
Desktop版本分為:
· Red Hat Enterprise Linux Desktop - 對應以前的Red Hat Desktop
· Red Hat Enterprise Linux Desktop with Workstation option - 對應以前的Red Hat Enterprise Linux WS
主要的功能包括:
1. 虛擬化技術
在各種平台上支持虛擬化技術
在Red Hat Enterprise Linux Advanced Platform支持存儲與擴展的伺服器虛擬化技術
Red Hat Network提供各種虛擬化系統的支持
virt-manager, libvirt/virsh管理工具
2. 內核與性能
基於Linux 2.6.18內核
支持多核處理器
廣泛的新硬體支持
更新的基於Kexec/Kmp的Dump支持
支持Intel Network Accelerator Technology (IOAT)
對於大型SMP系統技持的增強
增強的管道緩存
內核緩存接合能力用於改進IO緩存操作
3. 安全
SELinux增強
圖形化SELinux管理界面
集成的目錄和安全機制
增強的IPESEC提高安全與性能
新的審計機制用於提供新的搜索、報表和實時監控的能力
4. 網路與互操作性
支持Autofs, FS-Cache和iSCSI
增強的IPv6支持
改進的Microsoft®文件/列印和Active Directory集成
5. 桌面
更新的管理工具、應用程序和對筆記本的支持
改進的ACPI支持,包括Suspend to Disk
智能卡登錄,包括PKI/Kerberos認證
集成的多媒體支持
增強的即插即用支持
Network Manager提供自動的有線和無線網路配置
基於AIGLX/Compiz的圖形化界面(支持淡化、透明等效果)
6. 開發環境
增強的開發工具,包括System Tap和Frysk
GCC4.1和glibc 2.5工具鏈
7. 存儲
支持根設置多路IO(MPIO),提高可用性
伺服器產品中包含單系統/客戶的Red Hat Global File System支持
塊設備數據加密支持
8. 管理
安裝過程更新簡化系統配
基於Yum/Pup的Red Hat Network更新
Conga集群和存儲管理
http://download.chinaunix.net/download/0013000/12382.shtml
G. Android系統集成自己的程序
之前在Android N平台上selinux是disabled的,這樣是生效的
但是Android P上好像沒有直接關閉selinux這個項,在bootargs_...txt文件中設置androidboot.selinux為disabled,但是開機啟動時仍然是Enforcing,查找原因:
發現在Android P上 system/core/init/init.cpp 中selinux狀態枚舉類型 enum selinux_enforcing_status { SELINUX_PERMISSIVE, SELINUX_ENFORCING, SELINUX_DISABLED };
包含三種狀態的,這樣adb shell getenforce ,源碼如下
然而在Android P上單獨分離出一個文件system/core/init/selinux.cpp,是如下定義的,
顯而易見,並沒有disabled狀態,得另想方案,於是在網路就看到了添加selinux 的te規則,使得Android系統允許開機運行我們的程序,設置androidboot.selinux為permissive
在device/hisilicon/bigfish/system/sepolicy/vendor 下添加屬於自己的規則,內容如下:
同目錄下file_contexts也要定義:
這樣結合上面這些,在init.rc中定義,並且添加屬於自己的規則TE文件,在selinux為permissive的情況的也能完成程序的自啟動
Android P和Android N不同,從Android O開始Google添加了客制化分區vendor分區,這樣導致原本在Android N上的運行程序放入system/bin下運行不了了,找不到庫,因為海思將他們的移到vendor/lib下面了,然而將自己程序移至vendor/bin下也會有許多問題,這樣在打包生成鏡像之前時就將vendor/lib所需要的庫到system/lib下,修改system/extras/ext4_utils/mkuserimg_mke2fs.sh腳本即可
H. linux系統中opt 、selinux 、srv、 media這些文件夾是做什麼用的
Linux文件夾
opt option自由選擇,主要給源碼安裝軟體時候選擇的安裝目錄位置
selinux 偽文件專系統kernel子系統通常使用的命屬令
srv 系統啟動服務時候可以訪問的資料庫目錄
media 一般是掛載cd、DVD的光碟
更深的可以搜索下:Linux目錄結構學習下
可以參考下:
http://www.360doc.com/content/14/0607/16/203871_384577619.shtml
I. 如何在centos上安裝samba圖形界面
組成Samba運行的有兩個服務,一個是SMB,另一個是NMB;SMB是Samba 的核心啟動服務,主要負責建立 Linux Samba伺服器與Samba客戶機之間的對話, 驗證用戶身份並提供對文件和列印系統的訪問,只有SMB服務啟動,才能實現文件的共享,監聽139 TCP埠;而NMB服務是負責解析用的,類似與DNS實現的功能,NMB可以把Linux系統共享的工作組名稱與其IP對應起來,如果NMB服務沒有啟動,就只能通過IP來訪問共享文件,監聽137和138 UDP埠。首先配置這些東西你需要先擁有root許可權。
1、關閉防火牆:service iptables stop。
2、關閉SELINUX的強制模式:setenforce 0,這個也不可忽略,如果setenforce 1,就好多共享都不成功了。
3、構建yum倉庫。打開目錄/etc/yum.repos.d下的CentOS-Base.repo文件。
4、在線Samba安裝包,開始安裝Samba。
yum install samba samba-client samba-swat,安裝過程不再貼圖。
5、查看安裝情況:rmp -qa|grep samba
7、保存退出:wq,重啟samba服務
創建/share目錄mkdir /share,並且設置chmod 777 /share——註:這樣做有風險,大家先達到共享這一步的效果,以後慢慢學習安全性的考慮。