forked from docs/doc-exports
Reviewed-by: Mützel, Andrea <andrea.muetzel@t-systems.com> Co-authored-by: Chen, Junjie <chenjunjie@huawei.com> Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
86 lines
17 KiB
HTML
86 lines
17 KiB
HTML
<a name="dcs-migrate-0220411"></a><a name="dcs-migrate-0220411"></a>
|
|
|
|
<h1 class="topictitle1">Online Full Migration of Redis from Another Cloud with redis-shake</h1>
|
|
<div id="body0000001252915134"><p id="dcs-migrate-0220411__p5787143145417">redis-shake is an open-source Redis migration tool. Its <strong id="dcs-migrate-0220411__b723122553519">rump</strong> mode allows you to obtain the full data of a source Redis using the <strong id="dcs-migrate-0220411__b1721910153613">SCAN</strong> command and write the data to a target Redis. This migration solution does not involve the <strong id="dcs-migrate-0220411__b7902752123611">SYNC</strong> or <strong id="dcs-migrate-0220411__b11730115443612">PSYNC</strong> command and can be widely used for migration between self-built Redis and cloud Redis.</p>
|
|
<p id="dcs-migrate-0220411__p1197516426595">This section describes how to use the <strong id="dcs-migrate-0220411__b14142161645314">rump</strong> mode of redis-shake to migrate the full Redis data of another cloud service vendor at a time online to DCS.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig413301355"><span class="figcap"><b>Figure 1 </b>Data flow in this solution</span><br><span><img class="eddx" id="dcs-migrate-0220411__image141318018356" src="en-us_image_0000001252755478.png"></span></div>
|
|
<div class="section" id="dcs-migrate-0220411__section175461313181014"><h4 class="sectiontitle">Prerequisites</h4><ul id="dcs-migrate-0220411__ul173951945161011"><li id="dcs-migrate-0220411__li670798205113">A <a href="dcs-ug-0312003.html">DCS Redis instance</a> has been created on the target cloud.</li><li id="dcs-migrate-0220411__li1707885513">An ECS has been created on the target cloud for running redis-shake.</li><li id="dcs-migrate-0220411__li853633720249">The ECS is in the same VPC as the DCS Redis instance and bound with an EIP.</li><li id="dcs-migrate-0220411__li7896125614717">The <strong id="dcs-migrate-0220411__b1797812714015">rump</strong> mode does not support incremental data migration. To keep data consistency, stop writing data to the source Redis before migration.</li><li id="dcs-migrate-0220411__li33921654778">This solution applies only to same-database mapping and does not apply to inter-database mapping.</li><li id="dcs-migrate-0220411__li1840043412101">If the source Redis has multiple databases (there are databases other than DB0), and your DCS instance is a cluster, this solution cannot be used. (Cluster DCS instances support only DB0.)</li></ul>
|
|
</div>
|
|
<div class="section" id="dcs-migrate-0220411__section4705105323111"><h4 class="sectiontitle">Procedure</h4><ol id="dcs-migrate-0220411__ol205640192327"><li id="dcs-migrate-0220411__li13849164817164"><span>Install Nginx on the ECS and the source forwarding server. The following describes how to install Nginx on an ECS running CentOS 7.x. The commands vary depending on the OS.</span><p><ol type="a" id="dcs-migrate-0220411__ol119934157811"><li id="dcs-migrate-0220411__li1157785919418">Add Nginx to the Yum repository.<pre class="screen" id="dcs-migrate-0220411__screen1772818581207">sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm</pre>
|
|
</li><li id="dcs-migrate-0220411__li144619714412">Check whether Nginx has been added successfully.<pre class="screen" id="dcs-migrate-0220411__screen057611169213">yum search nginx</pre>
|
|
</li><li id="dcs-migrate-0220411__li74060102434">Install Nginx.<pre class="screen" id="dcs-migrate-0220411__screen1718112712219">sudo yum install -y nginx</pre>
|
|
</li><li id="dcs-migrate-0220411__li680091916116">Install the stream module.<pre class="screen" id="dcs-migrate-0220411__screen1261114335212">yum install nginx-mod-stream --skip-broken</pre>
|
|
</li><li id="dcs-migrate-0220411__li19861625451">Start Nginx and set it to run automatically upon system startup.<pre class="screen" id="dcs-migrate-0220411__screen125701739142116">sudo systemctl start nginx.service
|
|
sudo systemctl enable nginx.service</pre>
|
|
</li><li id="dcs-migrate-0220411__li1120155614616">In the address box of a browser, enter the server address (the EIP of the ECS) to check whether Nginx is installed successfully.<p id="dcs-migrate-0220411__p9122195434716"><a name="dcs-migrate-0220411__li1120155614616"></a><a name="li1120155614616"></a>If the following page is displayed, Nginx has been installed successfully.</p>
|
|
<p id="dcs-migrate-0220411__p1990011394818"><span><img id="dcs-migrate-0220411__image14626143715215" src="en-us_image_0000001253074986.png"></span></p>
|
|
</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li76111381445"><span>Add the source forwarding server to the whitelist of the source Redis.</span></li><li id="dcs-migrate-0220411__li14428144951818"><span>Configure a security group for the source forwarding server.</span><p><ol type="a" id="dcs-migrate-0220411__ol928413126193"><li id="dcs-migrate-0220411__li14669191812192">Obtain the EIP of the ECS.</li><li id="dcs-migrate-0220411__li18771752151914">In the inbound rule of the security group of the source forwarding server, add the EIP of the ECS, and open the port that ECS's requests come through. The following takes port 6379 as an example.</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li19975143613450"><span>Configure Nginx forwarding for the source forwarding server.</span><p><ol type="a" id="dcs-migrate-0220411__ol1924094324811"><li id="dcs-migrate-0220411__li19609174934817">Log in to the Linux source forwarding server and run the following commands to open and modify the configuration file:<pre class="screen" id="dcs-migrate-0220411__screen13202858165910">cd /etc/nginx
|
|
vi nginx.conf</pre>
|
|
</li><li id="dcs-migrate-0220411__li06401357104818">Example forwarding configuration:<pre class="screen" id="dcs-migrate-0220411__screen34331446184818">stream {
|
|
server {
|
|
listen 6379;
|
|
proxy_pass {source_instance_address}:{port};
|
|
}
|
|
}</pre>
|
|
<p id="dcs-migrate-0220411__p232810156114"><strong id="dcs-migrate-0220411__b17662158131214">6379</strong> is the listening port of the source forwarding server. <em id="dcs-migrate-0220411__i437151691218">{source_instance_address}</em> and <em id="dcs-migrate-0220411__i18885102313128">{port}</em> are the connection address and port of the source Redis instance.</p>
|
|
<p id="dcs-migrate-0220411__p474124917547">This configuration allows you to access the source Redis through the local listening port 6379 of the source forwarding server.</p>
|
|
<p id="dcs-migrate-0220411__p0452103812178">This configuration must be added exactly where it is shown in the following figure.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig42351341142517"><span class="figcap"><b>Figure 2 </b>Configuration location</span><br><span><img id="dcs-migrate-0220411__image162354412253" src="en-us_image_0000001299155037.png"></span></div>
|
|
</li><li id="dcs-migrate-0220411__li1416762953011">Restart Nginx.<pre class="screen" id="dcs-migrate-0220411__screen182391643118">service nginx restart</pre>
|
|
</li><li id="dcs-migrate-0220411__li1334411452304">Verify whether Nginx has been started.<pre class="screen" id="dcs-migrate-0220411__screen366531193118">netstat -an|grep 6379</pre>
|
|
<p id="dcs-migrate-0220411__p593853532713">If the port is being listened, Nginx has been started successfully.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig15433124613489"><span class="figcap"><b>Figure 3 </b>Verification result</span><br><span><img id="dcs-migrate-0220411__image1243324614819" src="en-us_image_0000001299513869.png"></span></div>
|
|
</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li107681114289"><span>Configure Nginx forwarding for the ECS.</span><p><ol type="a" id="dcs-migrate-0220411__ol1151616220369"><li id="dcs-migrate-0220411__li10516172263616">Log in to the Linux ECS and run the following commands to open and modify the configuration file:<p id="dcs-migrate-0220411__p10914155310204"><a name="dcs-migrate-0220411__li10516172263616"></a><a name="li10516172263616"></a><strong id="dcs-migrate-0220411__b1635831183610">cd /etc/nginx</strong></p>
|
|
<p id="dcs-migrate-0220411__p951915610209"><strong id="dcs-migrate-0220411__b156351631173618">vi nginx.conf</strong></p>
|
|
</li><li id="dcs-migrate-0220411__li28611116103716">Configuration example:<pre class="screen" id="dcs-migrate-0220411__screen1418219241098">stream {
|
|
server {
|
|
listen 6666;
|
|
proxy_pass {source_ecs_address}:6379;
|
|
}
|
|
}</pre>
|
|
<p id="dcs-migrate-0220411__p52110532392"><strong id="dcs-migrate-0220411__b1624173815217">6666</strong> is ECS's listening port, <em id="dcs-migrate-0220411__i216411091914">{source_ecs_address}</em> is the public IP address of the source forwarding server, and <strong id="dcs-migrate-0220411__b1672424382111">6379</strong> is the listening port of the source forwarding server Nginx.</p>
|
|
<p id="dcs-migrate-0220411__p2911729182613">This configuration allows you to access the source forwarding server through the local listening port 6666 of the ECS.</p>
|
|
<p id="dcs-migrate-0220411__p15629194810343">This configuration must be added exactly where it is shown in the following figure.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig262974853410"><span class="figcap"><b>Figure 4 </b>Configuration location</span><br><span><img id="dcs-migrate-0220411__image76291748143412" src="en-us_image_0000001299274493.png"></span></div>
|
|
</li><li id="dcs-migrate-0220411__li11629448133418">Restart Nginx.<pre class="screen" id="dcs-migrate-0220411__screen5629154873411">service nginx restart</pre>
|
|
</li><li id="dcs-migrate-0220411__li7629248173410">Verify whether Nginx has been started.<pre class="screen" id="dcs-migrate-0220411__screen1562954833418">netstat -an|grep 6666</pre>
|
|
<p id="dcs-migrate-0220411__p1459184772816">If the port is being listened, Nginx has been started successfully.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig52972206350"><span class="figcap"><b>Figure 5 </b>Verification result</span><br><span><img id="dcs-migrate-0220411__image1129752063519" src="en-us_image_0000001299354449.png"></span></div>
|
|
</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li1629316143413"><span>Run the following command on the ECS to test the network connection of port 6666:</span><p><pre class="screen" id="dcs-migrate-0220411__screen9189230121519">redis-cli -h {target_ecs_address} -p 6666 -a {password}</pre>
|
|
<p id="dcs-migrate-0220411__p16330112132510"><em id="dcs-migrate-0220411__i132590214215">{target_ecs_address}</em> is the EIP of the ECS, <strong id="dcs-migrate-0220411__b1927283314218">6666</strong> is the listening port of the ECS, and <em id="dcs-migrate-0220411__i254115492111">{password}</em> is the source Redis password. If there is no password, leave it blank.</p>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig1168715172413"><span class="figcap"><b>Figure 6 </b>Connection example</span><br><span><img id="dcs-migrate-0220411__image446672703311" src="en-us_image_0000001252915210.png"></span></div>
|
|
</p></li><li id="dcs-migrate-0220411__li13564181913214"><span>Prepare the migration tool redis-shake.</span><p><ol type="a" id="dcs-migrate-0220411__ol0483154263117"><li id="dcs-migrate-0220411__li630814352317">Log in to the ECS.</li><li id="dcs-migrate-0220411__li15905189153217">Download redis-shake. Version 2.0.3 is used as an example. You can use <a href="https://github.com/alibaba/RedisShake/releases" target="_blank" rel="noopener noreferrer">other redis-shake versions</a> as required.<pre class="screen" id="dcs-migrate-0220411__screen195204110481">wget https://github.com/tair-opensource/RedisShake/releases/download/release-v2.0.3-20200724/redis-shake-v2.0.3.tar.gz</pre>
|
|
</li><li id="dcs-migrate-0220411__li8781918103217">Decompress the redis-shake file.<pre class="screen" id="dcs-migrate-0220411__screen65481045101912">tar -xvf redis-shake-v2.0.3.tar.gz</pre>
|
|
</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li188959963517"><span>Configure the redis-shake configuration file.</span><p><ol type="a" id="dcs-migrate-0220411__ol1210514325499"><li id="dcs-migrate-0220411__li1311918125196">Go to the directory generated after the decompression.<pre class="screen" id="dcs-migrate-0220411__screen383515448361">cd redis-shake-v2.0.3</pre>
|
|
</li><li id="dcs-migrate-0220411__li427914206484">Modify the <strong id="dcs-migrate-0220411__b1795442212231">redis-shake.conf</strong> configuration file.<pre class="screen" id="dcs-migrate-0220411__screen162871920114818">vim redis-shake.conf</pre>
|
|
<p id="dcs-migrate-0220411__p323331816587">Modify the source Redis configuration.</p>
|
|
<ul id="dcs-migrate-0220411__ul065172810338"><li id="dcs-migrate-0220411__li19540124495317">source.type<p id="dcs-migrate-0220411__p3885446115316"><a name="dcs-migrate-0220411__li19540124495317"></a><a name="li19540124495317"></a>Type of the source Redis instance. Use <strong id="dcs-migrate-0220411__b753119187241">standalone</strong> for single-node, master/standby, and Proxy Cluster, and <strong id="dcs-migrate-0220411__b459832622413">cluster</strong> for cluster instances.</p>
|
|
</li><li id="dcs-migrate-0220411__li1444197145418">source.address<p id="dcs-migrate-0220411__p170318502520"><a name="dcs-migrate-0220411__li1444197145418"></a><a name="li1444197145418"></a>EIP of the ECS and the mapped port of the source forwarding server (ECS's listening port 6666). Separate the EIP and port number with a colon (:).</p>
|
|
</li><li id="dcs-migrate-0220411__li112489198558">source.password_raw<p id="dcs-migrate-0220411__p1794732135511"><a name="dcs-migrate-0220411__li112489198558"></a><a name="li112489198558"></a>Password of the source Redis instance. If no password is set, you do not need to set this parameter.</p>
|
|
</li></ul>
|
|
<p id="dcs-migrate-0220411__p485983313585">Modify the target DCS configuration.</p>
|
|
<ul id="dcs-migrate-0220411__ul4672232153313"><li id="dcs-migrate-0220411__li6150153985910">target.type<p id="dcs-migrate-0220411__p873994119599"><a name="dcs-migrate-0220411__li6150153985910"></a><a name="li6150153985910"></a>Type of the DCS Redis instance. Use <strong id="dcs-migrate-0220411__b20985728102516">standalone</strong> for single-node, master/standby, and Proxy Cluster, and <strong id="dcs-migrate-0220411__b139901528142518">cluster</strong> for cluster instances.</p>
|
|
</li><li id="dcs-migrate-0220411__li333157205">target.address<p id="dcs-migrate-0220411__p9796148602"><a name="dcs-migrate-0220411__li333157205"></a><a name="li333157205"></a>Colon (:) separated connection address and port of the DCS Redis instance.</p>
|
|
</li><li id="dcs-migrate-0220411__li4287910623">target.password_raw<p id="dcs-migrate-0220411__p2358717023"><a name="dcs-migrate-0220411__li4287910623"></a><a name="li4287910623"></a>Password of the DCS Redis instance. If no password is set, you do not need to set this parameter.</p>
|
|
</li></ul>
|
|
</li><li id="dcs-migrate-0220411__li72061610105414">Press <strong id="dcs-migrate-0220411__b745814296264">Esc</strong> to exit the editing mode and enter <strong id="dcs-migrate-0220411__b53296465547">:wq!</strong>. Press <strong id="dcs-migrate-0220411__b1074564817266">Enter</strong> to save the configuration and exit the editing interface.</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li893341084316"><span>Run the following command to start redis-shake and migrate data in the <strong id="dcs-migrate-0220411__b644212156279">rump</strong> (online in full) mode:</span><p><pre class="screen" id="dcs-migrate-0220411__screen194133405218">./redis-shake.linux -conf redis-shake.conf -type rump</pre>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig11121811922"><span class="figcap"><b>Figure 7 </b>Migration process</span><br><span><img id="dcs-migrate-0220411__image1755952719521" src="en-us_image_0000001252755498.png"></span></div>
|
|
<div class="fignone" id="dcs-migrate-0220411__fig6427185214"><span class="figcap"><b>Figure 8 </b>Migration result</span><br><span><img id="dcs-migrate-0220411__image7559142717525" src="en-us_image_0000001253234262.png"></span></div>
|
|
</p></li><li id="dcs-migrate-0220411__li154644591102"><span>After the migration is complete, use redis-cli to connect to the source and target Redis instances to check whether the data is complete.</span><p><ol type="a" id="dcs-migrate-0220411__ol46021459112920"><li id="dcs-migrate-0220411__li17397115712916">Connect to the source and target Redis instances, respectively.<p id="dcs-migrate-0220411__p20731122971718"><a name="dcs-migrate-0220411__li17397115712916"></a><a name="li17397115712916"></a>For details, see <a href="dcs-ug-0326009.html">Accessing a DCS Redis Instance Through redis-cli</a>.</p>
|
|
</li><li id="dcs-migrate-0220411__li99912440304">Run the <strong id="dcs-migrate-0220411__b1110104192813">info keyspace</strong> command to check the values of <strong id="dcs-migrate-0220411__b1101141172815">keys</strong> and <strong id="dcs-migrate-0220411__b1210124122813">expires</strong>.</li><li id="dcs-migrate-0220411__li174451506300">Calculate the differences between the values of <strong id="dcs-migrate-0220411__b91727780145635">keys</strong> and <strong id="dcs-migrate-0220411__b76239882845635">expires</strong> of the source Redis and the target Redis. If the differences are the same, the data is complete and the migration is successful.</li></ol>
|
|
</p></li><li id="dcs-migrate-0220411__li14332111316191"><span>Delete the redis-shake configuration file.</span></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dcs-migration-0312005.html">Migrating Redis Data from Another Cloud to DCS</a></div>
|
|
</div>
|
|
</div>
|
|
|