下載Centos 網址如下
http://isoredirect.centos.org/centos/7/isos/x86_64/
可下載CentOS-7-x86_64-Minimal-2003.iso縮小版大約1GB
安裝VIM&Ifconfig等工具
yum -y update
yum -y install vim
yum -y install net-tools
yum -y install wget
Yum 安裝 Htop:
首先啟用 EPEL Repository:
# yum -y install epel-release
# yum -y update
首用 EPEL Repository 後, 可以用 yum 直接安裝 Htop:
# yum -y install htop
安裝好 Htop 後, 啟動只需執行 “htop” 指令:
# htop
CentOS 7 關閉防火牆及 SELinux
關閉 SELinux:
開啟檔案 /etc/selinux/config:
# vim /etc/selinux/config
找到以下一行:
SELINUX=enforce 改成: SELINUX=disabled
另外將 “SELINUXTYPE=targeted” 加上註釋, 改成這樣:
# SELINUXTYPE=targeted
儲存後離開編輯器, 需要重新開機設定才會生效。
要檢查 SELinux 的狀態, 執行 sestatus 指令便可以看到:
# sestatus
關閉 Firewalld 防火牆:
關閉 Firewalld 防火牆指令:# systemctl stop firewalld.service
設定下次開機不啟動 Firewalld 防火牆
# systemctl disable firewalld.service
在CentOS 6和CentOS 7或CentOS 8上安裝PHP 5.4、5.5、5.6或7.3、7.4版本
1.wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
2.wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
3.rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
如果您原本就已經裝過EPEL則執行下面指令:
1. wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
2. rpm -Uvh remi-release-7*.rpm
安裝Yum-Utils來管理存儲庫
2.安裝yum-utils,它是一組與yum集成的實用程序,以多種方式擴展其本機功能,從而使其更強大且更易於使用。
軟件包yum-utils用於即時啟用或禁用軟件包,而無需任何手動配置。
# yum -y install yum-utils
(本範例使用CentOS 7 安裝 Apache 2.4)
Step 1
安裝Apache及支援https的模組!
| [root@localhost ~]$ sudo yum -y install httpd mod_ssl openssl |
Step 2
啟動Apache及設定開機啟動
| [root@localhost ~]$ sudo systemctl start httpd [root@localhost ~]$ sudo systemctl enable httpd |
Step 3
查詢Apache執行權限
| [root@localhost ~]$ sudo vim /etc/httpd/conf/httpd.conf |
尋找關鍵字『User 』
(尾端加上一個空白鍵)
| # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User apache Group apache |
如此一來,便可確定Apache執行者是apache,想要讓Apache擁有權限的檔案或目錄,就要變更擁有者為apache!
Step 4
設定或修改Apache目錄
| [root@localhost ~]$ sudo vim /etc/httpd/conf/httpd.conf |
尋找『DocumentRoot 』
| # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" |
為了讓Apache可以支援.htaccess,請加入AllowOverride All
搜尋『<directory 』,可能會找到好幾個,要修改的是後方雙引號內容為Apache預設目錄
| <directory "/var/www/html"> AllowOverride All </Directory> |
一般而言,Apache Http Server預設使用80 port,如要修改可搜尋『Listen 80』
| # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80 |
有修改設定的話,記得存檔離開!
安裝各種版本Install PHP 5.4, PHP 5.5 or PHP 5.6 on CentOS 6
以下依據PHP要使用的版本做搭配修改
# yum-config-manager --enable remi-php54 [Intall PHP 5.4]
# yum-config-manager --enable remi-php55 [Intall PHP 5.5]
# yum-config-manager --enable remi-php56 [Intall PHP 5.6]
安裝範例
# yum-config-manager --enable remi-php54 [Intall PHP 5.4]
# yum -y install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
測試案例
在網站目錄放置一個phpinfo.php,內容如下
root@localhost:~$ vim phpinfo.php [Enter]
<?php
phpinfo();
?>
重新啟動Apache
sudo systemctl restart httpd
查詢PHP版本
[root@localhost~]# php --version
Centos 7 官網下載安裝 mysql server 5.6
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum -y install mysql-community-server
安裝成功後重啟mysql服務。
初次安裝mysql,root賬戶沒有密碼。
查看一下狀態
| [root@Localhost ~]$ sudo systemctl status mysqld.service |
初次安裝mysql,root賬戶沒有密碼。
[root@localhost]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.48 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| |
+--------------------+
3 rows in set (0.01 sec) mysql>
設定密碼
mysql> set password for 'root'@'localhost' =password('mypassword'); Query OK, 0 rows affected (0.00 sec) mysql>
不需要重啟資料庫即可生效。
設定開機自動啟動MySQL服務
| [root@localhost ~]$ sudo systemctl enable mysqld |
設定防火牆允許外網存取MySQL服務
(如果系統架構是程式和資料庫都在同一台伺服器,就不需要做這個設定!)
| [root@localhost ~]$ sudo firewall-cmd --zone=public --add-service=mysql |
CentOS 7 安裝 phpMyAdmin 4.0
檢查php, MySQL版本,會牽涉到phpMyAdmin是否能支援!
PHP 5.4 -------->4.0 phpmyadmin
PHP 5.5 -------->4.6 phpmyadmin
https://www.phpmyadmin.net/files/4.0.10.20/
下載
wget https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.tar.gz
解壓縮
| [root@localhost ~]$ sudo tar -xvf phpMyAdmin-4.0.10.20-all-languages.tar.gz |
將phpMyAdmin的根目錄更名,並且移動到你想放置的目錄下
(本範例欲將根目錄更名為phpmyadmin,並且放置到/usr/share/之下)
| [root@localhost ~]$ sudo mv phpMyAdmin-4.0.10.20-all-languages /var/www/html/phpmyadmin |
即可使用!
Centos 擴充空間
第一步 :安裝磁碟工具模組Parted
安裝
sudo yum -y install parted
執行
sudo parted
離開
quit
第二步 : 建立擴充磁區
[root@localhost home]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 51.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 17.2GB 16.1GB primary lvm
3 17.2GB 34.4GB 17.2GB primary lvm
設定磁區指令mkpart
(parted) mkpart
Partition type? primary/extended? p
File system type? [ext2]? xfs
Start? 34.4
End? 51.5gb
Warning: You requested a partition from 34.4MB to 51.5GB (sectors 67187..100585937).
The closest location we can manage is 34.4GB to 51.5GB (sectors 67108864..100663295).
Is this still acceptable to you?
Yes/No? y
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 51.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 17.2GB 16.1GB primary lvm
3 17.2GB 34.4GB 17.2GB primary lvm
4 34.4GB 51.5GB 17.2GB primary
第四磁區建立完成
Control + Z 跳出
第三步 :
(parted) set 4 lvm on 將第4磁區設定為 LVM
# pvcreate /dev/sda4 設定第4磁區
# vgdisplay
# vgextend centos /dev/sda4
[root@localhost home]# vgextend centos /dev/sda4
Volume group "centos" successfully extended
# lvdisplay 秀磁區資訊
# lvextend /dev/centos/root /dev/sda4 合併第4磁區
# df -h
查詢時可能會發現硬碟空間顯示依然是舊的,必須進行重新掃描
xfs 檔案系統:
# xfs_growfs /dev/centos/root
ext4 檔案系統:
# resize2fs /dev/centos/root
# df -h
即可完成擴充!
參考資料1:https://www.opencli.com/linux/centos-7-disable-firewalld-selinux
2.https://www.opencli.com/linux/centos-7-install-htop
3.https://www.cadch.com/modules/news/article.php?storyid=227
4.https://www.tecmint.com/install-php-5-4-php-5-5-or-php-5-6-on-centos-6/
5.https://www.brilliantcode.net/170/centos-7-install-apache-httpd/
6.https://www.brilliantcode.net/262/centos-7-install-phpmyadmin-4-7/
7.https://www.itread01.com/content/1544150958.html
8.https://jsnwork.kiiuo.com/archives/2118/centos-7-%E5%AE%89%E8%A3%9D- apachephp-7mysqlphpmyadminftpssh/
9.https://www.linuxidc.com/Linux/2017-08/146018.htm
10.https://blog.bertello.org/2019/12/resizing-centos-7-disk/
11.https://www.liaohaha.tw/search?updated-max=2020-03-18T22:13:00%2B08:00&max-results=7&start=7&by-date=false
12.https://kenwu0310.wordpress.com/2018/12/17/centos-7-%E5%9C%A8-vsphere-esxi-%E4%B8%AD%E6%93%B4%E5%85%85%E7%A1%AC%E7%A2%9F%E7%A9%BA%E9%96%93-gpt/