Article Migrer facilement de CentOS à Rocky

Migrer facilement de CentOS à Rocky

Nous avons découvert dans un précédent article qu’il existait une alternative à CentOS: Rocky Linux.
Nous allons maintenant voir un script réalisé par la communauté, disponible sur GitHub qui permet de migrer en douceur un serveur depuis CentOS vers Rocky Linux.
Pour les besoins de cet article je vais partir d’une installation de CentOS 8 sur laquelle nous allons déployer un serveur web, PHP ainsi qu’une base de données maria. Puis nous utiliserons le script pour migrer notre OS vers Rocky, et regarderons si tout fonctionne comme attendu.

Notre serveur

Nous allons utiliser une machine virtuelle sur laquelle nous avons installé CentOS 8. Sur notre système nous avons déployé un serveur LAMP complet. Voici les différentes commandes entrées suite à l’installation de notre serveur :

Mise à jour du système et installation de nos prérequis

# Installation des paquets systèmes
#mise à jour
[root@centos8]# dnf makecache
[root@centos8]# dnf update -y
#outillage
[root@centos8]# dnf install htop iftop nmon -y
[root@centos8]# dnf install epel-release -y
#serveur web et PHP
[root@centos8]# dnf install httpd php -y
#serveur de base de données
[root@centos8]# dnf install mariadb mariadb-server -y
#ajout des modules php pour WordPress
[root@centos8]# dnf install php-cli php-json php-gd php-mbstring php-pdo php-xml php-mysqlnd php-pecl-zip wget policycoreutils-python-utils -y
# configuration des services et du pare-feu
[root@centos8]# systemctl enable --now httpd
[root@centos8]# systemctl enable --now php-fpm
[root@centos8]# systemctl enable --now mariadb
[root@centos8]# firewall-cmd --add-service=http --permanent
[root@centos8]# firewall-cmd --reload

Création de la base de données pour notre site web WordPress

[root@centos8]# mysql -u root -p
#il s'agit d'une installation par défaut il n'y a donc pas de password (do not try this at home)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'secret';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> quit
Bye

Téléchargement et installation de l’archive WordPress

[root@centos8]# cd /var/www
[root@centos8]# wget https://wordpress.org/latest.tar.gz
# décompression de l'archive
[root@centos8]# tar zxvf latest.tar.gz
# On vérifie la présence de notre dossier wordpress qui a dû se créer suite à la décompression de l'archive
[root@centos8]# ls -l
total 15388
drwxr-xr-x. 2 root   root          6  4 nov.   2020 cgi-bin
drwxr-xr-x. 2 root   root          6  4 nov.   2020 html
-rw-r--r--. 1 root   root   15750424 13 mai   01:50 latest.tar.gz
drwxr-xr-x. 5 nobody nobody     4096 13 mai   01:49 wordpress
# Suppression de l'archive qui n'est plus nécessaire
rm latest.tar.gz
#on donne les droits à apache sur le dossier WordPress
[root@centos8]# chown -Rf apache:apache ./wordpress/
[root@centos8]# chmod -Rf 775 ./wordpress/
#correction du contexte selinux pour WordPress
[root@centos8]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/wordpress(/.*)?"
[root@centos8]# restorecon -Rv /var/www/wordpress

Configuration du serveur apache

On commence par éditer le fichier /etc/httpd/conf.d/wordpress.conf, et l’on colle dedans la configuration suivante :

<VirtualHost *:80>
  ServerAdmin root@localhost
  DocumentRoot /var/www/wordpress
  <Directory "/var/www/wordpress">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
  </Directory>
  ErrorLog /var/log/httpd/wordpress_error.log
  CustomLog /var/log/httpd/wordpress_access.log common
</VirtualHost>

Puis on redémarre apache pour activer notre nouvelle configuration :

[root@centos8]# systemctl restart httpd

Installation et configuration de WordPress

Pour cela on utilise notre navigateur web pour nous rendre sur l’adresse IP du serveur. Puis on se laisse guider par le wizzard :

Avant de migrer vers Rocky Linux

