首页 文章 精选 留言 我的

精选列表

搜索[基础搭建],共10017篇文章
优秀的个人博客,低调大师

MHA架构搭建

MHA工作原理总结如下: 1、配置文件检查阶段(整个集群的配置) 2、宕机奔溃的master保存二进制日志事件且摘除VIP操作 3、识别含有最新更新的slave 4、复制dead master和slave相差的中继日志,保存到mha manager具体的目录下面 5、提升一个slave为新的master 6、使其他的slave连接新的master进行复制 复制机制: 异步复制: MySQL默认是异步复制,MASTER将事件写入BINLOG,但并不知道SLAVE是否何时已经接收且处理,在异步复制的机制的情况下,如果MASTER宕机,事务在MASTER上已提交,但很可能这些事务没有传到任何的SLAVE上,此时SLAVE可能会丢失事务 同步复制: MASTER提交事务,直到事务在所有的SLAVE都已提交,此时才会返回客户端,事务执行完毕,完成一个事务可能会有很大的延迟。 半同步复制: 当SLAVE主机连接到MASTER时,能够查看其是否处于半同步复制的机制。当MASTER上开启半同步复制的功能时,至少应该有一个SLAVE开启其功能,此时,一个线程在MASTER上提交事务将受到阻塞,直到得知一个已开启半同步复制功能的SLAVE已收到此事务的所有事件,或等待超时,当一个事务都写入其relay-log中且已刷新到磁盘上,SLAVE才会告知已收到,如果等待超时,也就是MASTER没呗告知已收到,此时MASTER会自动转换为异步复制,当至少一个半同步的SLAVE赶上,MASTER与其SLAVE自动转换为半同步复制的机制 半同步复制工作机制处于同步和异步之间,MASTER的事务提交阻塞,只要一个SLAVE已收到该事务的事件且已记录,他不会等待所有的SLAVE都告知已收到,且他只是接收,并不用等其他执行且提交。 MHA的隐患: 在MHA自动故障切换的过程中,MHA试图从宕掉的主服务器上保存二进制日志,最大程度保证数据的不丢失,存在的问题是,如果主服务器硬件故障宕机或无法通过SSH访问,MHA没有办法保存二进制日志,只能进行故障转移而可能丢失最新数据。, MySQL服务挂了,可以从服务器拷贝二进制日志,若是硬件话,只能GG了,如果复制出现延迟,也只能GG了。 使用场景: MHA主要支持一主多从的架构,要求一个复制集群必须至少有3台数据库服务器。 简介:MasterHighAvailability 该软件由两部分组成:MHA Manager(管理节点)和MHA Node(数据节点) Manager工具包主要包括以下几个工具: masterha_check_ssh 检查MHA的SSH配置状况 masterha_check_repl 检查MySQL复制状况 masterha_manger 启动MHA masterha_check_status 检测当前MHA运行状态 masterha_master_monitor 检测master是否宕机 masterha_master_switch 控制故障转移(自动或者手动) masterha_conf_host 添加或删除配置的server信息 Node工具包 save_binary_logs 保存和复制master的二进制日志 apply_diff_relay_logs 识别差异的中继日志事件并将其差异的事件应用于其他的slave filter_mysqlbinlog去除不必要的ROLLBACK事件(MHA已不再使用这个工具) purge_relay_logs清除中继日志(不会阻塞SQL线程) ##关闭relay log自动清楚,set globalrelay_log_purge=0 MHA在发生切换的过程中,从库的恢复过程中依赖于RELAY LOG的相关信息,所以这里要将RELAYLOG的自动清楚设置为OFF,采用手动清楚的方式。 PURGE_RELAY_LOGS工具原理:它可以为中继日志创建硬链接,执行SET GOLBAL RELAY_LOG_PURGE=1,等待几秒钟以便SQL线程切换到新的中继日志,在执行RELAY_LOG_PURGE=0 Mha安装 1、在所有节点安装MHA node所需的perl模块(DBD:mysql) yum install perl-DBD-MySQL -y 2、在所有节点安装mha node tar -xvf mha4mysql-node-0.53.tar.gz cd mha4mysql-node-0.53 perl Makefile.PL make make install 安装后再/usr/local/bin下生成以下文件 ll /usr/local/bin/apply_diff_relay_logs/usr/local/bin/filter_mysqlbinlog /usr/local/bin/purge_relay_logs/usr/local/bin/save_binary_logs 3、安装MHA Manager 安装相关软件 yum -y install perl-DBD-MySQLperl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManagerperl-Config-IniFiles ncftp perl-Params-Validate perl-CPAN perl-Test-Mock-LWP.noarchperl-LWP-Authen-Negotiate.noarch perl-devel perl-ExtUtils-CBuilderperl-ExtUtils-MakeMaker cd mha4mysql-manager-0.53 perl Makefile.PL make make install 拷贝相关脚本到/usr/local/bin下 cd/usr/local/mha4mysql-manager-0.53/samples/scripts scp * /usr/local/bin master_ip_failover #自动切换时vip管理的脚本,不是必须,如果我们使用keepalived的,我们可以自己编写脚本完成对vip的管理,比如监控mysql,如果mysql异常,我们停止keepalived就行,这样vip就会自动漂移 master_ip_online_change #在线切换时vip的管理,不是必须,同样可以可以自行编写简单的shell完成 power_manager #故障发生后关闭主机的脚本,不是必须 send_report #因故障切换后发送报警的脚本,不是必须,可自行编写简单的shell完成。 4、配置SSH登录无密码验证 1)在每台发服务器上执行:ssh-keygen-t rsa ssh-copy-id -i.ssh/id_rsa.pub "root@192.168.28.87" ssh-copy-id -i.ssh/id_rsa.pub "root@192.168.28.70" ssh-copy-id -i .ssh/id_rsa.pub "root@192.168.28.71” 5、两台Slave服务设置read_only set global read_only=1; 6、relay_log脚本 #!/bin/bash user=root passwd=123456 port=3306 log_dir='/data/masterha/log' work_dir='/data' purge='/usr/local/bin/purge_relay_logs' if[!-d$log_dir]then mkdir$log_dir-p Fi $purge--user=$user--password=$passwd--disable_relay_log_purge--port=$port--workdir=$work_dir>>$log_dir/purge_relay_logs.log2>&1 设置定时任务 04***/bin/bash/root/purge_relay_log.sh 7、在master库创建监控用户 grant all privileges on *.* to 'root'@'192.168.1.%'identified by '125746'; flush privileges; 8、配置mha 1)创建MHA的工作目录,并且创建相关配置文件 mkdir -p /etc/masterha cd/usr/local/mha4mysql-manager-0.53/samples/conf cp app1.cnf /etc/masterha/ 2)修改配置文件 vi/etc/masterha/app1.cnf [server default] manager_workdir=/var/log/masterha manager_log=/var/log/masterha/app1/manager.log master_binlog_dir=/data/mysql master_ip_failover_script=/usr/local/bin/master_ip_failover master_ip_online_change_script=/usr/local/bin/master_ip_online_change password=125746 user=root ping_interval=1 remote_workdir=/tmp repl_password=123 repl_user=repl report_script=/usr/local/bin/send_report ssh_user=root [server1] hostname=192.168.1.120 candidate_master=1 port=3306 [server2] hostname=192.168.1.115 port=3306 candidate_master=1 [server3] hostname=192.168.1.118 port=3307 3)检查ssh设置 masterha_check_ssh--conf=/etc/masterha/app1.cnf ln-s /usr/lib/perl5/vendor_perl/MHA /usr/lib64/perl5/vendor_perl/ 4)检查主从复制 masterha_check_repl--conf=/etc/masterha/app1.cnf 5)安装keepalived tar xfkeepalived-1.2.12.tar.gz cd keepalived-1.2.12 ./configure--prefix=/usr/local/keepalived make&& make install cp/usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ cp/usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir/etc/keepalived cp/usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp/usr/local/keepalived/sbin/keepalived /usr/sbin/ 主库keepalived配置文件 vi/etc/keepalived/keepalived.conf global_defs { notification_email { lihong@bxjinrong.com } notification_email_fromAlexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id MySQL_HA } vrrp_instance VI_1{ state BACKUP interface eth0 virtual_router_id 51 nopreempt priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.20 } } 备用主库的keepalived配置文件 vi/etc/keepalived/keepalived.conf global_defs { notification_email { lihong@bxjinrong.com } notification_email_fromAlexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id MySQL_HA } vrrp_instance VI_1{ state BACKUP interface eth0 virtual_router_id 51 priority 120 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.20 } } 7)mhamanager管理 启动manager nohupmasterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf--ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log2>&1 & 关闭manager masterha_stop--conf=/etc/masterha/app1.cnf 查看manager的状态 masterha_check_status--conf=/etc/masterha/app1.cnf 切换 1启动manager后,master发生故障后会自动切换 2在线切换过程 masterha_stop--conf=/etc/masterha/app1.cnf masterha_master_switch--conf=/etc/masterha/app1.cnf --master_state=alive--new_master_host=192.168.1.120 --new_master_port=3306 --orig_master_is_new_slave--running_updates_limit=10000 相关脚本 1)master_ip_failover #!/usr/bin/envperl use strict; use warnings FATAL=> 'all'; use Getopt::Long; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host,$new_master_ip, $new_master_port ); my $vip= '192.168.1.120'; my$ssh_start_vip = "/etc/init.d/keepalived start"; my$ssh_stop_vip = "/etc/init.d/keepalived stop"; GetOptions( 'command=s' => \$command, 'ssh_user=s' => \$ssh_user, 'orig_master_host=s' =>\$orig_master_host, 'orig_master_ip=s' => \$orig_master_ip, 'orig_master_port=i' =>\$orig_master_port, 'new_master_host=s' => \$new_master_host, 'new_master_ip=s' =>\$new_master_ip, 'new_master_port=i' => \$new_master_port, ); exit &main(); sub main { print "\n\nIN SCRIPTTEST====$ssh_stop_vip==$ssh_start_vip===\n\n"; if ( $command eq "stop" ||$command eq "stopssh" ) { my $exit_code = 1; eval { print "Disabling the VIP onold master: $orig_master_host \n"; &stop_vip(); $exit_code = 0; }; if ($@) { warn "Got Error: $@\n"; exit $exit_code; } exit $exit_code; } elsif ( $command eq "start" ) { my $exit_code = 10; eval { print "Enabling the VIP - $vipon the new master - $new_master_host \n"; &start_vip(); $exit_code = 0; }; if ($@) { warn $@; exit $exit_code; } exit $exit_code; } elsif ( $command eq "status" ) { print "Checking the Status of thescript.. OK \n"; #`ssh $ssh_user\@cluster1 \"$ssh_start_vip \"`; exit 0; } else { &usage(); exit 1; } } # A simple systemcall that enable the VIP on the new master sub start_vip() { `ssh $ssh_user\@$new_master_host \"$ssh_start_vip \"`; } # A simple systemcall that disable the VIP on the old_master sub stop_vip() { return 0unless ($ssh_user); `ssh $ssh_user\@$orig_master_host \"$ssh_stop_vip \"`; } sub usage { print "Usage: master_ip_failover--command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip--orig_master_port=port --new_master_host=host --new_master_ip=ip--new_master_port=port\n"; } 2)master_ip_online_change #!/usr/bin/envperl # Copyright (C) 2011 DeNA Co.,Ltd. # # This program is free software; you canredistribute it and/or modify # it under the terms of the GNU General PublicLicense as published by # the Free Software Foundation; either version2 of the License, or # (at your option) any later version. # # This program is distributed in the hope thatit will be useful, # but WITHOUT ANY WARRANTY; without even theimplied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNUGeneral Public License # along with this program; if not, write tothe Free Software # Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston,MA 02110-1301 USA ## Note: This is asample script and is not complete. Modify the script based on your environment. use strict; use warnings FATAL=> 'all'; use Getopt::Long; use MHA::DBHelper; use MHA::NodeUtil; use Time::HiResqw( sleep gettimeofday tv_interval ); use Data::Dumper; my $ssh_user ="root"; my $vip ='192.168.1.20'; my $ssh_start_vip= "/etc/init.d/keepalived start"; my $ssh_stop_vip ="/etc/init.d/keepalived stop"; my $_tstart; my$_running_interval = 0.1; my ( $command, $orig_master_host, $orig_master_ip, $orig_master_port, $orig_master_user,$orig_master_password, $new_master_host, $new_master_ip, $new_master_port, $new_master_user, $new_master_password ); GetOptions( 'command=s' => \$command, 'orig_master_host=s' => \$orig_master_host, 'orig_master_ip=s' => \$orig_master_ip, 'orig_master_port=i' => \$orig_master_port, 'orig_master_user=s' => \$orig_master_user, 'orig_master_password=s' =>\$orig_master_password, 'new_master_host=s' => \$new_master_host, 'new_master_ip=s' => \$new_master_ip, 'new_master_port=i' => \$new_master_port, 'new_master_user=s' => \$new_master_user, 'new_master_password=s' => \$new_master_password, ); exit &main(); subcurrent_time_us { my ( $sec, $microsec ) = gettimeofday(); my $curdate = localtime($sec); return $curdate . " " . sprintf("%06d", $microsec ); } sub sleep_until { my $elapsed = tv_interval($_tstart); if ( $_running_interval > $elapsed ) { sleep( $_running_interval - $elapsed ); } } subget_threads_util { my $dbh = shift; my $my_connection_id = shift; my $running_time_threshold = shift; my $type = shift; $running_time_threshold = 0 unless($running_time_threshold); $type = 0 unless ($type); my @threads; my $sth = $dbh->prepare("SHOWPROCESSLIST"); $sth->execute(); while ( my $ref = $sth->fetchrow_hashref()) { my $id = $ref->{Id}; my $user = $ref->{User}; my $host = $ref->{Host}; my $command = $ref->{Command}; my$state = $ref->{State}; my $query_time = $ref->{Time}; my $info = $ref->{Info}; $info =~ s/^\s*(.*?)\s*$/$1/ ifdefined($info); next if ( $my_connection_id == $id ); next if ( defined($query_time) &&$query_time < $running_time_threshold ); next if ( defined($command) && $command eq "BinlogDump" ); next if ( defined($user) && $user eq "systemuser" ); next if ( defined($command) && $command eq "Sleep" && defined($query_time) && $query_time >= 1 ); if ( $type >= 1 ) { next if ( defined($command) &&$command eq "Sleep" ); next if ( defined($command) &&$command eq "Connect" ); } if ( $type >= 2 ) { next if ( defined($info) && $info=~ m/^select/i ); next if ( defined($info) && $info=~ m/^show/i ); } push @threads, $ref; } return @threads; } sub main { if ( $command eq "stop" ) { ## Gracefully killing connections on thecurrent master # 1. Set read_only= 1 on the new master # 2. DROP USER so that no app user canestablish new connections # 3. Set read_only= 1 on the current master # 4. Kill current queries # * Any database access failure will resultin script die. my $exit_code = 1; eval { ## Setting read_only=1 on the new master(to avoid accident) my $new_master_handler = newMHA::DBHelper(); # args: hostname, port, user, password,raise_error(die_on_error)_or_not $new_master_handler->connect($new_master_ip, $new_master_port, $new_master_user, $new_master_password,1 ); print current_time_us() . " Setread_only on the new master.. "; $new_master_handler->enable_read_only(); if ($new_master_handler->is_read_only() ) { print "ok.\n"; } else { die "Failed!\n"; } $new_master_handler->disconnect(); # Connecting to the orig master, die ifany database error happens my $orig_master_handler = newMHA::DBHelper(); $orig_master_handler->connect($orig_master_ip, $orig_master_port, $orig_master_user,$orig_master_password, 1 ); ## Drop application user so that nobodycan connect. Disabling per-session binlog beforehand $orig_master_handler->disable_log_bin_local(); print current_time_us() . " Drppingapp user on the orig master..\n"; #FIXME_xxx_drop_app_user($orig_master_handler); ## Waiting for N * 100 milliseconds sothat current connections can exit my $time_until_read_only = 15; $_tstart = [gettimeofday]; my @threads = get_threads_util($orig_master_handler->{dbh}, $orig_master_handler->{connection_id} ); while ( $time_until_read_only > 0&& $#threads >= 0 ) { if ( $time_until_read_only % 5 == 0 ) { printf "%s Waitingall running %d threads are disconnected.. (max %d milliseconds)\n", current_time_us(), $#threads + 1,$time_until_read_only * 100; if ( $#threads < 5 ) { print Data::Dumper->new( [$_])->Indent(0)->Terse(1)->Dump . "\n" foreach (@threads); } } sleep_until(); $_tstart = [gettimeofday]; $time_until_read_only--; @threads = get_threads_util($orig_master_handler->{dbh}, $orig_master_handler->{connection_id}); } ## Setting read_only=1 on the currentmaster so that nobody(except SUPER) can write print current_time_us() . " Setread_only=1 on the orig master.. "; $orig_master_handler->enable_read_only(); if ( $orig_master_handler->is_read_only()) { print "ok.\n"; } else { die "Failed!\n"; } ## Waiting for M * 100 milliseconds sothat current update queries can complete my $time_until_kill_threads = 5; @threads = get_threads_util($orig_master_handler->{dbh}, $orig_master_handler->{connection_id} ); while ( $time_until_kill_threads > 0&& $#threads >= 0 ) { if ( $time_until_kill_threads % 5 == 0) { printf "%s Waitingall running %d queries are disconnected.. (max %d milliseconds)\n", current_time_us(), $#threads + 1,$time_until_kill_threads * 100; if ( $#threads < 5 ) { print Data::Dumper->new( [$_])->Indent(0)->Terse(1)->Dump . "\n" foreach (@threads); } } sleep_until(); $_tstart = [gettimeofday]; $time_until_kill_threads--; @threads = get_threads_util($orig_master_handler->{dbh}, $orig_master_handler->{connection_id} ); } print "Disabling the VIP on oldmaster: $orig_master_host \n"; &stop_vip(); ## Terminating all threads print current_time_us() . " Killingall application threads..\n"; $orig_master_handler->kill_threads(@threads) if ( $#threads >= 0); print current_time_us() . "done.\n"; $orig_master_handler->enable_log_bin_local(); $orig_master_handler->disconnect(); ## After finishing the script, MHAexecutes FLUSH TABLES WITH READ LOCK $exit_code = 0; }; if ($@) { warn "Got Error: $@\n"; exit $exit_code; } exit $exit_code; } elsif ( $command eq "start" ) { ## Activating master ip on the new master # 1. Create app user with write privileges # 2. Moving backup script if needed # 3. Register new master's ip to thecatalog database # We don't returnerror even though activating updatable accounts/ip failed so that we don'tinterrupt slaves' recovery. # If exit code is0 or 10, MHA does not abort my $exit_code = 10; eval { my $new_master_handler = newMHA::DBHelper(); # args: hostname, port, user, password,raise_error_or_not $new_master_handler->connect($new_master_ip, $new_master_port, $new_master_user, $new_master_password,1 ); ## Set read_only=0 on the new master $new_master_handler->disable_log_bin_local(); print current_time_us() . " Setread_only=0 on the new master.\n"; $new_master_handler->disable_read_only(); ## Creating an app user on the new master print current_time_us() . " Creatingapp user on the new master..\n"; FIXME_xxx_create_app_user($new_master_handler); $new_master_handler->enable_log_bin_local(); $new_master_handler->disconnect(); ## Update master ip on the catalogdatabase, etc print "Enabling the VIP - $vip onthe new master - $new_master_host \n"; &start_vip(); $exit_code = 0; }; if ($@) { warn "Got Error: $@\n"; exit $exit_code; } exit $exit_code; } elsif ( $command eq "status" ) { # do nothing exit 0; } else { &usage(); exit 1; } } # A simple systemcall that enable the VIP on the new master sub start_vip() { `ssh $ssh_user\@$new_master_host \"$ssh_start_vip \"`; } # A simple systemcall that disable the VIP on the old_master sub stop_vip() { `ssh $ssh_user\@$orig_master_host \"$ssh_stop_vip \"`; } sub usage { print "Usage:master_ip_online_change --command=start|stop|status --orig_master_host=host--orig_master_ip=ip --orig_master_port=port --new_master_host=host--new_master_ip=ip --new_master_port=port\n"; die; } MHA测试: MHA的三种工作情况: 一、自动Failover 必须启动mha Manager监控,否则无法自动切换,切换包括以下步骤: 1、配置文件检查阶段(包括整个集群的配置文件) 2、宕机的MASTER处理,这个阶段包括虚拟IP摘除操作, 3、复制DEAD MASTER和最新SLAVE相差的RELAY LOG,并保存MHA MANAGER具体的目录下 4、识别含有最新更新的SLAVE 5、应用从MASTER保存的二进制日志事件 6、提升一个SLAVE为新的MASTER进行复制 7、使其他的SLAVE连接新的MASTER进行复制 ###在自动切换之后监控就停止了 二、手动切换 1、不需要开启mha manager监控 2、如果MHA MANAGER检测到没有DEAD的SERVER将报错,并结束FAILOVER,所以手动切换必须在主MYSQL宕掉才可以 三、在线进行切换 1、检测复制设置和确定当前主服务器 2、确定新的主服务器 3、阻塞写入到当前主服务器 4、等待所有从服务器赶上复制 5、授予写入到新的主服务器 6、重新设置从服务器 #1、自动识别MASTER和SLAVE问题,VIP的移动 3、负载均衡问题,当有机器离开集群时,负载比例 四、切换满足条件 1、所有SLAVE的IO、SQL线程都在运行 2、所有的SHOW SLAVE STATUS的输出中SECONDS_BEHIND_MASTER参数小于或等于running_updates_limit秒,如果在切换过程中不指定,默认为1秒 3、在MASTER端,通过SHOW PROCESSLIST输出,没有一个更新花费的时间大于RUNNING ##在线切换需要调用master_ip_online_change这个脚本,貌似这个脚本不够完善,,需要自己修改 软件包下载: http://down.51cto.com/data/2258543 http://down.51cto.com/data/2258544 本文转自 DBAspace 51CTO博客,原文链接:http://blog.51cto.com/dbaspace/1898371

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

