首页 文章 精选 留言 我的

精选列表

搜索[centos],共5665篇文章
优秀的个人博客,低调大师

centos下利用yum安装卸载软件常用命令

一、使用yum安装和卸载软件,有个前提是yum安装的软件包都是rpm格式的。 安装的命令是,yum install ~,yum会查询数据库,有无这一软件包,如果有,则检查其依赖冲突关系,如果没有依赖冲突,那么最好,下载安装;如果有,则会给出提示,询问是否要同时安装依赖,或删除冲突的包,你可以自己作出判断; 删除的命令是,yum remove ~,同安装一样,yum也会查询数据库,给出解决依赖关系的提示。 其中~ 代表软件名 1.用YUM安装软件包命令:yum install ~ 2.用YUM删除软件包命令:yum remove ~ 二、用yum查询想安装的软件 我们常会碰到这样的情况,想安装一个软件,只知道它和某方面有关,但又不能确切知道它的名字。这时yum的查询功能就起作用了。我们可以用 yum search keyword这样的命令来进行搜索,比如我们要则安装一个Instant Messenger,但又不知到底有哪些,这时不妨用 yum search messenger这样的指令进行搜索,yum会搜索所有可用rpm的描述,列出所有描述中和messeger有关的rpm包,于是我们可能得到 gaim,kopete等等,并从中选择。 有时我们还会碰到安装了一个包,但又不知道其用途,我们可以用yum info packagename这个指令来获取信息。 1.使用YUM查找软件包 命令:yum search ~ 2.列出所有可安装的软件包 命令:yum list 3.列出所有可更新的软件包 命令:yum list updates 4.列出所有已安装的软件包 命令:yum list installed 5.列出所有已安装但不在Yum Repository 內的软件包 命令:yum list extras 6.列出所指定软件包 命令:yum list ~ 7.使用YUM获取软件包信息 命令:yum info ~ 8.列出所有软件包的信息 命令:yum info 9.列出所有可更新的软件包信息 命令:yum info updates 10.列出所有已安裝的软件包信息 命令:yum info installed 11.列出所有已安裝但不在Yum Repository 內的软件包信息 命令:yum info extras 12.列出软件包提供哪些文件 命令:yum provides~ 三、清除YUM缓存 yum 会把下载的软件包和header存储在cache中,而不会自动删除。如果我们觉得它们占用了磁盘空间,可以使用yum clean指令进行清除,更精确的用法是yum clean headers清除header,yum clean packages清除下载的rpm包,yum clean all 清除所有。 1.清除缓存目录(/var/cache/yum)下的软件包 命令:yum clean packages 2.清除缓存目录(/var/cache/yum)下的 headers 命令:yum clean headers 3.清除缓存目录(/var/cache/yum)下旧的 headers 命令:yum clean oldheaders 4.清除缓存目录(/var/cache/yum)下的软件包及旧的headers 命令:yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 四、yum命令工具使用举例 yum update 升级系统 yum install ~ 安装指定软件包 yum update ~ 升级指定软件包 yum remove ~ 卸载指定软件 yum grouplist 查看系统中已经安装的和可用的软件组,可用的可以安装 yum grooupinstall ~安装上一个命令显示的可用的软件组中的一个 yum grooupupdate ~更新指定软件组的软件包 yum grooupremove ~ 卸载指定软件组中的软件包 yum deplist ~ 查询指定软件包的依赖关系 yum list yum\* 列出所有以yum开头的软件包 yum localinstall ~ 从硬盘安装rpm包并使用yum解决依赖

优秀的个人博客,低调大师

CentOS6.9使用Rsync+sersync实现数据实时同步