A ce stade nous avons donc un serveur hébergeant une application web avec une base de données et quelques modules php utilisés. Nous allons donc voir ce qui se passe lors de la migration vers Rocky Linux.
Avant d’aller plus loin voici un aperçu de nos informations système :

Le script que nous allons utiliser se trouve sur le repos GitHub suivant: Rocky Tools.
Avant de l’utiliser on se place à la racine du compte root et on le télécharge :

[root@centos8]# cd /root
[root@centos8]# wget https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/centos2rocky.sh
[root@centos8]# chmod +x centos2rocky.sh

Migration vers Rocky Linux

Le processus de migration est très simple, il suffit de lancer le script :

[root@centos8]# ./centos2rocky.sh

Voici un petit aperçu de la sortie du script dans le cas de notre serveur :

Ensuring rpm and yum are here.
Ensuring your version of CentOS is supported
Finding our modules that are enabled

There are some modules that are unsure of how to handle. This normally shouldn t happen. Do you want to resolve this yourself (Yes) or continue (No)?
1) Yes
2) No
#? 2
~/release ~
warning: rocky-gpg-keys-8.3-13.el8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 6d745a60: NOKEY
Verifying...                          ########################################
Preparing...                          ########################################
Updating / installing...
rocky-gpg-keys-8.3-13.el8             ########################################
rocky-release-8.3-13.el8              ########################################
rocky-repos-8.3-13.el8                ########################################
Removing dnf cache
Ensuring repos are enabled before the package swap
Rocky Linux 8 - AppStream                       8.0 MB/s | 6.7 MB     00:00
Rocky Linux 8 - BaseOS                          2.6 MB/s | 2.5 MB     00:00
Rocky Linux 8 - Extras                          1.5 kB/s | 1.6 kB     00:01
...
  Reinstalling     : libXpm-3.5.12-8.el8.x86_64                        273/1315
  Reinstalling     : libXt-1.1.5-12.el8.x86_64                         274/1315
  Reinstalling     : libXmu-1.1.3-1.el8.x86_64                         275/1315
  Reinstalling     : libXrandr-1.5.2-1.el8.x86_64                      276/1315
  Reinstalling     : libXinerama-1.1.4-1.el8.x86_64                    277/1315
  Reinstalling     : libXcursor-1.1.15-3.el8.x86_64                    278/1315
  Reinstalling     : libXdamage-1.1.4-14.el8.x86_64                    279/1315
  Reinstalling     : libXxf86misc-1.0.4-1.el8.x86_64                   280/1315
  Reinstalling     : xorg-x11-server-utils-7.7-27.el8.x86_64           281/1315
  Reinstalling     : libXcomposite-0.4.4-14.el8.x86_64                 282/1315
  Reinstalling     : libglvnd-glx-1:1.2.0-6.el8.x86_64                 283/1315
  Reinstalling     : mesa-libGL-20.1.4-1.el8.x86_64                    284/1315
  Reinstalling     : libXaw-1.0.13-10.el8.x86_64                       285/1315
  Reinstalling     : libXtst-1.2.3-7.el8.x86_64                        286/1315
  Reinstalling     : libXv-1.0.11-7.el8.x86_64                         287/1315
  Reinstalling     : libXxf86dga-1.1.5-1.el8.x86_64                    288/1315
  Reinstalling     : libdmx-1.1.4-3.el8.x86_64                         289/1315
  Reinstalling     : adobe-mappings-pdf-20180407-1.el8.noarch          290/1315
  Downgrading      : linux-firmware-20200619-101.git3890db36.el8.no    291/1315
  Downgrading      : dbus-common-1:1.12.8-12.el8.noarch                292/1315
  Reinstalling     : cyrus-sasl-lib-2.1.27-5.el8.x86_64                293/1315
  Running scriptlet: cyrus-sasl-lib-2.1.27-5.el8.x86_64                293/1315
  Reinstalling     : platform-python-pip-9.0.3-18.el8.noarch           294/1315
  Reinstalling     : platform-python-setuptools-39.2.0-6.el8.noarch    295/1315