hadoop集群搭建

1.准备Linux环境 1.0先将虚拟机的网络模式选为NAT 1.1修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=itcast ### 1.2修改IP 两种方式: 第一种:通过Linux图形界面进行修改(强烈推荐) 进入Linux图形界面 -> 右键点击右上方的两个小电脑 -> 点击Edit connections -> 选中当前网络System eth0 -> 点击edit按钮 -> 选择IPv4 -> method选择为manual -> 点击add按钮 -> 添加IP:192.168.1.101 子网掩码:255.255.255.0 网关:192.168.1.1 -> apply 第二种:修改配置文件方式(屌丝程序猿专用) vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="static" ### HWADDR="00:0C:29:3C:BF:E7" IPV6INIT="yes" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="ce22eeca-ecde-4536-8cc2-ef0dc36d4a8c" IPADDR="192.168.1.101" ### NETMASK="255.255.255.0" ### GATEWAY="192.168.1.1" ### 1.3修改主机名和IP的映射关系 vim /etc/hosts 192.168.1.101itcast 1.4关闭防火墙 #查看防火墙状态 service iptables status #关闭防火墙 service iptables stop #查看防火墙开机启动状态 chkconfig iptables --list #关闭防火墙开机启动 chkconfig iptables off 1.5 修改sudo su root vim /etc/sudoers 给hadoop用户添加执行的权限 关闭linux服务器的图形界面: vi /etc/inittab 1.5重启Linux reboot 2.安装JDK 2.1上传alt+p 后出现sftp窗口,然后put d:\xxx\yy\ll\jdk-7u_65-i585.tar.gz 2.2解压jdk #创建文件夹 mkdir /home/hadoop/app #解压 tar -zxvf jdk-7u55-linux-i586.tar.gz -C /home/hadoop/app 2.3将java添加到环境变量中 vim /etc/profile #在文件最后添加 export JAVA_HOME=/home/hadoop/app/jdk-7u_65-i585 export PATH=$PATH:$JAVA_HOME/bin #刷新配置 source /etc/profile 3.安装hadoop2.4.1 先上传hadoop的安装包到服务器上去/home/hadoop/ 注意:hadoop2.x的配置文件$HADOOP_HOME/etc/hadoop 伪分布式需要修改5个配置文件 3.1配置hadoop 第一个:hadoop-env.sh vim hadoop-env.sh #第27行 export JAVA_HOME=/usr/java/jdk1.7.0_65 第二个:core-site.xml <!-- 指定HADOOP所使用的文件系统schema(URI),HDFS的老大(NameNode)的地址 --> <property> <name>fs.defaultFS</name> <value>hdfs://weekend-1206-01:9000</value> </property> <!-- 指定hadoop运行时产生文件的存储目录 --> <property> <name>hadoop.tmp.dir</name> <value>/home/hadoop/hadoop-2.4.1/tmp</value> </property> 第三个:hdfs-site.xml <!-- 指定HDFS副本的数量 --> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>dfs.secondary.http.address</name> <value>192.168.1.152:50090</value> </property> 第四个:mapred-site.xml (mv mapred-site.xml.template mapred-site.xml) mv mapred-site.xml.template mapred-site.xml vim mapred-site.xml <!-- 指定mr运行在yarn上 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> 第五个:yarn-site.xml <!-- 指定YARN的老大(ResourceManager)的地址 --> <property> <name>yarn.resourcemanager.hostname</name> <value>weekend-1206-01</value> </property> <!-- reducer获取数据的方式 --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> 3.2将hadoop添加到环境变量 vim /etc/proflie export JAVA_HOME=/usr/java/jdk1.7.0_65 export HADOOP_HOME=/itcast/hadoop-2.4.1 export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin source /etc/profile 3.3格式化namenode(是对namenode进行初始化) hdfs namenode -format (hadoop namenode -format) 3.4启动hadoop 先启动HDFS sbin/start-dfs.sh 再启动YARN sbin/start-yarn.sh 3.5验证是否启动成功 使用jps命令验证 27408 NameNode 28218 Jps 27643 SecondaryNameNode 28066 NodeManager 27803 ResourceManager 27512 DataNode http://192.168.1.101:50070 (HDFS管理界面) http://192.168.1.101:8088 (MR管理界面) 4.配置ssh免登陆 #生成ssh免登陆密钥 #进入到我的home目录 cd ~/.ssh ssh-keygen -t rsa (四个回车) 执行完这个命令后,会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥) 将公钥拷贝到要免密登陆的目标机器上 ssh-copy-id localhost --------------------------- ssh免登陆: 生成key: ssh-keygen 复制从A复制到B上: ssh-copy-id B 验证: ssh localhost/exit,ps -e|grep ssh ssh A #在B中执行 启动hadoop集群:(此处配置搞了一天!!!!) 1、注意关闭防火墙 2、修改hosts里面文件,三个都需要加 192.168.162.130 mini130 192.168.162.131 mini131 192.168.162.132 mini132 192.168.162.133 mini133 3、slaves文件中也需要配置 192.168.162.130 mini130 192.168.162.131 mini131 192.168.162.132 mini132 192.168.162.133 mini133 4、配置hadoop中的4个xml文件中写mini130这样的 5、把master配置好后,拷贝到其他的服务器上面即可 hadoop-daemon.sh start namenode hadoop-daemon.sh stop namenode hadoop-daemon.sh start datanode hadoop-daemon.sh start datanode yarn-daemon.sh stop resourcemanager yarn-daemon.sh start resourcemanager 本文转自yushiwh 51CTO博客,原文链接:http://blog.51cto.com/yushiwh/1910594,如需转载请自行联系原作者

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

