Skip to content

oliguo/Server-Deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Server Deployment

LAMPP here

XAMPP here

Docker here

Change Server Time

sudo apt-get install ntp

then,edit file

sudo nano /etc/ntp.conf

add below:

server ntp.ubuntu.com
server pool.ntp.org

restart

sudo service ntp stop
sudo service ntp start

Check server time and set timezone:

sudo dpkg-reconfigure tzdata

will show:

Current default time zone: 'Asia/Hong_Kong'
Local time is now:      Wed Feb 22 20:16:02 HKT 2017.
Universal Time is now:  Wed Feb 22 12:16:02 UTC 2017.

Check File/Folder Size

df -h /path/xxx
du -sh xxxx.file
#list file maximun size
du -lh --max-depth=1 --block-size=M | sort -nr

Rename,Copy file/folder

*rename
mv old.file new file

*if move file to some directory
mv /path/a.file /target/a.file

*copy
cp -r /path/folder/xxx /target/folder/xxx

*Recursive, Non-Overwriting File Copy
sudo cp -vnpr /xxx/* /yyy

xxx = source

yyy = destination

v = verbose

n = no clobber (no overwrite)

p = preserve permissions

r = recursive

Server BandWidth Speed Test

reference here

*speedtest
wget -O speedtest-cli-newest https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
sudo chmod +x speedtest-cli-newest
sudo ./speedtest-cli-newest

Locale Language Setting

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_MESSAGES = "zh_CN.UTF-8",
    LANG = "zh_CN.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Then exec:

sudo apt-get install localepurge

Choose en_US.UTF-8,if want change again and print it to check:

sudo dpkg-reconfigure localepurge
sudo locale-gen en_US.UTF-8

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

Or mapping local locate to server like below:

LC_ALL=en_US.UTF-8 ssh name@host

External Package

reference here

Use the --remove flag, similar to how the PPA was added:

sudo add-apt-repository --remove ppa:whatever/ppa

As a safer alternative, you can install ppa-purge:

sudo apt-get install ppa-purge

And then remove the PPA, downgrading gracefully packages it provided to packages provided by official repositories:

sudo ppa-purge ppa_name

Note that this will uninstall packages provided by the PPA, but not those provided by the official repositories. If you want to remove them, you should tell it to apt:

sudo apt-get purge package_name

You can also remove PPAs by deleting the .list files from /etc/apt/sources.list.d directory.

Check Services or Ports,then Stop and Remove

*service
service --status-all
sudo service xxxx stop
sudo apt-get remove xxx
sudo apt-get --purge remove xxx
*port
sudo netstat -tunap | grep LISTEN
sudo kill xxxx

How To Add Swap

# cat /proc/sys/vm/swappiness 
# 60 

it means the memory is over 40(100-60) then will use the swap, 
but it will make the disk I/O frequently, 
suggest to change to over 90 then we use swap

# sudo nano /etc/sysctl.conf
---
vm.swappiness = 10
---
# sudo sysctl -p

1.check swap:

sudo swapon -s

and:

free -m

2.create what you want memory for swap

sudo fallocate -l 4G /swapfile  

3.check swapfile

ls -lh /swapfile

4.enable swapfile

sudo chmod 600 /swapfile

5.check again

ls -lh /swapfile

6.next setup

sudo mkswap /swapfile

sudo swapon /swapfile

7.check it

sudo swapon -s

free -m

8.make it permanent

sudo nano /etc/fstab

add bottom:

/swapfile   none    swap    sw    0   0

Helpful visual to check traffic

sudo apt-get install slurm

slurm -s -i eth0

Mount the drive

Reference 1

Reference 2

list the drives

$ fdisk -l

example result

root@abcd:~# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6c740fc2

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886046 83883999  40G 83 Linux


Disk /dev/vdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

To mount the drive:/dev/vdb

$ fdisk /dev/vdb

following the steps

root@abcd:~# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xaa3faf38.

Command (m for help): n ->Here
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p ->Here
Partition number (1-4, default 1): 1
First sector (2048-xxx, default 2048): ->click 'enter;
Last sector, +sectors or +size{K,M,G,T,P} (2048-xxx, default xxx): ->click 'enter;

Created a new partition 1 of type 'Linux' and of size 40 GiB.

Command (m for help): wq ->Here
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

list the drive

$ fdisk -l

format the drive

$ mkfs.ext3 /dev/vdb1  

create mount folder

$ mkdir /data_drive_0

automatic mount at boot time

$ echo '/dev/vdb1 /data_drive_0 ext3 defaults 0 0' >> /etc/fstab 

mount all drive

$ mount -a

view the mounted list

$ df -h
-> /dev/vdb1      39G   73M  39G   1% /data_drive_0

Log htop log

ps auxf > `date +\%Y\%m\%d\%H\%M\%S`.csv

Apache && PHPMyAdmin setting

php.ini, upload size

max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M
post_max_size = 750M
upload_max_filesize = 750M

phpmyadmin/libraries/config.default.php, timeout limit

$cfg['ExecTimeLimit'] = 0;

resize ubuntu disk

ref: 
https://arstech.net/resize-linux-partition-command-line/
https://community.spiceworks.com/topic/2325763-how-can-i-make-ubuntu-vg-ubuntu-lv-consume-the-entire-disk-space-available

sudo fdisk -l

take snapshot or back whole disk first

sudo fdisk /dev/sda

1.type: p
2.type: d
3.remove /dev/sda3 by type 3
4.type: n
5.add new /dev/sda3 by type 3
6.type default enter for First sector,Last sector
7.type: w
8.sudo reboot
9.sudo pvresize /dev/sda3
10.sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
11.sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
12.sudo reboot