...
  Cleanup          : libgcc-8.3.1-5.1.el8.x86_64                      1315/1315
  Running scriptlet: libgcc-8.3.1-5.1.el8.x86_64                      1315/1315
  Running scriptlet: filesystem-3.8-3.el8.x86_64                      1315/1315
  Running scriptlet: glibc-all-langpacks-2.28-127.el8.2.x86_64        1315/1315
  Running scriptlet: crypto-policies-scripts-20210209-1.gitbfb6bed.   1315/1315
  Running scriptlet: ca-certificates-2020.2.41-80.0.el8_2.noarch      1315/1315
  Running scriptlet: kernel-core-4.18.0-240.22.1.el8.x86_64           1315/1315
Failed to add dependency on unit, unit systemd-ask-password-plymouth.service does not exist.

  Running scriptlet: libwbclient-4.12.3-14.el8.x86_64                 1315/1315
  Running scriptlet: kmod-kvdo-6.2.3.114-74.el8.x86_64                1315/1315
Failed to add dependency on unit, unit systemd-ask-password-plymouth.service does not exist.
Failed to add dependency on unit, unit systemd-ask-password-plymouth.service does not exist.
Failed to add dependency on unit, unit systemd-ask-password-plymouth.service does not exist.

  Running scriptlet: urw-base35-bookman-fonts-20170801-10.el8.noarc   1315/1315
  Running scriptlet: urw-base35-c059-fonts-20170801-10.el8.noarch     1315/1315
  Running scriptlet: urw-base35-d050000l-fonts-20170801-10.el8.noar   1315/1315
  Running scriptlet: urw-base35-gothic-fonts-20170801-10.el8.noarch   1315/1315
  Running scriptlet: urw-base35-nimbus-mono-ps-fonts-20170801-10.el   1315/1315
  Running scriptlet: urw-base35-nimbus-roman-fonts-20170801-10.el8.   1315/1315
  Running scriptlet: urw-base35-nimbus-sans-fonts-20170801-10.el8.n   1315/1315
  Running scriptlet: urw-base35-p052-fonts-20170801-10.el8.noarch     1315/1315
  Running scriptlet: urw-base35-standard-symbols-ps-fonts-20170801-   1315/1315
  Running scriptlet: urw-base35-z003-fonts-20170801-10.el8.noarch     1315/1315
  Running scriptlet: authselect-libs-1.2.1-2.el8.x86_64               1315/1315
  Running scriptlet: httpd-2.4.37-30.module+el8.3.0+124+cde66633.x8   1315/1315
  Running scriptlet: rocky-logos-83.0-3.el8.x86_64                    1315/1315
  Running scriptlet: sssd-common-2.3.0-9.el8.x86_64                   1315/1315
  Running scriptlet: tuned-2.14.0-3.el8.2.noarch                      1315/1315
  Running scriptlet: microcode_ctl-4:20200609-2.20210216.1.el8.x86_   1315/1315
...
 xfsprogs-5.0.0-4.el8.x86_64
  xkeyboard-config-2.28-1.el8.noarch
  xmlsec1-1.2.25-4.el8.x86_64
  xmlsec1-openssl-1.2.25-4.el8.x86_64
  xorg-x11-font-utils-1:7.5-40.el8.x86_64
  xorg-x11-fonts-ISO8859-1-100dpi-7.5-19.el8.noarch
  xorg-x11-server-utils-7.7-27.el8.x86_64
  xorg-x11-utils-7.5-28.el8.x86_64
  xz-5.2.4-3.el8.x86_64
  xz-libs-5.2.4-3.el8.x86_64
  yum-4.2.23-4.el8.noarch
  zip-3.0-23.el8.x86_64

Complete!
~
Generating grub configuration file ...
Adding boot menu entry for EFI firmware configuration
done
Last metadata expiration check: 0:02:28 ago on Wed 26 May 2021 05:02:34 PM CEST.
Unable to resolve argument
Error: Problems in request:
missing groups or modules:

On constate que le script se termine sur une erreur. Voyons ce qu’on trouve après le redémarrage de notre serveur:

  1. au démarrage on constate une entrée supplémentaire dans notre grub

2. ensuite on arrive sur une invite de console qui a bien changée :

3. On termine en lançant notre script qui nous permet d’identifier le système :