ELK环境搭建

安装Elasticsearch1.拷贝elasticsearch-5.4.0.tar.gz到你需要安装的目录2.执行 sudo tar -zxvf elasticsearch-5.4.0.tar.gz 3.切换非root账户 su suername4.cd到解压后的目录 执行 ./bin/elasticsearch5.在浏览器输入localhost:9200如果出现一下字段说明ES安装成功 如果先ERROR日志请参考:http://www.qingpingshan.com/pc/fwq/205925.html http://www.cnblogs.com/sloveling/p/elasticsearch.html elasticsearch启动常见的错误 6.Elasticsearch启动时非root角色才可以!安装Logstash1.拷贝logstash-5.4.0.tar.gz到你需要安装的目录2.执行 sudo tar -zxvf logstash-5.4.0.tar.gz 3.cd到解压后的目录 执行 ./bin/logstash -e ""4.在挂起的程序中输入hello logstash5.出现一下内容则安装成功 6.安装时记得切换回拥有相关权限的角色安装Kibana1.拷贝kibana-5.4.0-linux-x86_64.tar.gz到你需要安装的目录2.执行 sudo tar -zxvf kibana-5.4.0-linux-x86_64.tar.gz3.cd到解压后的目录 执行 ./bin/kibana4.在浏览器访问localhost:5601出现一下内容则安装成功

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