Sersync简介 Sersync利用inotify与rsync对服务器进行实时同步,其中inotify用于监控文件系统事件,rsync是目前广泛使用的同步算法,其优点是只对文件不同的部分进行操作,所以其优势大大超过使用挂接文件系统的方式进行镜像同步。由金山的周洋开发完成,是目前使用较多的文件同步工具之一。该工具和其他的工具相比有如下优点: sersync是使用c++编写,由于只同步发生更改的文件,因此比其他同步工具更节约时间、带宽; 安装方便、配置简单; 使用多线程进行同步,能够保证多个服务器实时保持同步状态; 自带出错处理机制,通过失败队列对出错的文件重新出错,如果仍旧失败,则每10个小时对同步失败的文件重新同步; 自带crontab功能,只需在xml配置文件中开启,即可按您的要求,隔一段时间整体同步一次; 自带socket与http协议扩展,你可以方便的进行二次开发; rsync+sersync与rsync+Inotify-tools区别 Inotify-tools只能记录下被监听的目录发生了变化(包括增加、删除、修改),并没有把具体是哪个文件或者哪个目录发生了变化记录下来; rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),因此,效率很低。 sersync是基于Inotify开发的,类似于Inotify-tools的工具; sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字; rsync在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变化的数据相对整个同步目录数据来说是很小的,rsync在遍历查找比对文件时,速度很快),因此,效率很高。 所以,当同步的目录数据量不大时,建议使用Rsync+Inotify-tools;当数据量很大(几百G甚至1T以上)、文件很多时,建议使用Rsync+sersync。 地址:http://code.google.com/p/sersync/,要翻墙才能下载 http://download.csdn.net/detail/hellopengyl/9918625 安装、配置 和Inotify-tools一样,只需要在数据源端安装 1、查看服务器内核是否支持inotify [root@localhostsrc] #ll/proc/sys/fs/inotify#查看服务器内核是否支持inotify,出现下面的内容,说明服务器内核支持inotify total0 -rw-r--r--1rootroot0Jul2710:32max_queued_events -rw-r--r--1rootroot0Jul2710:32max_user_instances -rw-r--r--1rootroot0Jul2710:32max_user_watches [root@localhostsrc] #uname-r#Linux下支持inotify的内核最小为2.6.13 2.6.32-642.el6.x86_64 [root@localhostsrc] #sysctl-a|egrep-i"max_queued_events|max_user_watches|max_user_instances"#修改inotify默认参数(inotify默认内核参数值太小) fs.inotify.max_user_instances=128 fs.inotify.max_user_watches=8192 fs.inotify.max_queued_events=16384 fs.epoll.max_user_watches=201420 [root@localhostsrc] #vim/etc/sysctl.conf fs.inotify.max_user_instances=65535 fs.inotify.max_user_watches=99999999 fs.inotify.max_queued_events=99999999 [root@localhostsrc] #cat/proc/sys/fs/inotify/{max_user_instances,max_user_watches,max_queued_events} 65535 99999999 99999999 [root@localhostsrc] # max_queued_events inotify队列最大长度,如果值太小,会出现"** Event Queue Overflow **"错误,导致监控文件不准确 max_user_watches 要同步的文件包含多少目录,可以用:find /home/www.osyunwei.com -type d | wc -l统计,必须保证max_user_watches值大于统计结果(这里/home/www.osyunwei.com为同步文件目录) max_user_instances 每个用户创建inotify实例最大值 2、安装、配置sersync [root@localhostsrc] #tarzxvfsersync2.5.4_64bit_binary_stable_final.tar.gz [root@localhostsrc] #mvGNU-Linux-x86/app/sersync [root@localhostsrc] #cd/app/sersync/ [root@localhostsersync] #ls confxml.xmlsersync2 [root@localhostsersync] #cpconfxml.xml{,.default} [root@localhostsersync] #vimconfxml.xml <?xmlversion= "1.0" encoding= "ISO-8859-1" ?> < head version= "2.5" > <hosthostip= "localhost" port= "8008" >< /host > #针对插件的保留字段,保留默认即可。 <debugstart= "true" /> #在sersync正在运行的控制台,打印inotify,rsync同步命令 <fileSystemxfs= "false" /> #对于xfs文件系统用户,需要将这个选项开启才正常工作 <filterstart= "false" > #过滤系统的临时文件,被过滤的文件不会被监控提高,默认过滤系统的临时文件(以“.”开头,以“~”结尾) <excludeexpression= "(.*)\.svn" >< /exclude > <excludeexpression= "(.*)\.gz" >< /exclude > <excludeexpression= "^info/*" >< /exclude > <excludeexpression= "^static/*" >< /exclude > < /filter > <inotify> #inotify监控文件模块 <deletestart= "true" /> #如果本地文件删除,不需要删除远程段的文件可以设置成false <createFolderstart= "true" /> #如果将createFolder设为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控; <createFilestart= "false" /> #把createFile(监控文件事件选项)设置为false来提高性能,减少rsync通讯;因为拷贝文件到监控目录会产生create事件与close_write事件,所以如果关闭create事件,只监控文件拷贝结束时的时间close_write,同样可以实现文件完整同步; <closeWritestart= "true" /> <moveFromstart= "true" /> <moveTostart= "true" /> <attribstart= "false" /> <modifystart= "false" /> < /inotify > <sersync> #进行数据同步的模块 <localpath watch = "/app/rsync_client" > #定义本地要同步的目录 <remoteip= "10.15.43.100" name= "app_rsync_server" /> #远程接受同步的IP和rsync模块名 <!--<remoteip= "192.168.8.39" name= "tongbu" />--> <!--<remoteip= "192.168.8.40" name= "tongbu" />--> < /localpath > < rsync > <commonParamsparams= "-artuz" /> #自定义rsync参数,默认是-artuz <authstart= "true" users = "rsync" passwordfile= "/etc/rsyncd.secret" /> #开启用户认证,定义用户名密码 <userDefinedPortstart= "false" port= "874" /><!--port=874--> <timeoutstart= "false" time = "100" /><!--timeout=100--> < ssh start= "false" /> #开启会使用rsync-essh的方式进行传输 < /rsync > <failLogpath= "/tmp/rsync_fail_log.sh" timeToExecute= "60" /><!--defaultevery60minsexecuteonce--> #对于失败的传输,会进行重新传送,再次同步失败后日志记录到/tmp/rsync_fail_log.sh,并且每60分钟对失败的log进行重新同步 < crontab start= "true" schedule= "600" ><!--600mins--> #每隔600s会做一次完全同步 <crontabfilterstart= "false" >#如果开启了filter文件过滤功能,那么 crontab 整体同步也需要设置过滤,否则虽然实时同步的时候文件被过滤了,但 crontab 整体同步的时候如果不单独设置crontabfilter,还会将需过滤的文件同步到远程, <excludeexpression= "*.php" >< /exclude > # crontab 的过滤正则与filter过滤的不同,果同时开启了filter与 crontab ,则要开启 crontab 的crontabfilter,并按示例设置使其与filter的过滤一一对应。 <excludeexpression= "info/*" >< /exclude > < /crontabfilter > < /crontab > <pluginstart= "false" name= "command" />#当设置为 true 的时候,将文件同步到远程服务器后会调用name参数指定的插件。 < /sersync > <pluginname= "command" > #name指定的插件 #当文件同步完成后,会调用command插件,例如同步文件是file.txt,file.txt文件在改动之后,调用rsync同步到远程服务器后,调用command插件,执行/bin/shfile.txtsuffix>/dev/null2>&1 #如果suffix设置了,则会放在inotify事件file.txt之后,如果ignoreError为true,则会添加>/dev/null2>&1 <paramprefix= "/bin/sh" suffix= "" ignoreError= "true" /> <!--prefix /opt/tongbu/mmm .shsuffix--> <filterstart= "false" > <includeexpression= "(.*)\.php" /> #当filter为ture,include可以只对正则匹配到的文件,调用command。 <includeexpression= "(.*)\.sh" /> < /filter > < /plugin > #http插件,可以向指定域名的主机post,inotify监控的事件。 #socket插件,开启该模块,则向指定ip与端口发送inotify所产生的文件路径信息 <pluginname= "socket" > <localpath watch = "/opt/tongbu" > <deshostip= "192.168.138.20" port= "8009" /> < /localpath > < /plugin > #在同步过程中将文件发送到目的服务器后刷新cdn接口。如果不想使用,则设置<pluginstart="false"name="refreshCDN"/> #该模块根据chinaCDN的协议,进行设计,当有文件产生的时候,就向cdn接口发送需要刷新的路径位置 <pluginname= "refreshCDN" > <localpath watch = "/data0/htdocs/cms.xoyo.com/site/" > #需要监控的目录 #cdnifo标签制定了cdn接口的域名,端口号,以及用户名与密码。 <cdninfodomainname= "ccms.chinacache.com" port= "80" username= "xxxx" passwd = "xxxx" /> #sendurl标签是需要刷新的url的前缀 <sendurlbase=" #regexurl标签中的,regex属性为true时候,使用match属性的正则语句匹配inotify返回的路径信息,并将正则匹配到的部分作为url一部分, <regexurlregex= "false" match= "cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images" /> #如果产生文件事件为:/data0/htdoc/cms.xoyo.com/site/jx3.xoyo.com/image/a/123.txt #经过上面的match正则匹配后,最后刷新的路径是:http://pic.xoyo.com/cms/jx3/a/123.txt; #如果regex属性为false,最后刷新的路径是http://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt; < /localpath > < /plugin > < /head > [root@localhostsersync] #/app/sersync/sersync2-d-r-n8-o/app/sersync/confxml.xml set thesystemparam execute: echo 50000000> /proc/sys/fs/inotify/max_user_watches execute: echo 327679> /proc/sys/fs/inotify/max_queued_events parsethe command param option:-d runasadaemon option:-r rsync allthe local filestotheremoteserversbeforethesersyncwork option:-n threadnumis:8 option:-o configxmlname: /app/sersync/confxml .xml parsexmlconfig file hostip:localhost hostport:8008 Opendebug,youwillseedebuginfomation daemonstart,sersyncrunbehindtheconsole Startthe crontab Every600minutes rsync allthefilestotheremoteserversentirely use rsync password- file : useris rsync passwordfileis /etc/rsyncd .secret configxmlparsesuccess please set /etc/rsyncd .confmaxconnections=0Manually sersyncworkingthread10=1(primarythread)+1(failretrythread)+8(daemonsubthreads) Maxthreadsnumbersis:18=10(Threadpoolnums)+8(Subthreads) pleaseaccordingyourcpu,use-nparamtoadjustthecpurate ------------------------------------------ rsync thedirectoryrecursivlytotheremoteserversonce workingpleasewait... execute command : cd /app/rsync_client && rsync -artuz-R--delete./ rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret crontab command : cd /app/rsync_client && rsync -artuz-R--delete./ rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret runthesersync: watch pathis: /app/rsync_client add watch : /app/rsync_client return wdis:1 add watch : /app/rsync_client/test return wdis:2 [root@localhostsersync] # -d 后台启动 -r同步前将已存在的文件全部同步过去,如果设置了过滤器,即在xml文件中,filter为true,则暂时不能使用-r参数进行整体同步; -n开启的线程总数默认10 -o指定配置文件,指定 -o 参数可以指定多个不同的配置文件,从而实现sersync多进程多实例的数据同步 -m不进行同步,只运行插件 ./sersync -m pluginName 例如:./sersync -m command,则在监控到事件后,不对远程目标服务器进行同步,而是直接运行command插件 [root@localhostsersync] #catmonitor_sersync.sh#监控Sersync运行状态的脚本,如果服务停止了就重启服务 #!/bin/bash server_file= "/app/sersync/sersync2" conf_file= "/app/sersync/confxml.xml" options= "-d-r-n8-o" proc_num=$( ps -ef| grep -isersync2| grep - v "grep" | wc -l) if [$proc_num-lt1]; then cd $( dirname $server_file) nohup $server_file$options$conf_file& else exit 0; fi [root@localhostsersync] #chmod+xmonitor_sersync.sh [root@localhostsersync] #crontab-l * /5 **** /app/sersync/monitor_sersync .sh [root@localhostsersync] #/etc/init.d/crondrestart [root@localhostsersync] #vim/etc/rc.d/rc.local#设置开机自动运行脚本 /app/sersync/sersync2 -d-r-n8-o /app/sersync/confxml .xml [root@localhostsersync] # 测试 在客户端监控的目录/app/rsync_client创建文件,然后查看服务器端app_rsync_server模块对应的目录是否同步更新 [root@localhostrsync_client] #touchfile{1..9} inotifywd:1 name:file1 mask:256 inotifywd:1 name:file1 mask:8 inotifywd:1 name:file2 mask:256 inotifywd:1 name:file2 mask:8 inotifywd:1 name:file3 mask:256 inotifywd:1 name:file3 mask:8 inotifywd:1 name:file4 mask:256 inotifywd:1 name:file4 mask:8 inotifywd:1 name:file5 mask:256 [root@localhostrsync_client] #cd/app/rsync_client&&rsync-artuz-R"./file2"rsync@10.15.43.100::app_rsync_server--password-file=/etc/rsyncd.secret inotifywd:1 name:file5 mask:8 inotifywd:1 name:file6 mask:256 inotifywd:1 name:file6 mask:8 inotifywd:1 name:file7 mask:256 inotifywd:1 name:file7 mask:8 inotifywd:1 name:file8 mask:256 inotifywd:1 name:file8 mask:8 inotifywd:1 name:file9 mask:256 inotifywd:1 name:file9 mask:8 cd /app/rsync_client && rsync -artuz-R "./file1" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file3" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file4" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file5" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file6" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file7" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file8" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret cd /app/rsync_client && rsync -artuz-R "./file9" rsync @10.15.43.100::app_rsync_server--password- file = /etc/rsyncd .secret [root@localhostrsync_client] #touchfile1 inotifywd:1 name:file1 mask:8 [root@localhostrsync_client] #cd/app/rsync_client&&rsync-artuz-R"./file1"rsync@10.15.43.100::app_rsync_server--password-file=/etc/rsyncd.secret [root@localhostsersync] # 压测 写入10K个文件批量同步测试结果: [root@localhostrsync_client] #fornin{1..10000};doddif=/dev/zeroof=/app/rsync_client/"$n".txtbs=1Mcount=5;done 查看同步速度,当10K个文件同步完后,在/app/rsync_server里发现才同步了600多个文件 多实例情况 配置多个confxml.xml文件(比如:www、bbs、blog....等等),根据不同的需求同步对应的实例文件 [root@localhostrsync_client] #/app/sersync/sersync2-d-r-n8-o/app/sersync/www_confxml.xml [root@localhostrsync_client] #/app/sersync/sersync2-d-r-n8-o/app/sersync/bbs_confxml.xml [root@localhostrsync_client] #/app/sersync/sersync2-d-r-n8-o/app/sersync/blog_confxml.xml

