{"id":7494,"date":"2018-06-01T23:02:01","date_gmt":"2018-06-01T15:02:01","guid":{"rendered":"http:\/\/rmohan.com\/?p=7494"},"modified":"2018-06-01T23:02:01","modified_gmt":"2018-06-01T15:02:01","slug":"ec2-instance","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7494","title":{"rendered":"EC2 instance"},"content":{"rendered":"<pre>chmod 400 SeniorServer.pem\r\n\r\nServer: ssh -i \"SeniorServer.pem\" ec2-user@ec2-54-149-37-172.us-west-2.compute.amazonaws.com\r\npassword for root:qwe123456\r\n\r\nserver2: ssh -i \"senior_design_victor.pem\" ec2-user@ec2-54-69-160-179.us-west-2.compute.amazonaws.com\r\n\r\ncontroller: ssh -i \"zheng.pem\" ec2-user@ec2-52-34-59-51.us-west-2.compute.amazonaws.com\r\n\r\n\r\nDB: mysql -h seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com -P 3306 -u root -p\r\nusername: root\r\npassword: qwe123456\r\n\r\n\r\nuse command \"screen\" to keep running server codes and controller codes on AWS\r\nscreen  #create a new screen session\r\nscreen -ls  #check running screens\r\nscreen -r screenID   #resume to a screen\r\nscreen -X -S screenID kill   #end a screen\r\n\r\n\r\nMySQL:\r\ncreate table transaction (username varchar(20), history varchar(20));\r\ninsert into property (username,password,money) values (\"client1\",\"123\",100);\r\n\r\n\r\nTo create more replicated server\/db:\r\n\r\nMaster (RDS) - all in mysql, no Bash - remember to remove [] from statements\r\n\t1. Create new slave\r\n\t\tCREATE USER '[SLAVE USERNAME]'@'%' IDENTIFIED BY '[SLAVE PASSWORD]'; \r\n\t2. Give it access \r\n\t\tGRANT REPLICATION SLAVE ON *.* TO '[SLAVE USERNAME]'@'%';  \r\n\r\nSlave (Server) - \r\n\t1. [Bash] Import the database from master\r\n\t\tmysqldump -h seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com -u root -p senior_design &gt; dump.sql\r\n\r\n\t2. [Bash] Import the dump.sql into your database \r\n\t\tmysql senior_design &lt; dump.sql\r\n\r\n\t3. [Bash] Edit the \/etc\/my.cnf - will require root access, add the follow lines\r\n\t**Remember to keep server-id different (currently using 10, so next is 11, etc...)\r\n\t\t# Give the server a unique ID\r\n\t\tserver-id               = #CHANGE THIS NUMBER#\r\n\t\t#\r\n\t\t# Ensure there's a relay log\r\n\t\trelay-log               = \/var\/lib\/mysql\/mysql-relay-bin.log\r\n\t\t#\r\n\t\t# Keep the binary log on\r\n\t\tlog_bin                 = \/var\/lib\/mysql\/mysql-bin.log\r\n\t\treplicate_do_db            = senior_design\r\n\r\n\t4. [Bash] Restart mysqld\r\n\t\tservice mysqld restart\r\n\r\nMaster-Slave Connection Creation\r\n\t1. On master (RDS) - type\r\n\t\tshow master status;\r\n\t\t** We will need to keep note of File and Position\r\n\t\t+----------------------------+----------+--------------+------------------+-------------------+\r\n\t\t| File                       | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |\r\n\t\t+----------------------------+----------+--------------+------------------+-------------------+\r\n\t\t| mysql-bin-changelog.010934 |      400 |              |                  |                   |\r\n\t\t+----------------------------+----------+--------------+------------------+-------------------+\r\n\t2. On the slave, enter mysql then enter\r\n\t\tCHANGE MASTER TO MASTER_HOST='seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com', MASTER_USER='[SLAVE NAME]', MASTER_PASSWORD='[SLAVE PWD]', MASTER_LOG_FILE='[MASTER FILE] ', MASTER_LOG_POS= [MASTER POSITION];\r\n\t3. On the slave, enter \"START SLAVE;\"\r\n\t4. Make sure the slave started - \"SHOW SLAVE STATUS\\G;\"\r\n\t5. You can always triple check by adding a new row to senior_design in master then see if it updates in slave.\r\n\r\n\tTROUBLESHOOTING \r\n\t- If for some reason you mess up the slave in step 2.\r\n\t\t[mysql] on the slave side\r\n\t\t\treset slave;\r\n\t\tthen repeat step 2 - 5\r\n\t- If in SHOW SLAVE STATUS\\G shows error\r\n\t\ttry \r\n\t\t\tSTOP SLAVE;\r\n\t\t\tSET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;\r\n\t\t\tSTART SLAVE;\r\n\t\terror should be gone, but this will only skip the error; the error may still re-appear\r\n\r\nuse senior_design;\r\nselect count(*) from property;\r\n\r\n\r\nSlave user pass:\r\nSlave 1 - username: slave1 pass: slave1pwd\r\nSlave 2 - username: slave2 pass: [slave2]\r\n\r\nCHANGE MASTER TO MASTER_HOST='seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com', MASTER_USER='slave1', MASTER_PASSWORD='slave1pwd', MASTER_LOG_FILE='mysql-bin-changelog.011030', MASTER_LOG_POS= 400;\r\n\r\nCHANGE MASTER TO MASTER_HOST='seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com', MASTER_USER='slave2', MASTER_PASSWORD='[slave2]', MASTER_LOG_FILE='mysql-bin-changelog.011030', MASTER_LOG_POS= 400;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>chmod 400 SeniorServer.pem Server: ssh -i &#8220;SeniorServer.pem&#8221; ec2-user@ec2-54-149-37-172.us-west-2.compute.amazonaws.com password for root:qwe123456 server2: ssh -i &#8220;senior_design_victor.pem&#8221; ec2-user@ec2-54-69-160-179.us-west-2.compute.amazonaws.com controller: ssh -i &#8220;zheng.pem&#8221; ec2-user@ec2-52-34-59-51.us-west-2.compute.amazonaws.com DB: mysql -h seniordesign.c9btkcvedeon.us-west-2.rds.amazonaws.com -P 3306 -u root -p username: root password: qwe123456 use command &#8220;screen&#8221; to keep running server codes and controller codes on AWS screen #create a new screen session screen -ls [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7494"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7494"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7494\/revisions"}],"predecessor-version":[{"id":7511,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7494\/revisions\/7511"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}