openfire环境搭建

1、下载源代码:http://www.igniterealtime.org/downloads/source.jsp 2、把源代码解压出的openfire_src文件夹放至eclipse workplace(注意:若是变更了解压出来的文件名,则接下来所有用到文件名的地方都要作出相应更改,否则会报错!) 3、把openfire_src文件夹里的三个无用的html文件删除 4、打开eclipse,新建一个名为openfire_src的Java Project,然后finish 注:此处的默认路径为openfire_src文件夹的绝对路径 5、项目建好后如图所示,其中有几个目录报错,是由于缺少3个jar包:coherence.jar、coherence-work.jar、tangosol.jar 6、下载这几个jar包,然后复制到/openfire_src/build/lib目录下,下载地址 7、选中3个新添加的jar包,点击右键,选择Build Path -> Add to Build Path 8、把jar包编译后还是会有报错,如图,解决办法是直接找到java源文件SipCommRouter.java和SipManager.java ,使用eclipse的自动修复,把错误修复,一般是没有实现抽象方法和没有处理异常。 9、点击Window -> Show View -> Ant,在Ant中选择Add Buildfiles,将build目录下的build.xml选中,然后ok 10、把Java JDK的lib目录下的tools.jar包拷贝到 Java JRE的lib目录下 11、运行选中的文件 12、运行成功后,刷新工程,目录多出两个文件夹 13、将target/lib目录下的所有jar包选中,单击右键,选择Build Path –> Add to Build Path(和步骤7相似) 14、选中项目,点击run -> run configurations 15、选择run configurations左边的Java Application,单击右键,选择New 16、选中Main选项卡,点击Browse选择openfire_src项目;单击Search选择ServerStarter - org.jivesoftware.openfire.starter,结果如下 17、选中Arguments选项卡,在VM arguments中填入-DopenfireHome="${workspace_loc:openfire_src}/target/openfire" 18、选中Classpath选项卡,选中User Entries,点击右边的Advanced按钮 19、在弹出的框中选中Add Folders,选中src/i18n文件夹,点击ok 20、重复上一步骤把src/resources选中添加,结果如下:User Entries下多了两个文件夹 21、选中Common选项卡,将Debug和Run打钩,然后点击apply,再点击run 22、成功运行结果 23、在浏览器中输入上图的地址http://127.0.0.1:9090 24、选择中文,然后继续。服务器设置可直接跳过。数据库设置选择标准数据库连接,点击继续 25、在数据库设置-标准连接设置界面,选择数据库驱动mysql,更改数据库url,其中需要更改的有服务器ip地址,还有数据库名,建议单独建立一个名为openfire的数据库。输入数据库管理员的账号和密码,下一步。 26、数据库连接成功后界面,直接点击继续。 27、管理员账户设置界面,输入管理员的邮箱地址,还有管理员的账号的密码,初始账号为admin。 28、完成设置,登录到管理控制台,初始账户名admin密码为上一步设置的密码。 29、登陆成功后显示 30、检测服务器是否配置成功,到http://www.igniterealtime.org/downloads/index.jsp下载Spark 31、安装Spark,一路next,然后finish。运行Spark,创建Spark账号 32、使用创建的账号登陆Spark,登陆成功可在Openfire管理控制台的用户组看到新注册的用户和在线状态

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