优秀的个人博客,低调大师

centos6.5下安装配置ELK及收集nginx日志

Elasticsearch 是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash 是一个完全开源的工具,他可以对你的日志进行收集、分析,并将其存储供以后使用(如,搜索) kibana 也是一个开源和免费的工具,他Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 环境:192.168.50.119:ELK+Nginx 192.168.50.120:Redis+Logstash 架构图 部署流程: 192.168.50.119 ELK服务器 1.安装JDK Logstash的运行依赖于Java运行环境, Logstash 1.5以上版本不低于java 7推荐使用最新版本的Java,我这里使用了1.8版本 1 2 3 4 5 6 tar -zxfjdk-8u45-linux-x64. tar .gz-C /usr/local/ vim /etc/profile #设置环境变量 export JAVA_HOME= /usr/local/jdk1 .8.0_45 export PATH=$PATH:$JAVA_HOME /bin export CLASSPATH=.:$JAVA_HOME /lib/tools .jar:$JAVA_HOME /lib/dt .jar:$CLASSPATH source /etc/profile #使环境变量生效 验证是否安装成功 1 2 3 4 [root@localhost~] #java-version javaversion "1.8.0_45" Java(TM)SERuntimeEnvironment(build1.8.0_45-b14) JavaHotSpot(TM)64-BitServerVM(build25.45-b02,mixedmode) 2.安装Logstash(日志收集、分析,并将其存储供以后使用) 1 2 wgethttps: //download .elastic.co /logstash/logstash/logstash-2 .4.0. tar .gz tar –zxflogstash-2.4.0. tar .gz-C /usr/local/ 验证logstash是否安装成功 1 2 3 4 5 [root@localhost~] #/usr/local/logstash-2.4.0/bin/logstash-e'input{stdin{}}output{stdout{}}' Settings:Defaultpipelineworkers:1 Logstashstartupcompleted 等待输入:helloworld 2016-11-28T20:32:07.853Zlocalhost.localdomainhelloworld 我们可以看到,我们输入什么内容logstash按照某种格式输出,其中-e参数参数允许Logstash直接通过命令行接受设置。 这点尤其快速的帮助我们反复的测试配置是否正确而不用写配置文件。使用CTRL-C命令可以退出之前运行的Logstash。 3.部署nginx并收集日志 1 2 3 4 5 6 yum-y install nginx 设置nginx的log格式 vim /etc/nginx/nginx .conf log_formatmain '$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent"$http_x_forwarded_for$request_length$msec$connection_requests$request_time' ; 启动nginx 1 servicenginxstart 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 mkdir /usr/local/logstash-2 .4.0 /conf/ #创建logstash配置目录 定义logstash配置文件,用来收集nginx日志 [root@localhostconf] #catlogstash_nginx.conf input{ file { path=>[ "/var/log/nginx/access.log" ] type => "nginx_log" } } output{ redis{ host=> "192.168.50.120" key=> 'logstash-redis' data_type=> 'list' } stdout{ codec=>rubydebug } } 4.安装部署redis 192.168.50.120 服务器 1 2 3 yum-y install redis vim /etc/redis .conf bind192.168.50.120 启动 1 serviceredisstart 5.启动Logstash 1 2 [root@localhostconf] #/usr/local/logstash-2.4.0/bin/logstash-f./logstash_nginx.conf--configtest#检查配置文件 ConfigurationOK 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 [root@localhostconf] #/usr/local/logstash-2.4.0/bin/logstashagent-f./logstash_nginx.conf#将日志信息输出到redis服务器 Settings:Defaultpipelineworkers:1 Logstashstartupcompleted { "message" => "192.168.50.114--[29/Nov/2016:00:58:43+0800]\"GET/HTTP/1.1\"3040\"-\"\"Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/54.0.2840.99Safari/537.36\"\"-\"" , "@version" => "1" , "@timestamp" => "2016-11-28T18:55:49.587Z" , "path" => "/var/log/nginx/access.log" , "host" => "localhost.localdomain" , "type" => "nginx_log" } { "message" => "192.168.50.114--[29/Nov/2016:00:58:43+0800]\"GET/nginx-logo.pngHTTP/1.1\"3040\"http://192.168.50.119/\"\"Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/54.0.2840.99Safari/537.36\"\"-\"" , "@version" => "1" , "@timestamp" => "2016-11-28T18:55:49.590Z" , "path" => "/var/log/nginx/access.log" , "host" => "localhost.localdomain" , "type" => "nginx_log" } { "message" => "192.168.50.114--[29/Nov/2016:00:58:43+0800]\"GET/poweredby.pngHTTP/1.1\"3040\"http://192.168.50.119/\"\"Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/54.0.2840.99Safari/537.36\"\"-\"" , "@version" => "1" , "@timestamp" => "2016-11-28T18:55:49.590Z" , "path" => "/var/log/nginx/access.log" , "host" => "localhost.localdomain" , "type" => "nginx_log" } 6.安装部署Elasticsearch 192.168.50.119 ELK服务器 创建安装用户 1 2 groupaddelk useradd es-gelk 1 2 3 4 tar -xfelasticsearch-2.2.0. tar .gz-C /usr/local/ vim /usr/local/elasticsearch-2 .2.0 /config/elasticsearch .yml network.host:192.168.50.119 #端口绑定ip地址 http.port:9200 启动 这里遇到一个坑:es用户默认是不能用root用户启动的。所以要切到普通用户启动 1 2 3 chown -Res.elk /usr/local/elasticsearch-2 .2.0 su -es nohup /usr/local/elasticsearch-2 .2.0 /bin/elasticsearch > /usr/local/elasticsearch-2 .2.0 /nohub & 1 2 [root@localhostELK] #netstat-tunpl|grep9200 tcp00::ffff:192.168.50.119:9200:::*LISTEN2183 /java 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@localhostELK] #curlhttp://192.168.50.119:9200#查看状态 { "name" : "BloodBrothers" , "cluster_name" : "elasticsearch" , "version" :{ "number" : "2.2.0" , "build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe" , "build_timestamp" : "2016-01-27T13:32:39Z" , "build_snapshot" : false , "lucene_version" : "5.4.1" }, "tagline" : "YouKnow,forSearch" } 安装kopf和head插件 1 2 3 4 5 6 7 8 [root@localhostconf] #cd/usr/local/elasticsearch-2.2.0/bin/ [root@localhostbin] #./plugininstalllmenezes/elasticsearch-kopf ->Installinglmenezes /elasticsearch-kopf ... Tryinghttps: //github .com /lmenezes/elasticsearch-kopf/archive/master .zip... Downloading............................................................DONE Verifyinghttps: //github .com /lmenezes/elasticsearch-kopf/archive/master .zipchecksums if available... NOTE:Unabletoverifychecksum for downloadedplugin(unableto find .sha1or.md5 file toverify) Installedkopfinto /usr/local/elasticsearch-2 .2.0 /plugins/kopf 1 2 3 4 5 6 [root@localhostbin] #./plugininstallmobz/elasticsearch-head ->Installingmobz /elasticsearch-head ... Tryinghttps: //github .com /mobz/elasticsearch-head/archive/master .zip... Downloading.........................................................DONE NOTE:Unabletoverifychecksum for downloadedplugin(unableto find .sha1or.md5 file toverify) Installed head into /usr/local/elasticsearch-2 .2.0 /plugins/head 7.安装kibana 192.168.50.119 ELK服务器 安装 1 2 [root@localhostELK] #tar-xfkibana-4.4.0-linux-x64.tar.gz-C/usr/local/ [root@localhostELK] #cd/usr/local/kibana-4.4.0-linux-x64/ 配置 1 2 3 4 [root@localhostkibana-4.4.0-linux-x64] #vimconfig/kibana.yml elasticsearch.url: "http://192.168.50.119:9200" server.port:5601 server.host: "0.0.0.0" 启动 1 [root@localhostkibana-4.4.0-linux-x64] #nohup/usr/local/kibana-4.4.0-linux-x64/bin/kibana>/usr/local/kibana-4.4.0-linux-x64/nohub.out& 1 2 [root@localhostELK] #netstat-tunpl|grep5601 tcp000.0.0.0:56010.0.0.0:* 浏览器访问http://192.168.50.119:5601/ 8.安装logstash-server服务器 192.168.50.120 服务器 安装jdk和logstash 1 2 3 4 5 6 tar -zxfjdk-8u45-linux-x64. tar .gz-C /usr/local/ vim /etc/profile #设置环境变量 export JAVA_HOME= /usr/local/jdk1 .8.0_45 export PATH=$PATH:$JAVA_HOME /bin export CLASSPATH=.:$JAVA_HOME /lib/tools .jar:$JAVA_HOME /lib/dt .jar:$CLASSPATH source /etc/profile #使环境变量生效 1 2 tar –zxflogstash-2.4.0. tar .gz-C /usr/local/ mkdir /usr/local/logstash-2 .4.0 /conf 将redis 中的数据发送到elasticsearch中 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@localhostconf] #catlogstash_server.conf input{ redis{ port=> "6379" host=> "192.168.50.120" data_type=> "list" key=> "logstash-redis" type => "redis-input" } } output{ elasticsearch{ hosts=> "192.168.50.119" index=> "logstash-%{+YYYY.MM.dd}" } } 9.在Kibanda上创建nginx日志监控视图 es常规操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 es健康状态 [root@localhost~] #curlhttp://192.168.50.119:9200/_cat/health?v epochtimestampclusterstatusnode.totalnode.datashardsprireloinitunassignpending_tasksmax_task_wait_timeactive_shards_percent 148034531523:01:55elasticsearchyellow11660060-50.0% health的状态包括:green,yellow,red. 列出节点 [root@localhost~] #curlhttp://192.168.50.119:9200/_cat/nodes?v hostipheap.percent ram .percentloadnode.rolemastername 192.168.50.119192.168.50.1198990.00d*BloodBrothers 列出索引 [root@localhost~] #curlhttp://192.168.50.119:9200/_cat/indices?v healthstatusindexprirepdocs.countdocs.deletedstore.sizepri.store.size yellow open .kibana11205.6kb5.6kb yellow open logstash-2016.11.2851104.9kb4.9kb 本文转自 shouhou2581314 51CTO博客,原文链接:http://blog.51cto.com/thedream/1878971,如需转载请自行联系原作者

