linux

Linux LNMP如何进行版本升级

小樊
48
2025-02-23 08:28:48
栏目: 智能运维

在Linux系统上进行LNMP(Linux, Nginx, MySQL/MariaDB, PHP)的版本升级,通常需要分别对每个组件进行更新。以下是详细的升级步骤和注意事项:

Nginx升级

  1. 备份当前配置

    sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
    
  2. 下载新版本: 访问Nginx官方网站获取最新版本号,例如nginx-1.20.1

  3. 编译安装

    cd /usr/local/src
    wget http://nginx.org/download/nginx-1.20.1.tar.gz
    tar -zxvf nginx-1.20.1.tar.gz
    cd nginx-1.20.1
    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module
    make && make install
    
  4. 配置并启动Nginx

    cp /usr/local/nginx/conf/nginx.conf /etc/nginx/nginx.conf
    systemctl restart nginx
    

MySQL/MariaDB升级

  1. 备份数据库

    mysqldump -u root -p all > all_databases.sql
    
  2. 下载新版本: 访问MySQL官方网站获取最新版本号,例如mysql-8.0.26

  3. 编译安装

    cd /usr/local/src
    wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz
    tar -zxvf mysql-8.0.26.tar.gz
    cd mysql-8.0.26
    mkdir mysql-files
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci
    make && make install
    
  4. 配置并启动MySQL

    cp support-files/mysql.server /etc/init.d/mysql
    systemctl start mysql
    systemctl enable mysql
    

PHP升级

  1. 备份当前配置

    cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.backup
    
  2. 下载新版本: 访问PHP官方网站获取最新版本号,例如php-7.4.26

  3. 编译安装

    cd /usr/local/src
    wget http://cn2.php.net/distributions/php-7.4.26.tar.gz
    tar -zxvf php-7.4.26.tar.gz
    cd php-7.4.26
    ./configure --prefix=/usr/local/php --with-mysqlnd --with-openssl --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib --with-iconv --with-mcrypt --with-xmlrpc --with-mbstring --with-zip --enable-mbstring --enable-sockets --enable-soap --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-gettext --with-xsl --with-xmlrpc --enable-json
    make && make install
    
  4. 配置并启动PHP-FPM

    cp /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.backup
    cp /usr/local/php/etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf.backup
    systemctl restart php-fpm
    

注意事项

  1. 备份数据:在进行任何升级操作之前,请确保所有重要数据已备份。
  2. 测试环境:在生产环境进行升级前,建议在测试环境中先进行升级和测试。
  3. 文档查阅:查阅相关软件的官方文档,以获取更详细的升级指南和注意事项。

以上步骤和注意事项为一般性指导,具体操作可能会因Linux发行版和版本的不同而有所差异。在执行升级操作时,请参考相应发行版的官方文档或寻求专业人士的帮助。

0
看了该问题的人还看了