基础为重,Python的基础,成就月薪过万

之前介绍了数字和字符串,接下来我们说的是列表和元祖这是之前的文章 Python安装与基本数据类型之一数字和字符串 List(列表) 列表是Python 中使⽤最频繁的数据类型。列表是写在⽅括号之间、⽤逗号分隔开的元素列表。列表中元素的类型可以不相同: 列表是写在⽅括号之间、⽤逗号分隔开的元素列表。列表中元素的类型可以不相同 和字符串⼀样,列表同样可以被索引和切⽚,列表被切⽚后返回⼀个包含所需元素的新列表。详细的在这⾥就不赘述了。 除了这些,列表还⽀持串联操作,使⽤+操作符: 与之前讲的字符串不⼀样的是,列表中的元素是可以改变的: PS: List写在⽅括号之间,元素⽤逗号隔开。 和字符串⼀样,list可以被索引和切⽚。 List可以使⽤+操作符进⾏拼接。 List中的元素是可以改变的。 Tuple(元组) 元组与列表类似,不同之处在于元组的元素不能修改。元组写在⼩括号⾥,元素之间⽤逗号隔开。 元组中的元素类型也可以不相同,元组与字符串类似,可以被索引且下标索引从0开始,也可以进⾏截取/切⽚ 其实,可以把字符串看作⼀种特殊的元组。 虽然tuple的元素不可改变,但它可以包含可变的对象,⽐如list列表。构造包含0个或1个元素的tuple是个特殊的问题,所以有⼀些额外的语法规则 现在手上也有一些Python的资料视频,大家可以加q-u-n 二二七,四三五,四五零 免费获取资料哈~ PS: 与字符串⼀样,元组的元素不能修改。 元组也可以被索引和切⽚,⽅法⼀样。 注意构造包含0或1个元素的元组的特殊语法规则。 元组也可以使⽤+操作符进⾏拼接。 Sets(集合) 集合是⼀个⽆序不重复元素的集。 基本功能是进⾏成员关系测试和消除重复元素。 可以使⽤⼤括号 或者 set()函数创建set集合,注意:创建⼀个空集合必须⽤ set() ⽽不是 { },因为{ }是⽤来创建⼀个空字典。 Dictionaries(字典) 我们最后再来介绍,字典是Python中另⼀个⾮常有⽤的内置数据类型。 字典是⼀种映射类型,它是⼀个⽆序的键 : 值对集合。关键字必须使⽤不可变类型,也就是说list和包含可变类型的tuple不能做关键字。在同⼀个字典中,关键字还必须互不相同。 PS: 字典是⼀种映射类型,它的元素是键值对。 字典的关键字必须为不可变类型,且不能重复。 创建空字典使⽤{ }。

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