优秀的个人博客,低调大师

CentOS下查找处理文件名后包含空格的文件

当Linux下文件名中出现空格这类特殊情况话,如何查找或确认那些文件名后有空格呢? 又怎么批量替换处理掉这些空格呢? 方法1: 输入文件名后使用Tab键,如果使用Tab键后面出现\ \ \这样的可见字符,那么该文件名包含空格。当然,这个方法弊端很大,例如,效率低下,不能批量查找,只有当你怀疑某个文件名后有空格,这个方法才比较凑效。另外,不能查找文件中间包含空格的文件名。如下测试所示: [root@DB-Server kerry]# cat >"test.txt " it is only for test! [1]+ Stopped cat > "test.txt " [root@DB-Server kerry]# cat >"tes t.txt" it is only for test too! [2]+ Stopped cat > "tes t.txt" [root@DB-Server kerry]# ls test.txt ls: test.txt: No such file or directory [root@DB-Server kerry]# ls test test~ test1.py test.py test.sh test.txt [root@DB-Server kerry]# ls test.txt\ \ \ \ test.txt [root@DB-Server kerry]# ls tes test~ test1.py test.py test.sh tes t.txt test.txt 方法2: 使用find命令查找文件名中包含空格的文件。 [root@DB-Server kerry]# find . -type f -name "* *" -print ./test.txt ./tes t.txt 那么如何将这些空格替换掉呢?下面脚本可以替换文件中间的空格,用下划线替换空格,但是只能替换文件中间的空格,并不能替换文件名后面的空格。如下测试所示: find . -type f -name "* *" -print | while read name; do na=$(echo $name | tr ' ''_') if [[ $name != $na ]]; then mv "$name""$na" fi done 上面脚本只能将文件名中间有空格的替换为下划线。那么如何解决文件名后有空格的情况呢? 可以用其它shell脚本实现,如下所示: [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"test.txt " 12 [root@DB-Server kerry]# cat >"tes t.txt" 12 [root@DB-Server kerry]# find . -type f -name "* *" -print ./test.txt ./tes t.txt [root@DB-Server kerry]# for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done [root@DB-Server kerry]# find . -type f -name "* *" -print [root@DB-Server kerry]# ls -lrt total 8 -rw-r--r-- 1 root root 0 Nov 13 10:04 test.txt -rw-r--r-- 1 root root 0 Nov 13 10:04 tes_t.txt 如上所示,虽然文件名中间的空格被替换为了下划线,但是后面的空格没有替换为下划线,而是将那些空格直接截断了。Why?下面使用sed命令也是如此 [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"test.txt " 12 [root@DB-Server kerry]# cat >"tes t.txt" 12 [root@DB-Server kerry]# find . -type f -name "* *" -print ./test.txt ./tes t.txt [root@DB-Server kerry]# for i in *' '*; do mv "$i" `echo $i | sed -e 's/ /_/g'`; done [root@DB-Server kerry]# find . -type f -name "* *" -print [root@DB-Server kerry]# ls -lrt total 8 -rw-r--r-- 1 root root 0 Nov 13 09:29 test.txt -rw-r--r-- 1 root root 0 Nov 13 09:29 tes_t.txt [root@DB-Server kerry]# [root@DB-Server kerry]# 其实,这个是因为读取文件名是$file 与"$file"是不同的,$file不会识别文件名后面的空格,而"$file"才会失败文件名后面的空格。所以上面脚本其实只是取巧而已。 [root@DB-Server kerry]# rm -rf *; [root@DB-Server kerry]# cat >"test.txt " 123 [root@DB-Server kerry]# for file in *; do echo "$file"; echo "$file" | wc -m ; done; test.txt 13 [root@DB-Server kerry]# for file in *; do echo $file; echo $file | wc -m ; done; test.txt 9 [root@DB-Server kerry]# 所以,正确的替换空格的命令应该为如下: 方案1: [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"test.txt " 123456 [root@DB-Server kerry]# find . -type f -name "* *" -print ./test.txt [root@DB-Server kerry]# for file in *; do mv "$file" `echo "$file" | tr ' ' '\n'` ; done [root@DB-Server kerry]# find . -type f -name "* *" -print [root@DB-Server kerry]# ls test.txt test.txt [root@DB-Server kerry]# 方案2: [root@DB-Server kerry]# [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"test.txt " 123456 [root@DB-Server kerry]# for file in *' '*; do mv "$file" `echo "$file" | sed -e 's/ /n/g'`; done [root@DB-Server kerry]# find . -type f -name "* *" -print 但是对于文件名中间包含空格的情况,上面两个脚本都无法完美解决。如下所示: [root@DB-Server kerry]# [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"tes t.txt" 123456 [root@DB-Server kerry]# for file in *; do mv "$file" `echo "$file" | tr ' ' '_'` ; done [root@DB-Server kerry]# find . -type f -name "* *" -print [root@DB-Server kerry]# ls -lrt total 8 -rw-r--r-- 1 root root 7 Nov 13 16:00 tes_t.txt [root@DB-Server kerry]# [root@DB-Server kerry]# rm -rf * [root@DB-Server kerry]# cat >"tes t.txt" 123456 [root@DB-Server kerry]# cat >"test.txt " 654321 [root@DB-Server kerry]# find . -type f -name "* *" -print ./test.txt ./tes t.txt [root@DB-Server kerry]# for file in *; do mv "$file" `echo "$file" | tr ' ' '_'` ; done [root@DB-Server kerry]# find . -type f -name "* *" -print [root@DB-Server kerry]# ls -lrt total 12 -rw-r--r-- 1 root root 0 Nov 13 15:59 tes_t.txt -rw-r--r-- 1 root root 7 Nov 13 15:59 test.txt____ 当然对于这两种特殊情况,上面脚本都不能一起处理,如上所示,后面的空格会被替换成了下划线。这反而不是我们想要的,反而最上面的那两种脚本,可以误打误撞的解决这两种问题。当然让前提是你得知其然知其所以然!

