オペレーティングシステム編のLinuxコマンド操作とredisインストールおよび基本使用

29674 ワード

       : windows7,8,10,xp,win98
                 : linux ax unix
                      ,       linux.
        linux   :    ,     ,    ..
        linux     :     tomcat   (redis).....
    1.       ,       ,360    (  vmware  )
    
      :
            :
                   ./      ../         .
            ./       
            ../       
            /      
            
            clear  
            
        :
        ls list         :
            -l :     
            -r :   
            -t :   
                   ll
            ll -a
            -a :          .
        cd change     :
                    .
            ~    :        ,cd~       cd   cd~  .
            cd - :         .
        pwd :         .
        mkdir -p :        
        :
        cat :        ,      ,     .
            cat    .
        more :        .
            more   
                  
            b    
                 
            q   
        less       
            less   
                  
            b    
                 
            q   
           
                               (/        ,?        ) ?           /        
              :
                -m    
                -N   
                    
        tail         :
            tail-                .
               -f    .
            (                ,          )
            
                  
                        ,  tail        .
            ping        .
            ping 127.0.0.1>ip.log  ping              
              : 127.0.0.1>ip.log & :       
            tail -f ip.log  :       ip.log     ,        
        
        :
        cp           copy
            cp           
            cp      /                
            -r :     
        mv  move
            mv            .
            mv      /                .
            -f    
        rm remove   
            rm-fr           
        find   
            find    -name     
            find    -name '*...'
        :
        vi vim       
            vi    txt
            vim     note++
    vim :      
             :         ,           , i  a  o  ,       :       .
             :              , esc         .
             :      registry-zookeeper:wq        :q!      .
          ,  esc ,   Shift+:   ,q!   wq
           :
        yy    p     dd     .
        nyy      ndd    .
        gg     shift + g     .
       | 
           :                1|  2
    
    grep        
           1: grep-i           
           2:   1|grep-i                        
            1              .
    
    
    
        :
        ps-ef        
             :
            ps-ef|grep-i      
        kill   
        kill pid     
        kill-9 pid     
        
        ifconfig     ip
        ping      
        
        :
                 :
        tar -zcvf             
        tar -zxvf                   
    
        (  )
           reboot
           halt
        
        shutdown -r      
        shutdonw -h      
    
        
        chmod        
        chmod 000       
        comod 777       
          7       
        4 2 1
        r            2 2    4
        w           2 1    2
        x        2 0    1
    
          :
            drwxr-xr-x. 2 root root 4096 8  11 04:23 a :                , d     ,-    
            -rw-r--r--.  : rw-      ; r--        ; r--     
                   : -rwxrw-r--
                    :     (d  ,-     ,|     (      ));
                 2-4 :       , u(user)  ;
                 5-7 :      , g(group)  ;
                 8-10 :       , o(other)  ;
                 2-10 :        , a(all)  ;
                r     
                w     
                x      
        
            :-       
            chmod u-rwx aaa.tar;         ---
            chmod g-rwx aaa.tar;          ---
            chmod o-rwx aaa.tar;           ---
            
            chmod ugo+rwx aaa.tar :              
            chmod 000 aaa.tar ;           
            chmod 777 aaa.tar;            
        
             :   CRT    linux,        :
        vim/etc/sysconfig/netword-scripts/ifcfg-eth0
            1 .     ,      .
            2 . 360       .
            3 .            .
            4 .         .
            5 . Linux               .
    
    ONBOOT = yes  :         