HDFS的基础组成部分及基础操作

HDFS组件结构图解说: 1、如图所示中,NameNode充当master角色,职责包括:管理文档系统的命名空间(namespace);调节客户端访问到需要的文件(存储在DateNode中的文件) 2、DataNodes充当slaves角色,通常情况下,一台机器只部署一个Datenode,用来存储MapReduce程序需要的数据 3、Namenode会定期从DataNodes那里收到Heartbeat和Blockreport反馈 4、Heartbeat反馈用来确保DataNode没有出现功能异常; 5、Blockreport包含DataNode所存储的Block集合 二、HDFS设计原则 1、文件以块(block)方式存储 2、每个块带下远比多数文件系统来的大(预设64M) 3、通过副本机制提高可靠度和读取吞吐量 4、每个区块至少分到三台DataNode上(一般,对namenode进行raid1配置,对datanode进行raid5配置) 5、单一 master (NameNode)来协调存储元数据(metadata) 6、客户端对文件没有缓存机制 (No data caching) 三、NameNode(NN) NameNode主要功能提供名称查询服务,它是一个jetty服务器(一个开源的servlet容器,嵌入式的web服务器) NameNode保存metadate信息包括 文件owership和permissions 文件包含哪些块 Block保存在哪个DataNode(由DataNode启动时上报) 1、NameNode的metadate信息在启动后会加载到内存 2、metadata存储到磁盘文件名为”fsimage” Block的位置信息不会保存到fsimage 四.DataNode(DN) 保存Block 启动DN线程的时候会向NN汇报block信息 hadoop fs -cmd cmd :为具体的操作,基本上于UNIX的命令相同 args:参数 hdfs资源URL格式:scheme://bigdata/path scheme:协议名,file或hdfs bigdata:namenode主机名 path:路径 eg:hdfs://localhost:9000/user/chunk/test.txt 假设已经在core-site.xml设置了fs.default.name=hdfs://localhost:9000, 则仅使用/user/chunk/test.txt即可 hdfs命令示例:存放的数据以文件的形式存储,使用绝对路径来区分每个资源,在创建目录来存储资源时候要加/ #创建目录 hadoop fs -mkidr/myFirstDir #查看创建的目录 hadoop fs -ls /myFirstDir #返回为空,目前还没存放数据 #对当前创建目录存放文件 hadoop fs -put /etc/shadow /myFirstDir #查看目录下的文件 hadoop fs -ls /myFirstDir #复制文件到指定的位置 hadoop fs -get /hadoop目下的文件 /本地文件路径 hadoop fs -get /myFirstDir/shadow /home/#下载shadow到/home目录下 #新建一个空文件 hadoop fs -touchz /myFirstDir/newFile.txt #将hadoop上某个文件重命名 hadoop fs -mv /myFirstDir/newFile.txt /myFirstDir/bigdata.txt #将hadoop指定目录下所有内容保存为一个文件,同时down至本地 hadoop dfs -getmerge /myFirstDir/bigdata.txt /home/a #查看文件里的内容 hadoop fs -cat /myFirstDir/shadow #查看最后1000字节数据 hadoop fs -tail /myFirsDir/shadow #删除文件\目录 hadoop fs -rm -R /myFirstDir/shadow hadoop fs -rm -R /myFirstDir/Secondary #查看HDFS下的文件 hadoop fs -ls / #查看集群数据的信息,登陆master节点查看 http://192.168.1.114:50070 管理与更新 #查看HDFS的基本统计信息 hadoop dfsadmin -report #进出安全模式 hadoop dfsadmin -safemode enter hadoop dfsadmin -safemode leave #节点添加 添加一个新的DataNode节点,先在新加节点上安装好Hadoop, 要和NameNode使用相同的配置(可以直接从NameNode复制),修改$HADOOP_HOME/conf/master文件,加入NameNode主机名。 然后在NameNode节点上修改$HADOOP_HOME/conf/slaves文件,加入新节点名,再建立新加节点无密码的SSH连接,运行启动命令为: /bin/start-all.sh #负载均衡 HDFS的数据在各个DataNode中的分布可能很不均匀,尤其是在DataNode节点出现故障或新增DataNode节点时。 新增数据块时NameNode对DataNode节点的选择策略也有可能导致数据块分布不均匀。 用户可以使用命令重新平衡DataNode上的数据块的分布: start-balancer.sh 本文转自 DBAspace 51CTO博客,原文链接:http://blog.51cto.com/dbaspace/1874685

资源下载

更多资源
Mario

Mario

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

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

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

用户登录
用户注册