Learn about Centmin Mod LEMP Stack today
Register Now

Sysadmin test server

Discussion in 'System Administration' started by dooma, Jul 8, 2017.

  1. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    Hello,

    Now, I have my website online based on centminmod and everything is running fine but there're some options I want to test it so what do you suggest to make another copy of my server and website to try the new options online first before I use it at the main one ?

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    having a cloned/copy of main site is a good idea for testing

    having a copy of your server on a separate test server is even better i.e. using steps outlined at Centmin Mod Site Data Migration Guide for cloning server and just don't update DNS
     
  3. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    Thank you but should I install centminmod first on the remote server before starting the migration ?
     
  4. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    1- Should I install CSF on the remote server ?

    2- Where should I add this commands ? ( only write it on putty ? :
    *remoterootpass ( the password of the remote root )
    *yourremoteserver = ( is that the hostname ? ) server2.cloud as ex ???
    *rootpassword = ( write the same root password again ???

    Code (Text):
    remoteip=111.222.333.444
    port=22
    comment=mykey
    [U]remoterootpass=yourremoteserver_rootpassword[/U]


    3- I didn't get this step
    " First time you connect you'll be asked about authenticity of the remote host ip and get a fingerprint displayed and ask if you are sure you want to continue connecting. Answer yes "

    , it takes me to this one :

    snipped

    Thanks
     
    Last edited by a moderator: Jul 8, 2017
  5. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    edited your code as you might have reveal sesitive server info in output of the command
    yes install centmin mod on remote server too

    on SSH command line only current SSH window session would recognise the variables. Unless you do all the commands and work within a Tmux Sysadmin - [Tutorial] tmux tutorial or Screen session Sysadmin - Who uses Screen for linux ?

    incorrect command you listed $22 instead of $port and $remoteIP instead of $remoteip

    incorrect
    Code (Text):
    ./keygen.sh gen rsa $remoteIP $22 root $mykey $remotepass
    

    correct
    Code (Text):
    ./keygen.sh gen rsa $remoteip $port root $mykey $remotepass 
    
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    so
    Code (Text):
    remoteip=111.222.333.444
    port=22
    comment=mykey
    remoterootpass=yourremoteserver_rootpassword
    

    type below exactly as written the $ prefixed names are calling variables you created above i.e. port=22
    Code (Text):
    cd /root/tools/keygen
    ./keygen.sh gen rsa $remoteip $port root $comment $remoterootpass


    you are creating variables in SSH so port=22 is create variable with value of 22, so when you type in SSH $port it reads as 22

    to test
    Code (Text):
    port=22
    echo $port
    

    would return 22 when you echo $port variable

    more examples of keygen.sh I wrote at https://github.com/centminmod/keygen as mentioned at Centmin Mod Site Data Migration Guide
     
  7. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    I have a question please, how the copy of my website will be accessible without editing DNS ?
     
  8. bassie

    bassie Active Member

    535
    116
    43
    Apr 29, 2016
    Ratings:
    +348
    Local Time:
    3:11 PM
    Exactly just like @eva2000 Testing is highly recommended.
    Never test new software, settings etc on your money site before testing it. In short:
    Clone server, register maindomain-development.ltd, change domain + certs on cloned server and at last don't forget to no index the test site otherwise you could get duplicated content in search engines.
     
    Last edited: Jul 8, 2017
    • Agree Agree x 2
  9. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
  10. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
  11. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  12. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    Hello

    I'm getting this error. I'm sure that database transferred :

    Code (Text):
    mysql -e "YOUR GRANT CMD"
    ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'YOUR GRANT CMD' at line 1
    


    note that when I entered the exact below command nothing happened :
    Code (Text):
     mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql | while read user host; do if [[ "$user" != 'root' ]]; then mysql --batch --skip-column-names -e "SHOW GRANTS FOR '$user'@'$host'" | sed -e 's|$|;|'; fi; done


    What that mean ?

    Thanks
     
  13. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    you are entering command on source server not remote ?

    YOUR GRANT CMD isn't the actual command it's example Centmin Mod Site Data Migration Guide

     
  14. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    I got you. The first created command run empty. But the second one gives me that error :

    Code (Text):
     mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `DATABASENAME`.* TO 'DATBASEUSERNAME'@'localhost';"
    -bash: DATABASENAME: command not found
    ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '* TO 'DATABASEUSERNAME'@'localhost'' at line 1
    


    * I ran both commands on the remote server after copying the both lines(GRANT...) from the main server.

    Thanks for help
     
  15. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    yes because 1st command is empty = no mysql users were displayed when you ran
    Code (Text):
    mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql | while read user host; do if [[ "$user" != 'root' ]]; then mysql --batch --skip-column-names -e "SHOW GRANTS FOR '$user'@'$host'" | sed -e 's|$|;|'; fi; done
    

    did you run it on live server, it is meant to run on live server this command to list mysql usernames on live server. You then take those GRANT commands and run them on remote/new server
     
  16. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    sorry for explaining what I did again :

    I did what you said, I opened the live server and I ran this command :
    Code:
    mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql | while read user host; do if [[ "$user" != 'root' ]]; then mysql --batch --skip-column-names -e "SHOW GRANTS FOR '$user'@'$host'" | sed -e 's|$|;|'; fi; done

    then I ran those commands on the remote server :

    Code (Text):
    mysql -e "GRANT USAGE ON *.* TO 'dbuser1'@'localhost' IDENTIFIED BY PASSWORD '*196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7';"

    successfully


    Code (Text):
    mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `dbname2`.* TO 'dbuser1'@'localhost';"

    giving me the error in the previous replay

    and when I tried to check grants on the remote server it gives me the following :
    Code (Text):
    +-------------------------------------------------------------------------------------------------------------------+
    | Grants for DATABASEUSER@localhost                                                                                   |
    +-------------------------------------------------------------------------------------------------------------------+
    | GRANT USAGE ON *.* TO 'DATABASEUSER'@'localhost' IDENTIFIED BY PASSWORD '*94ECAC90F8C83E94ACB7CCC7CA9581B9E3E69B73' |
    +-------------------------------------------------------------------------------------------------------------------+

    **The first command was added but the second NOT??

    Thanks alot
     
  17. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    what was output on live server for
    Code (Text):
    mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql | while read user host; do if [[ "$user" != 'root' ]]; then mysql --batch --skip-column-names -e "SHOW GRANTS FOR '$user'@'$host'" | sed -e 's|$|;|'; fi; done
    

    you can mask the actual mysql username
     
  18. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    the output on live :
    Code (Text):
    GRANT USAGE ON *.* TO 'userdb'@'localhost' IDENTIFIED BY PASSWORD '*94ECAC90F8C83E94ACB7CCC7CA9581B9E3E69B73';
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `dbname`.* TO 'userdb'@'localhost';
     
  19. eva2000

    eva2000 Administrator Staff Member

    30,180
    6,786
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,139
    Local Time:
    11:11 PM
    Nginx 1.13.x
    MariaDB 5.5
    you're not meant to copy my example you are meant to replace the GRANT command with the ones you get outputted lines for

    so in your example on live server to get mysql user/pass and database GRANTs
    Code (Text):
    mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql | while read user host; do if [[ "$user" != 'root' ]]; then mysql --batch --skip-column-names -e "SHOW GRANTS FOR '$user'@'$host'" | sed -e 's|$|;|'; fi; done
    
    GRANT USAGE ON *.* TO 'userdb'@'localhost' IDENTIFIED BY PASSWORD '*94ECAC90F8C83E94ACB7CCC7CA9581B9E3E69B73';
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `dbname`.* TO 'userdb'@'localhost';
    

    so 1st line
    Code (Text):
    GRANT USAGE ON *.* TO 'userdb'@'localhost' IDENTIFIED BY PASSWORD '*94ECAC90F8C83E94ACB7CCC7CA9581B9E3E69B73';
    

    2nd line
    Code (Text):
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `dbname`.* TO 'userdb'@'localhost';
    

    so you wrap these lines in mysql -e "YOUR COMMAND" to become commands you run on remote server as
    so 1st line
    Code (Text):
    mysql -e "GRANT USAGE ON *.* TO 'userdb'@'localhost' IDENTIFIED BY PASSWORD '*94ECAC90F8C83E94ACB7CCC7CA9581B9E3E69B73';"
    

    2nd line
    Code (Text):
    mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `dbname`.* TO 'userdb'@'localhost';"
    

    running those 2 commands on remote server will just replicate / clone the mysql user/password and database grant privileges on remote server to be same as one from live server.
     
  20. dooma

    dooma Member

    226
    22
    18
    Oct 15, 2016
    Cairo
    Ratings:
    +27
    Local Time:
    3:11 PM
    Yes I understand, please check that what happened exactly with real info : please delete it after checking :