Linux         ,     ,tomcat ,  jdk,mysql,  redis
        :
        1.       .
        2.  .
        3.  .
    
    rpm -qa   .
    rpm -ivh        .
    rpm -Uvh        .
    rpm -e     --nodeps      .
    
      :
                  jdk : rpm -qa | grep -i jdk
              jdk,        
        rpm -e      jdk  
    
    yum remove         
    yum install         
    cm95DvStxaqflMVE :                
    
    gPKufF50DIn720ua   MySql  
    
    NoSql : 
    
        NoSql   :
                                    :
                1.   :
                    NoSql        ,                        .    
                       ,         .     ,                .
                2.    ,   
                    NoSql               ,        ,      .      
                        ,        .
                3.       
                    NoSql                ,              .     
                       ,              .           ,        
                        .        Web2.0      .
                4.   
                    NoSql           ,              .  Cassandra,HBase
                      ,             .
                    
    
    
        MySql        :          ,      .
        Redis         :            (    ,     )
        db4o       :          .
        
            :          .
            :            .
        
        Redis :                        .
            Redis  C                (key-value)   .                  
                    ,    Redis           :
                1.       2.      3.      4.      5.      
        hibernate :          .
        hibernate :     (      )   redis  .
        
        redis   
              C     .
        
        Redis       :
            1.            redis      copy     redis.conf
            cp redis.conf /usr/local/src/redis
            
            2.      
                daemonize yes(   yes)
                           ,    _    _   _    _0  1
                Constant                  .
                public static final     _    _   _    _=""
        
            :
        
            redis       key-value     ,  value        .
                1.   (String)  2.  (hash)  3.     (list)
                4.     (set)  5.       (sorted set)
                   key    ,         :
                1:key    ,      1024   ,                
                2.key    ,       key    .
                3.    ,key            .
        
            String
                   set key value
                
                   get key
                     getset key value      
                
                   del key
                
                  
                       incr key
                    
                       decr key
                    
                         incrby key   
                    
                         decrby key   
                    
                       append key      
                    
            Hash
                  :
                    hset                       
                    hmset                           
                  
                    hget                   
                    hmget            [         ]...          
                    hgetall              
                  
                    del               (          )
                    hdel          [....]
            
                  
                          
                        hincrby                
                                 
                        hexists      
                      
                        hlen   
                         key
                        hkeys   
                         value
                        hvals   
                          key value
                        hgetall   
                        
            :           class   ,              .
           :      (    tomcat jar        jar ,         class  ) ,      (       jar ,       jar       ) ,       (          ).
                          .
         :        ,       
    System.out.println(ClassLoaderDemo.class.getClassLoader());
    System.out.println(ClassLoaderDemo.class.getClassLoader().getParent());
    System.out.println(ClassLoaderDemo.class.getClassLoader().getParent().getParent());
    
    rt.jar       ,          .
    String parths = System.getProperty("sun.boot.class.path");
    String[] arr = parths.split(";");
    for(String string : arr) {
        System.out.println(string);
    }
    System.out.println(String.class.getClassLoader());
    
    public class ClassLoaderDemo {
    /*public static void main(String[] args) {
        //       :           class                
        //       :                       (    C             Class  )
        //    :          
        //System.out.println(ClassLoaderDemo.class.getClassLoader());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent().getParent());
        //System.out.println(DNSNameService.class.getClassLoader());
        
        //rt.jar                 
        String parths = System.getProperty("sun.boot.class.path");
        String [] arr = parths.split(";");
        
        for (String string : arr) {
            System.out.println(string);
        }
        System.out.println(String.class.getClassLoader());
        
    }*/
    /*public static void main(String[] args) {
        //       :           class                
        //       :                       (    C             Class  )
        //    :          
        //System.out.println(ClassLoaderDemo.class.getClassLoader());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent().getParent());
        //System.out.println(DNSNameService.class.getClassLoader());
        
        //rt.jar                 
        String parths = System.getProperty("java.ext.dirs");
        String [] arr = parths.split(";");
        
        for (String string : arr) {
            System.out.println(string);
        }
        //             
        System.out.println(DNSNameService.class.getClassLoader());
        
    }*/
    
    
    public static void main(String[] args) {
        //       :           class                
        //       :                       (    C             Class  )
        //    :          
        //System.out.println(ClassLoaderDemo.class.getClassLoader());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent());
        //System.out.println(ClassLoaderDemo.class.getClassLoader().getParent().getParent());
        //System.out.println(DNSNameService.class.getClassLoader());
        
        //rt.jar                 
        String parths = System.getProperty("java.class.path");
        String [] arr = parths.split(";");
        
        for (String string : arr) {
            System.out.println(string);
        }
        //           tomcat   jar       
        //E:\Users\hzb\workspace\ee66_day48\build\classes
        //E:\Users\hzb\workspace\ee66_day48\WebContent\WEB-INF\lib\jedis-2.7.0.jar
        System.out.println(ClassLoaderDemo.class.getClassLoader());
        
    }
}
List
          :lpush key value1[value2......]             key      
             rpush key value1[value2......]             key      
          
            lrange key start end       start       end           .
            end                  
          
            lpop key      
            rpop key      
          
            llen key       
            lpushx key value1            key          
            rpushx key value1            key          
            lrem key count value            
                count > 0       count 
                count = 0        value 
                count < 0       count 
            lset key index value        index  value 
            linsert key before | after                      
            rpoplpush   1   2      1              2      (       )
        
    Set    
           : 
            sadd key value [value...]    
           :
            smembers key        
          
            srem key value [value...]         
            
          
            sismember key member               
             
                    1      2        1    .
                sdiff key1 key2
                             
                sinter key1 key2
                                
                sunion key1 key2
            
                
                    1      2        1           newkey 
                sdiffstore newkey key1 key2
                                    newkey 
                sinterstore newkey key1 key2
                                       newkey 
                sunionstore newkey key1 key2
            scard key            
            srandmember key         
        
    Sortset
           : 
            zadd key sore1 member1 sore2 member2 ...
           : 
            zrange key start end [withscores]                 
            start         end            
                                  end                    
            zrevrange key start end [withscores]              
          
            zrem key member
          
            zscore key member           
            zcard key        
                       
            zremrangebyrank key start end
            
                   start end
            zremrangebyscore key minscore maxscore
            
                      
            zrangebyscore key minscore maxscore [withscores] [limit startindex pagesize]
            
                 
            zincrby key    value  
                  
            zcount key minscore maxscore
            
                    
            zrank key value   
            zrevrank key value    
        
            
            keys *        key ?       
            Del key      key
            Exists key   key    
            Rename key  newKey     
            Type key     
            
            Expire key       
            Ttl       
                -2     
                -1     
                >0          
                
    Jedis
        Jedis java    redis                java     redis     jar 
            commons-pool-2.3.jar
            jedis-2.7.0.jar
            
        jedis   :
            public static void main(String[] args) {
                //  redis   java    jedis  
                
                Jedis jedis = new Jedis("192.168.40.199",6379);
                String nickname = jedis.get("nickname");
                System.out.println(nickname);
                //    
                jedis.set("nickname","  ");//      json   
                nickname = jedis.get("nickname");
                System.out.println(nickname);
                jedis.close();
                
            }
        
        Jedis    :
            public static void main(String[] args) {
                //      
                JedisPoolConfig poolConfig = new JedisPoolConfig();
                
                //      
                //      (              ,           ,             ,       ,            ,      )
                poolConfig.setMinIdle(3);
                //      (              ,            ,             30 ,     30 ,      )
                poolConfig.setMaxIdle(30);
                //     
                JedisPool jedisPool = new JedisPool(poolConfig,"192.168.40.199",6379);
                //          jedis  
                Jedis jedis = jedisPool.getResource();
                
                String nickname = jedis.get("nickname");
                System.out.println(nickname);
                jedis.close();
                
            }
            
    1.8Redis  
        1.8.1      
                        

        Select         
        Move key     key           

           quit exit ctrl + c
        Dbsize key   
        Info   

        Flushdb           key
        Flushall         key


        1.8.2       
        Subscribe                  
        Psubscribe               
        Publish                  



    1.8.3  (    )
        Multi     
        Exec   
        Discard     

                               
        1.9   
        Redis                       (      )
        Redis            :         

                    ?         
            RDB :    redis          
                  :     
                  :         
            AOF :               
                  :       
                  :      
                  AOF       
              AOF      
        1.  AOF
        2.            
        3.     
        4. redis        (             )
        5.  redis         
                
                           :vim /etc/sysconfig/iptables
                : service iptables restart

                  redis     
                cd /usr/local/redis
                /usr/local/src/redis install
                  bin           
                ./bin/redis-cli
                ./redis-server ../redis.conf
        
    9.  redis  
            cd /root/baidu/redis/redis-3.0.0
            10. redis  conf     redis 
            cp redis.conf /usr/local/redis

            11.  redis bin   
            cd /usr/local/src/redis/bin
            12.  
            ./redis-server ../redis.conf 



                
            vim /usr/local/redis/redis.conf
            1.          yes
            daemonize no  ==>>daemonize yes

            2.   ,      
            cd /usr/local/redis/
            ./bin/redis-server ./redis.conf