sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt install update-manager-core -y
sudo do-release-upgrade
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt install update-manager-core -y
sudo do-release-upgrade
Ref: https://alibaba-cloud.medium.com/how-to-setup-mariadb-master-and-slave-replication-on-ubuntu-16-04-850c155c5481
MariaDB is a free, open source and one of the most popular open source relational database management system. It is a drop-in replacement for MySQL intended to remain free under the GNU GPL. You will need to increase the instances of your MariaDB server and replicate the data on multiple servers when your traffic grows. The Master-Slave replication provides load balancing for the databases. It is not used for any failover solution.
There are two ways to replicate data:
Master-Master Replication: In this mode, data to be copied from either server. In other words, perform reads or writes from either server. So whenever one server gets the write request it will sync data to other server. This mode will be very useful when you want the best redundancy.
Master-Slave Replication: In this mode, data changes happen on the master server, while the slave server automatically replicates the changes from the master server. This mode will be best suited for data backups.
In this tutorial, we will learn how to set up MariaDB Master-Slave replication on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.
First, log in to your Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04 as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root user.
Once you are logged into your Ubuntu 16.04 instance, run the following command to update your base system with the latest available packages.
apt-get update -y
Before starting, you will need to install MariaDB server on both instance. You can install it by running the following command:
apt-get install mariadb-server -y
Once the installation is completed, start MariaDB service and enable it to start on boot time with the following command:
systemctl start mysql
systemctl enable mysql
By default, MariaDB is not secured. So you will need to secure it first. You can do this by running the following command:
mysql_secure_installation
Answer all the questions as shown below:
Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
First, you will need to edit /etc/mysql/my.cnf and make some changes inside it.
nano /etc/mysql/my.cnf
Make the following changes:
[mysqld]
bind-address = 192.168.0.101
server_id=1
log-basename=master
log-bin=/var/log/mysql/mariadb-bin
binlog-format=row
binlog-do-db=masterdb
Save and close the file, when you are finished.
Next, restart MariaDB service to apply the chnages:
systemctl restart mysql
Next, log in to MariaDB shell and configure replication:
mysql -u root -p
Enter your root password, then stop the slave and create a replication user and set password:
MariaDB [(none)]> STOP SLAVE;
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password';
Next, flush the privileges:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;
Next, check the master server status:
MariaDB [(none)]> SHOW MASTER STATUS;
Output:
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000001 | 615 | masterdb | |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
Note: Remember the file mariadb-bin.000001 and position number 615.
Next, exit from the MariaDB shell:
MariaDB [(none)]> exit;
Next, take a backup of all databases on the master server and transfer it to the slave server.
First, take all database backup with the following command:
mysqldump --all-databases --user=root --password --master-data > alldatabase.sql
Next, transfer alldatabase.sql file to the slave server with the following command:
scp alldatabase.sql root@192.168.0.102:/root/
Next, log in to MariaDB console again and unlock the tables:
mysql -u root -pMariaDB [(none)]> UNLOCK TABLES;
MariaDB [(none)]> exit;
You will also need to edit /etc/mysql/my.cnf file and make some changes inside it:
nano /etc/mysql/my.cnf
Make the following changes:
[mysqld]
bind-address = 192.168.0.102
server-id = 2
replicate-do-db=masterdb
Save the file, then restart MariaDB service:
systemctl restart mysql
Next, import the alldatabase.sql which you have transferred from master server:
mysql -u root -p < alldatabase.sql
Next, log in to MariaDB shell:
mysql -u root -p
Enter your root password, then stop the slave:
MariaDB [(none)]> STOP SLAVE;
Next, configure the slave to use the master with the following command:
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.0.101', MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mariadb-bin.000001', MASTER_LOG_POS=615;
Next, start the slave and check slave status:
MariaDB [(none)]> START SLAVE;
MariaDB [(none)]> SHOW SLAVE STATUS\G;
Output:
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 172.20.10.6
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000001
Read_Master_Log_Pos: 615
Relay_Log_File: mysqld-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mariadb-bin.000001
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB: masterdb
Both MariaDB master and slave server are now configured. It’s time to test replication.
Navigate to the Master server, and log in to MariaDB shell:
mysql -u root -p
Enter your root password, then create a database masterdb which you have specified in my.cnf file:
MariaDB [(none)]> create database masterdb;
Next, add some tables and entries on it:
MariaDB [(none)]> use masterdb;
MariaDB [masterdb]> create table mastertable (c int);
MariaDB [masterdb]> insert into mastertable (c) values (1);
Now, check the mastertable:
MariaDB [masterdb]> select * from mastertable;
Output:
+------+
| c |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
Now, navigate to the slave server and verify whether the above created table has been replicated:
First, log in to MariaDB shell:
mysql -u root -p
Enter your root password, then change the database to masterdb:
MariaDB [(none)]> use masterdb;
Next, check the mastertable:
MariaDB [masterdb]> select * from mastertable;
Output:
+------+
| c |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
You should see that the database and table are replicated successfully from the master server to the slave server.
Install ca-certificates
sudo apt-get install ca-certificates
Down load cer from letsencrypt
cd
/usr/share/ca-certificates
sudo wget https://letsencrypt.org/certs/isrgrootx1.pem
-O
isrgrootx1.crt
sudo wget
https://letsencrypt.org/certs/letsencryptauthorityx3.pem
-O
letsencryptauthorityx3.crt
Update CA
sudo dpkg-reconfigure ca-certificates
sudo
privileges set up on your server.
- sudo apt-get update
- sudo apt-get install default-jdk
tomcat
user, which will be used to run the Tomcat service.tomcat
group:
- sudo groupadd tomcat
tomcat
user. We’ll make this user a member of the tomcat
group, with a home directory of /opt/tomcat
(where we will install Tomcat), and with a shell of /bin/false
(so nobody can log into the account):
- sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
tomcat
user is set up, let’s download and install Tomcat./tmp
directory on your server. This is a good directory to download ephemeral items, like the Tomcat tarball, which we won’t need after extracting the Tomcat contents:
- cd /tmp
curl
to download the link that you copied from the Tomcat website:
- curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz
/opt/tomcat
directory. Create the directory, then extract the archive to it with these commands:
- sudo mkdir /opt/tomcat
- sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
tomcat
user that we set up needs to have access to the Tomcat installation. We’ll set that up now.
- cd /opt/tomcat
tomcat
group ownership over the entire installation directory:
- sudo chgrp -R tomcat /opt/tomcat
tomcat
group read access to the conf
directory and all of its contents, and execute access to the directory itself:
- sudo chmod -R g+r conf
- sudo chmod g+x conf
tomcat
user the owner of the webapps
, work
, temp
, and logs
directories:
- sudo chown -R tomcat webapps/ work/ temp/ logs/
- sudo update-java-alternatives -l
Output
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
JAVA_HOME
variable can be constructed by taking the output from the last column (highlighted in red) and appending /jre
to the end. Given the example above, the correct JAVA_HOME
for this server would be:
JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
JAVA_HOME
may be different.tomcat.service
in the /etc/systemd/system
directory by typing:
- sudo nano /etc/systemd/system/tomcat.service
JAVA_HOME
if necessary to match the value you found on your system. You may also want to modify the memory allocation settings that are specified in CATALINA_OPTS
:[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
- sudo systemctl daemon-reload
- sudo systemctl start tomcat
- sudo systemctl status tomcat
ufw
firewall enabled currently.8080
to accept conventional requests. Allow traffic to that port by typing:
- sudo ufw allow 8080
:8080
in a web browser:
Open in web browser
http://server_domain_or_IP:8080
- sudo systemctl enable tomcat
tomcat-users.xml
file:
- sudo nano /opt/tomcat/conf/tomcat-users.xml
manager-gui
and admin-gui
(web apps that come with Tomcat). You can do so by defining a user, similar to the example below, between the tomcat-users
tags. Be sure to change the username and password to something secure:<tomcat-users . . .>
<user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
context.xml
files.
- sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
- sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
</Context>
- sudo systemctl restart tomcat
The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...