优秀的个人博客,低调大师

阿里云服务器CentOS 7.3 64位部署FTP服务

一、安装vsftpd yum -y install vsftpd 二、配置 vsftpd的配置文件在/etc/vsftpd,其中vsftp.conf文件是住配置文件,打开如下: # Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). # 匿名访问,NO关闭,默认为YES开启状态 anonymous_enable=NO # # Uncomment this to allow local users to log in. # When SELinux is enforcing check for SE bool ftp_home_dir local_enable=YES # # Uncomment this to enable any form of FTP write command. write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access #anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. #anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # Activate logging of uploads/downloads. xferlog_enable=YES # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever # # You may override where the log file goes if you like. The default is shown # below. #xferlog_file=/var/log/xferlog # # If you want, you can have your log file in standard ftpd xferlog format. # Note that the default log file location is /var/log/xferlog in this case. xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. #nopriv_user=ftpsecure # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. # Beware that on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES # (default follows) #banned_email_file=/etc/vsftpd/banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that # the user does not have write access to the top level directory within the # chroot) #chroot_local_user=YES #chroot_list_enable=YES # (default follows) #chroot_list_file=/etc/vsftpd/chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES # # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=NO # # This directive enables listening on IPv6 sockets. By default, listening # on the IPv6 "any" address (::) will accept connections from both IPv6 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 # sockets. If you want that (perhaps because you want to listen on specific # addresses) then you must run two copies of vsftpd with two configuration # files. # Make sure, that one of the listen options is commented !! listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES # FTP跟路径设置 local_root=/home 理论上什么都不用修改就可以,但是实际上,我们都会把匿名访问给关闭,和设置一个FTP根路径 anonymous_enable=NO YES改为NO 添加local_root=/home 等号后面为想要设置的文件路径 三、添加用户 useradd ftpadmin -s /sbin/nologin // ftpadmin可改为你的FTP账号 passwd ftpadmin // 设置密码,输入两遍,密码不可见 chown -R ftpadmin /var/ftp // 改动用户权限,格式为chown -R 用户名 文件路径 四、开启服务 service vsftpd start 附:这篇就先这样,以后再更新卸载,vsftpd主配置文件修改及介绍,黑白名单,制定用户配置权限等等

优秀的个人博客,低调大师

解决centos下非root用户频繁出现Authentication is required to set the ne

非root用户登陆linux服务器,总是弹出一个对话框,而且关闭之后,过一段时间还会弹出来。对话框的内容是:Authentication is required to set the network proxy used for downloading packages。然后提示你输入root密码。 解决办法:在终端窗口(右键,open in terminal)输入“gnome-session-properties”。然后把“PackageKit Update Applet”前面的勾去掉就行了。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册