Vérifications post migration

Quand nous étions sous CentOS nous avions déployé un site web WordPress vérifions donc si les services sont toujours fonctionnels, si la configuration du pare-feu est toujours bonne, et surtout si notre site est toujours accessible/fonctionnel.

  1. Vérification de nos services:
    On commence par regarder si nos services sont bien démarrés
# Apache
[root@centos8]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           └─php-fpm.conf
   Active: active (running) since Wed 2021-05-26 17:06:17 CEST; 24min ago
     Docs: man:httpd.service(8)
 Main PID: 1071 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 12107)
   Memory: 29.8M
   CGroup: /system.slice/httpd.service
           ├─1071 /usr/sbin/httpd -DFOREGROUND
           ├─1147 /usr/sbin/httpd -DFOREGROUND
           ├─1148 /usr/sbin/httpd -DFOREGROUND
           ├─1157 /usr/sbin/httpd -DFOREGROUND
           └─1159 /usr/sbin/httpd -DFOREGROUND

mai 26 17:06:16 centos8.local systemd[1]: Starting The Apache HTTP Server...
mai 26 17:06:17 centos8.local httpd[1071]: AH00558: httpd: Could not reliably determine the server s fully qualified domain name,>
mai 26 17:06:17 centos8.local systemd[1]: Started The Apache HTTP Server.
mai 26 17:06:17 centos8.local httpd[1071]: Server configured, listening on: port 80
#Mariadb
[root@centos8]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-26 17:06:18 CEST; 24min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 1467 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 1118 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
  Process: 1073 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 1379 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 12107)
   Memory: 107.0M
   CGroup: /system.slice/mariadb.service
           └─1379 /usr/libexec/mysqld --basedir=/usr

mai 26 17:06:16 centos8.local systemd[1]: Starting MariaDB 10.3 database server...
mai 26 17:06:17 centos8.local mysql-prepare-db-dir[1118]: Database MariaDB is probably initialized in /var/lib/mysql already, not>
mai 26 17:06:17 centos8.local mysql-prepare-db-dir[1118]: If this is not the case, make sure the /var/lib/mysql is empty before r>
mai 26 17:06:17 centos8.local mysqld[1379]: 2021-05-26 17:06:17 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) starting as>
mai 26 17:06:18 centos8.local systemd[1]: Started MariaDB 10.3 database server.
#php-fpm
[root@centos8]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-26 17:06:17 CEST; 24min ago
 Main PID: 1068 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 12107)
   Memory: 33.8M
   CGroup: /system.slice/php-fpm.service
           ├─1068 php-fpm: master process (/etc/php-fpm.conf)
           ├─1132 php-fpm: pool www
           ├─1133 php-fpm: pool www
           ├─1134 php-fpm: pool www
           ├─1135 php-fpm: pool www
           └─1136 php-fpm: pool www

mai 26 17:06:16 centos8.local systemd[1]: Starting The PHP FastCGI Process Manager...
mai 26 17:06:17 centos8.local systemd[1]: Started The PHP FastCGI Process Manager.

On peut donc constater que nos services ont bien été migré et sont toujours démarrés correctement suite au redémarrage de notre serveur.

  1. Vérification de la configuration du pare-feu
[root@centos8 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens32
  sources:
  services: cockpit dhcpv6-client http ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Ici aussi on constate que notre firewall a bien conservé la configuration que nous avions réalisée sur la machine CentOS.

  1. Notre site est-il toujours accessible et fonctionnel?

Pour cela on utilise notre navigateur web et on se rend à l’adresse du site :

Conclusion

Comme nous avons pu le voir au cours de cet article, et malgré quelques erreurs remontées par le script de migration, nous avons donc réussi à passer de CentOS 8 à Rocky Linux sans réinstaller tout le système ou installer un nouveau serveur.
Nous pouvons dire que nous avons là une solution élégante et simple pour migrer rapidement des serveurs sous centos8 vers un OS ayant un support plus étendu dans la durée.

Infogérance AWS
Partage
Laisser un commentaire

Inscrivez-vous à la newsletter Syloé !

Recevez gratuitement les analyses de nos experts