<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # redis-工具-安全-python連接 [TOC] ## 一、 PHP加載redis redis插件網址:http://pecl.php.net/package/redis 1. 操作步驟: 1)下載 ```sh cd /usr/local/src wget http://pecl.php.net/get/redis-2.2.7.tgz ``` 2)解壓并進入目錄 ``` /usr/local/php/bin/pipize .configure --with-php-config=/usr/local/bin/php-config make && make install 最后編輯php.ini,在最后加入如下語句 extension = redis.so ``` 3)重啟PHP并檢查redis是否加載成功 檢查方法1:phpinfo ```sh <?php phpinfo(); ?> ``` 檢查方法2:寫一個插入并讀取的腳本redis.php ```sh <?php $redis = newRedis(); $redis->connect('192.168.1.10',6379); $redis->set('keyname','value'); echo $redis->get('keyname'); ?> ``` ## 二、 redis工具 redis推薦使用的工具有兩個,分別是PHPRedisAdmin管理工具和rebtools分析工具,還有一個redis在windows下的管理工具xxx ### 1. PHPRedisAdmin: 網址:https://github.com/erikdubbelboer/phpRedisAdmin 方法: ```sh wget https://github.com/erikdubbelboer/phpRedisAdmin/archive/master.zip unzip master.zip mv phpRedisAdmin-master/ /var/www/html/redisadmin cd /var/www/html/ chown -R apache:apache redisadmin/ /etc/init.d/httpd start ``` 2. rdbtools 網址:https://github.com/sripathikrishnan/redis-rdb-tools 方法: ``` yum install python-pip -y pip install rdbtools cd /var/lib/redis/ cp dump.rdb /tmp/ rdb -c memory /tmp/dump.rdb >redis.csv ``` ## 三、redis安全 redis漏洞入侵模擬:http://unixhot.com/article/23 1)設置密碼 找到配置文件中的如下位置,然后將井號去掉并寫上自己的密碼,重啟即可 ```sh grep requirepass /etc/redis.conf # If the master is password protected (using the "requirepass" configuration # requirepass foobared ``` 以后連接上redis數據庫以后,任何操作都會提示沒有權限,需要進行認證 ``` 11.10.0.0.41:6379> auth oldboy ``` 2)給危險命令進行重命名 ```sh grep rename /etc/redis.conf # security of read only slaves using 'rename-command' to shadow all the # environment. For instance the CONFIG command may be renamed into something # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 # rename-command CONFIG "" ``` ## 四、 redis的api開發 Redis提供了各類開發語言的API,方便開發語言連接使用Redis。 https://redis.io/clients官方網站提供了不同開發語言的API程序 官網中,給我們提供了很多種Python連接redis的API,我們通常選擇有“笑臉”并且帶有“星號”的使用,這里我們推薦使用redis-py. ### 1. pythoy連接redis 1)python安裝 ```sh tar xf Python-3.5.2.tar.xz cd Python-3.5.2 ./configure make && make install ``` 2)安裝redis-py客戶端 下載地址 https://redis.io/clients,下載redis-py-master.zip ```sh unzip redis-py-master.zip cd redis-py-master python3 setup.py install ``` 3)安裝redis-cluser的客戶端程序 ```sh cd redis-py-cluster-unstable python3 setup.py install ### 2. 對redis的單實例進行連接操作 python3 >>>import redis >>>r = redis.StrictRedis(host='localhost', port=6379, db=0,password='root') >>>r.set('lufei', 'guojialei') True >>>r.get('lufei') 'bar' ``` ### 3. sentinel集群連接并操作 ```sh [root@db01 ~]# redis-server /data/redis_m/6380/redis.conf [root@db01 ~]# redis-server /data/redis_m/6381/redis.conf [root@db01 ~]# redis-server /data/redis_m/6382/redis.conf [root@db01 ~]# redis-sentinel /data/26380/sentinel.conf & 1) 導入redis sentinel包 >>> from redis.sentinel import Sentinel 2) 指定sentinel的地址和端口號 >>> sentinel = Sentinel([('localhost', 26380)], socket_timeout=0.1) 3) 測試,獲取以下主庫和從庫的信息 >>> sentinel.discover_master('mymaster') >>> sentinel.discover_slaves('mymaster') ``` ### 4. 配置讀寫分離 ```sh 1) 寫節點 >>> master = sentinel.master_for('mymaster', socket_timeout=0.1) 2) 讀節點 >>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1) 3) 讀寫分離測試 key >>> master.set('oldboy', '123') >>> slave.get('oldboy') '123' ``` ### 5. redis cluster的連接并操作 python2.7.2以上版本才支持redis cluster,我們選擇的是3.5,下載地址:https://github.com/Grokzen/redis-py-cluster 1)python連接rediscluster集群測試 安裝 ```sh $ pip install redis-py-cluster or from source $ python setup.py install ``` 使用 ```sh >>> from rediscluster import StrictRedisCluster >>> startup_nodes = [{"host": "127.0.0.1", "port": "7000"}] >>> # Note: decode_responses must be set to True when used with python3 >>> rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True) >>> rc.set("foo", "bar") True >>> print(rc.get("foo")) 'bar' ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看