Ubuntu Server Installation

by Little Bear @26 พ.ค. 64 13:02 ( IP : 171...205 ) | Tags : Ubuntu , Let's Encrypt , PhpMyAdmin , PHP , Server

ติดตั้ง Server ใหม่ของ Ubuntu Server เขียนบันทึกคำสั่งไว้สักหน่อย

Apache Installation

sudo apt update
sudo apt upgrade

sudo apt install apache2 -y
systemctl status apache2

sudo a2dismod ssl
sudo a2enmod ssl
sudo a2enmod rewrite

Apache config

sudo nano /etc/apache2/sites-available/000-default.conf

เพิ่ม AllowOverride Al

<Directory /home/>
        Options Indexes FollowSymLinks
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted

sudo apt-get install mariadb-server mariadb-client
systemctl status mariadb

sudo nano /etc/mysql/conf.d/mysqld.cnf sudo systemctl restart mysql

debian : service mysqld restart

กรณีที่ติดตั้ง mariadb แล้วไม่ได้กำหนดรหัสของ root

mysql --version

systemctl stop mariadb systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking" systemctl start mariadb mysql -u root

mysql> FLUSH PRIVILEGES; mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD("newpassword"); mysql> quit

sudo systemctl unset-environment MYSQLD_OPTS sudo systemctl restart mariadb

mysql -u root -p

mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

#MySql Config

ตรวจสอบว่าควรกำหนดค่า keybuffersize สักเท่าไหร่ดี

    -> IF(PowerOf1024<0,0,IF(PowerOf1024>3,0,PowerOf1024)))+0.4999),
    -> SUBSTR(' KMG',IF(PowerOf1024<0,0,
    -> IF(PowerOf1024>3,0,PowerOf1024))+1,1))
    -> recommendedkeybuffersize FROM
    -> FROM (SELECT SUM(indexlength) KBS1
    -> FROM informationschema.tables
    -> WHERE engine='MyISAM' AND
    -> tableschema NOT IN ('information_schema','mysql')) AA ) A,
    -> (SELECT 2 PowerOf1024) B;

name /etc/my.cnf
 <a class="hashtag" href="/tags/MyISAM">#MyISAM</a>
join_buffer_size=256K  # from 140M for row pointers
thread_cache_size=40  # from 8 to avoid thread starvation
query_cache_limit=8M  # from 4M since you have QC turned OFF
key_cache_age_threshold=7200  # from 300 seconds to reduce key_reads RPS
key_cache_division_limit=50  # from 100 percent for HOT/WARM caches
key_cache_block_size=16K  # from 1K to evict bigger block when full
open_files_limit=30000  # from 1024 to reduce opened_files RPS
table_open_cache=10000  # from 407 to reduce opened_tables RPS
table_definition_cache=2000  # from 603 to reduce opened_table_definitions RPS
max_heap_table_size=48M  # from 32M  for additional capacity
tmp_table_size=48M  # from 32M to reduce created_tmp_disk_tables count
innodb_io_capacity=1600  # from 200 to allow more IOPS
read_rnd_buffer_size=192K  # from 256K to reduce handler_read_rnd_next RPS
sort_buffer_size=2M  # from 256K to reduce sort_merge_passes count

 <a class="hashtag" href="/tags/Innodb">#Innodb</a>
<a class="hashtag" href="/tags/innodb">#innodb</a>_buffer_pool_size = 6144M
innodb_log_file_size = 512M
innodb_lru_scan_depth=100  # from 1024 to reduce CPU busy every SE$

max_connections = 500
key_buffer_size = 512M

ติดตั้ง PHP => How to install PHP 7.4 on Ubuntu 22.04 LTS Jammy Linux

sudo apt update && sudo apt upgrade
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y

sudo apt install php7.4
sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}

sudo update-alternatives --config php

sudo apt-get install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4

sudo nano /etc/php/7.4/fpm/php.ini

sudo systemctl restart apache2
sudo systemctl restart mysql

wget -r --ask-password ftp://user:example.com/

Install phpMyAdmin

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

Mount volumn จาก server เดิม มาไว้ใน server ใหม่ เพื่อทำการ copy file

sudo apt install sshfs

mkdir folder
sshfs -p 22 username@example.com:/home/folder/ folder

ใช้งานเสร็จก็ un mount

umount folder



Relate topics