內容選單標籤

2020年12月4日 星期五

CentOS8 vsftp、Apache、php、MariaDB

 此篇已經重新謄錄完成!!

可以作廢。



||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| vsftpd |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

# dnf list -h

# dnf list | grep vsftpd
vsftpd.x86_64                                        3.0.3-31.el8                                     AppStream


# dnf -y install vsftpd
...
已安裝:
logrotate-3.14.0-3.el8.x86_64                   vsftpd-3.0.3-31.el8.x86_64         完成!


# dnf list installed | grep vsftpd
vsftpd.x86_64                        3.0.3-31.el8

# rpm -qa | grep vsftpd
vsftpd-3.0.3-32.el8.x86_64



# vi /etc/vsftpd/vsftpd.conf
...
chroot_local_user=YES
...


# ls /usr/sbin | grep vsftpd
vsftpd


# ls /usr/lib/systemd/system | grep vsftpd
vsftpd.service
vsftpd@.service
vsftpd.target


# ls /etc/vsftpd
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh


# ls /var/ftp
pub



# systemctl | grep vsftpd
# systemctl status vsftpd
# systemctl start vsftpd.service
# systemctl enable vsftpd.service


# systemctl status vsftpd
# ps -aux | grep vsftpd




# firewall-cmd --state
running

# firewall-cmd --get-zones
block dmz drop external home internal public trusted work

# firewall-cmd --get-active-zone
public
  interfaces: ens33

# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources:
  services: cockpit dhcpv6-client ssh
...

# firewall-cmd --get-services | grep ftp    //沒有 vsftpd
... ftp ...tftp tftp-client ...


# firewall-cmd --permanent --zone=public --add-service=ftp
success


# firewall-cmd --reload

# firewall-cmd --zone=public --list-all
public (active)
...
  services: cockpit dhcpv6-client ftp ssh




# getsebool -a | grep ftp*
...

# setsebool -P ftpd_full_access on
# setsebool -P tftp_home_dir on




# useradd s306
# passwd s306

# cat /etc/group
...
s306:x:1000:

# cat /etc/passwd
...
s306:x:1000:1000::/home/s306:/bin/bash

# cat /etc/shadow
...
s306:$6$q5YHBgD77s9Och3S$LQvTtYegLZOJSjqoc7jsssC0NY/9z8AcZm5E0dysTZ9LZZLzVmStgdMsYUhkhbYk87g9rOptU1H/E9G9lwxmR0:18602:0:99999:7:::



# ls -l /home
drwx------. 2 s306 s306 62 12月  6 09:01 s306

# id s306
uid=1000(s306) gid=1000(s306) groups=1000(s306)





# su -l s306
$ mkdir {01..40}
$ ls

$ su
密碼:
# cd
#

# lsattr /home
-------------------- /home/s306
# chattr +a -R /home/s306
# lsattr /home
-----a-------------- /home/s306



ftp://s306@192.168.1.100/40        //測試是否可以正常ftp 及 新增檔案


# ps aux | grep s306
root        9712  0.0  0.1 334996  6276 pts/0    S    15:01   0:00 su -l s306
s306        9713  0.0  0.1 232912  3872 pts/0    S    15:01   0:00 -bash
root        9802  0.0  0.0 221896  1068 pts/0    S+   15:12   0:00 grep --color=auto s306



# kill  -9 1394    //送出 kill ,訊號9,強制結束該行程     //??pietty 連線會中斷

# chattr -a -R /home/s306


# userdel -rf s306
# cat /etc/group
# cat /etc/passwd
# cat /etc/shadow
# ls -l /home

# dnf -y remove vsftpd









||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Apache ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 



# dnf list | grep httpd
...
httpd.x86_64                                         2.4.37-30.module_el8.3.0+561+97fdbbcc            @AppStream
...


# dnf -y install httpd
...
已安裝:
 httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64
 ...


# dnf list installed grep httpd
已安裝軟體包
...
httpd.x86_64   2.4.37-30.module_el8.3.0+561+97fdbbcc    @AppStream



# ls /usr/sbin | grep httpd
httpd

# ls /usr/lib/systemd/system | grep httpd
httpd.service
httpd@.service
httpd.service.d
httpd.socket
httpd.socket.d

# ls /etc/httpd/conf
httpd.conf  magic

# ls /var/www
cgi-bin  html



# systemctl start httpd.service

# systemctl enable httpd.service

# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled>
   Active: active (running) since Sun 2020-12-13 16:19:06 CST; 24>
...



# ps -aux | grep httpd
...
apache      1893  0.0  0.2 294188  8484 ?        S    16:19   0:00 /usr/sbin/httpd -DFOREGROUND
apache      1894  0.0  0.3 1810712 12324 ?       Sl   16:19   0:00 /usr/sbin/httpd -DFOREGROUND
apache      1896  0.0  0.4 1941848 16412 ?       Sl   16:19   0:00 /usr/sbin/httpd -DFOREGROUND
apache      1907  0.0  0.3 1810712 12324 ?       Sl   16:19   0:00 /usr/sbin/httpd -DFOREGROUND





# firewall-cmd --get-services | grep http
...
availability http https imap imaps ipp
...


# firewall-cmd --get-zones
block dmz drop external home internal public trusted work

# firewall-cmd --get-active-zone
public


# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources:
  services: cockpit dhcpv6-client ftp ssh
...

# firewall-cmd --permanent --zone=public --add-service=http
success


# firewall-cmd --reload
success
# firewall-cmd --zone=public --list-all           public (active)
 ...
  services: cockpit dhcpv6-client ftp http ssh
...


HostOS
http://192.168.1.100/



# vi /var/www/html/01.html
This page is on /var/www/html ...

http://192.168.1.100/01.html
This page is on /var/www/html ...



-----------------------------
----------------------------- 設定虛擬目錄 Alias -----------------------------
-----------------------------

////////////////////////////////////////////////////////系統目錄下
# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr


# mkdir /opt/web

# vi /opt/web/02.html
This page is on /opt/web ...

 

# ls -l /
...
drwxr-xr-x.   2 root root    6 12月 12 15:19 home
...
drwxr-xr-x.   3 root root   17 12月 13 16:47 opt
...


# ls -l /opt
drwxr-xr-x. 2 root root 21 12月 13 16:48 web

# ls -l /opt/web
-rw-r--r--. 1 root root 29 12月 13 16:48 02.html





# vi /etc/httpd/conf/httpd.conf
...    //最後加上
Alias /opt_web /opt/web
<Directory /opt/web>
        Require all granted
</Directory>   



# systemctl restart httpd.service

http://192.168.1.100/opt_web/02.html
This page is on /opt/web ...



//////////////////////////////////////////////////////// home目錄下

# mkdir /home/web

# vi /home/web/03.html
This page is on /home/web ...

# ls -l /
...
drwxr-xr-x.   3 root root   17 12月 13 17:06 home
...

# ls -l /home
drwxr-xr-x. 2 root root 21 12月 13 17:07 web

# ls -l /home/web
-rw-r--r--. 1 root root 30 12月 13 17:07 03.html



# vi /etc/httpd/conf/httpd.conf
...
Alias /home_web /home/web
<Directory /home/web>
        Require all granted
</Directory>


# systemctl restart httpd.service


http://192.168.1.100/home_web/03.html
Forbidden
You don't have permission to access this resource.





# tail -1 /var/log/httpd/error_log
[Sun Dec 13 17:17:59.229269 2020] [core:error] [pid 2902:tid 139709336037120] (13)Permission denied: [client 192.168.1.105:65439] AH00132: file permissions deny server access: /home/web/03.html


# man ls
...
-Z, --context
              print any security context of each file
...



# ls -Z /var/www
system_u:object_r:httpd_sys_content_t:s0 html

# ls -Z /var/www/html
unconfined_u:object_r:httpd_sys_content_t:s0 01.html


# ls -Z /opt
unconfined_u:object_r:usr_t:s0 web

# ls -Z /opt/web
unconfined_u:object_r:usr_t:s0 02.html

# ls -Z /home
unconfined_u:object_r:user_home_dir_t:s0 web

# ls -Z /home/web
unconfined_u:object_r:user_home_t:s0 03.html

# chcon -t httpd_sys_content_t /home/web

# ls -Z /home
unconfined_u:object_r:httpd_sys_content_t:s0 web

# ls -Z /home/web
unconfined_u:object_r:user_home_t:s0 03.html

# chcon -t httpd_sys_content_t /home/web/03.html

# ls -Z /home/web
unconfined_u:object_r:httpd_sys_content_t:s0 03.html


http://192.168.1.100/home_web/03.html
This page is on /home/web ...


# vi /home/web/04.html
This page is on /home/web TOO ....

# ls -Z /home/web
unconfined_u:object_r:httpd_sys_content_t:s0 03.html
unconfined_u:object_r:httpd_sys_content_t:s0 04.html




http://192.168.1.100/home_web/04.html
This page is on /home/web TOO ....



@@@ 若要在 /home 下建立網站虛擬目錄,先
 
# chcon -t httpd_sys_content_t /home/web

再建立網頁,就不須再變更各網頁





-----------------------------
----------------------------- UserDir個人網頁 -----------------------------
-----------------------------

# dnf -y install httpd
# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service


# firewall-cmd --get-active-zone
public
  interfaces: ens33

# firewall-cmd --zone=public --list-all
public (active)
  ...
  services: cockpit dhcpv6-client ssh
...

# firewall-cmd --permanent --zone=public --add-service=http
success

# firewall-cmd --reload
success

# firewall-cmd --zone=public --list-all
public (active)
  ...
  services: cockpit dhcpv6-client http ssh



http://172.31.145.99/






# useradd kk1
# passwd kk1

# mkdir /home/kk1/public_html


****************************************************
//使用者家目錄的參考,建立 /etc/skel/public_html 這個目錄,那麼未來新增使用者後,在他的家目錄下就會有 public_html 那個目錄了

# mkdir /etc/skel/public_html
# ls /etc/skel/
public_html

# useradd kk1
# passwd kk1

****************************************************


# ls -l /home/
drwx------. 3 kk1 kk1 81 12月 14 23:17 kk1

# chmod 711 /home/kk1
# ls -l /home/
drwx--x--x. 3 kk1  kk1  81 12月 18 13:51 kk1


# ls -l /home/kk1
drwxr-xr-x. 2 root root 6 12月 14 23:17 public_html


# vi /home/kk1/public_html/index.html
This page is on /home/kk1/public_html...


# vi /etc/httpd/conf.d/userdir.conf
...
#    UserDir disabled
...
    UserDir public_html
...


# systemctl restart httpd.service


http://172.31.145.99/~kk1
Forbidden
You don't have permission to access this resource.


# tail -1 /var/log/httpd/error_log
[Fri Dec 18 13:58:02.211753 2020] [core:error] [pid 10084:tid 139974091257600] (13)Permission denied: [client 172.31.145.100:50148] AH00035: access to /~kk1 denied (filesystem path '/home/kk1/public_html') because search permissions are missing on a component of the path


# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      31


//Enforcing:SELinux 正在執行; Permissive :臨時關閉; 如果是 Disabled, 即已經關閉
# getenforce
Enforcing

# setenforce 0

# getenforce
Permissive


****************************************************
永久關閉 SELinux
# vi /etc/sysconfig/selinux
...
#SELINUX=enforcing
SELINUX=disabled

儲存檔案後重新啟動系統便會永久關閉 SELinux
****************************************************


http://172.31.145.99/~kk1/
This page is on /home/kk1/public_html...

由此可知是SELinux

再將 SELinux 執行
# setenforce 1
# getenforce
Enforcing


# getsebool -a | grep httpd
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
...

# setsebool -P httpd_enable_homedirs on

http://172.31.145.99/~kk1/
This page is on /home/kk1/public_html...





-----------------------------
----------------------------- VirtualHost 虛擬主機 -----------------------------
-----------------------------

# dnf -y install httpd

# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service
# firewall-cmd --permanent --zone=public --add-service=http
success
# firewall-cmd --reload
success

http://172.31.145.99/


# mkdir /var/www/asus
# vi /var/www/asus/index.html
This is <h1>Asus</h1>web...

# mkdir /var/www/acer
# vi /var/www/acer/index.html
This is <h1>Acer</h1>web...



# vi /etc/httpd/conf/httpd.conf
...
<VirtualHost *:80>
        DocumentRoot /var/www/html
        ServerName 172.31.145.99
</VirtualHost>


<VirtualHost *:80>
        DocumentRoot /var/www/asus
        ServerName web.asus.com.tw
</VirtualHost>
<Directory "/var/www/asus">
    Options Indexes
    AllowOverride None
    Require all granted
</Directory>


<VirtualHost *:80>
        DocumentRoot /var/www/acer
        ServerName web.acer.com.tw
</VirtualHost>
<Directory "/var/www/acer">
    Options Indexes
    AllowOverride None
    Require all granted
</Directory>




# systemctl reload httpd.service


修改 windows10 hosts 檔
開啟記事本,以系統管理員身分執行
檔案-->開啟舊檔:C:\Windows\System32\drivers\etc\hosts
新增資料:
172.31.145.99 web.asus.com.tw  web.acer.com.tw

完成後-->檔案-->儲存檔案





http://web.asus.com.tw/
This is
Asus
web...

http://web.acer.com.tw/
This is
Acer
web...






???????????????????????????以下作廢
-----------------------------
----------------------------- php + MariaDB -----------------------------
-----------------------------
DDDDDDDDDDDDDDDDDD
# dnf -y install httpd

# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

http://172.31.145.99/



# dnf -y install php

# dnf list installed | grep php
php.x86_64                           7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-cli.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-common.x86_64                    7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-fpm.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream


# rpm -qa | grep php
php-cli-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64
php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64
php-common-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64
php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64




# ls /usr/sbin | grep php
php-fpm

# ls /usr/lib/systemd/system | grep php
php-fpm.service


# systemctl | grep php
php-fpm.service   

# ls /etc/php.ini
/etc/php.ini









# systemctl restart httpd.service


# vi /var/www/html/test.php
<?php
        phpinfo();
php?>


http://172.31.145.99/test.php









++++++++++++++++++++++ MariaDB ++++++++++++++++


# dnf -y install httpd
# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

http://172.31.145.99/


# dnf -y install php
# systemctl restart httpd.service

# vi /var/www/html/test.php
<?php
echo "kk";
phpinfo();
?>

http://192.168.1.100/test.php




# dnf list | grep mariadb
mariadb.x86_64                                         3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
...
mariadb-server.x86_64                              3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
...


# dnf -y install mariadb-server

# dnf list installed | grep mariadb
mariadb.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-backup.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-common.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-connector-c.x86_64           3.0.7-1.el8                             @AppStream
mariadb-connector-c-config.noarch    3.0.7-1.el8                             @AppStream
mariadb-errmsg.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-gssapi-server.x86_64         3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server-utils.x86_64          3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream


# rpm -qa | grep mariadb
mariadb-server-utils-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-connector-c-config-3.0.7-1.el8.noarch
mariadb-connector-c-3.0.7-1.el8.x86_64
mariadb-errmsg-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-gssapi-server-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-server-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-common-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-backup-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64

# ls /usr/lib/systemd/system | grep mariadb
mariadb@bootstrap.service.d
mariadb.service
mariadb@.service



# systemctl start mariadb.service
# systemctl enable mariadb.service
# systemctl status mariadb.service
# systemctl is-active mariadb.service
active


# mysqladmin -u root password db123456
# mysql -u root -p
Enter password:


> select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+




--------------- 伺服器字元集 character set 和連線校對 collaction   -------------
 
> show variables like 'character_set_server';
+----------------------+--------+
| Variable_name        | Value  |
+----------------------+--------+
| character_set_server | latin1 |
+----------------------+--------+


> set character_set_server='utf8';
Query OK, 0 rows affected (0.000 sec)

> show variables like 'character_set_server';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| character_set_server | utf8  |
+----------------------+-------+




> show variables like 'collation_server';
+------------------+-----------------+
| Variable_name    | Value           |
+------------------+-----------------+
| collation_server | utf8_general_ci |
+------------------+-----------------+


> set collation_server='utf8_unicode_ci';
Query OK, 0 rows affected (0.000 sec)

> show variables like 'collation_server';
+------------------+-----------------+
| Variable_name    | Value           |
+------------------+-----------------+
| collation_server | utf8_unicode_ci |
+------------------+-----------------+





--------------- 資料庫字元集 character set 和連線校對 collaction   -------------

> show variables like 'character_set_database';
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| character_set_database | latin1 |
+------------------------+--------+


> set character_set_database='utf8';
Query OK, 0 rows affected (0.000 sec)

> show variables like 'character_set_database';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| character_set_database | utf8  |
+------------------------+-------+



> show variables like 'collation_database';
+--------------------+-----------------+
| Variable_name      | Value           |
+--------------------+-----------------+
| collation_database | utf8_general_ci |
+--------------------+-----------------+


> set collation_database='utf8_unicode_ci';
Query OK, 0 rows affected (0.000 sec)

> show variables like 'collation_database';
+--------------------+-----------------+
| Variable_name      | Value           |
+--------------------+-----------------+
| collation_database | utf8_unicode_ci |
+--------------------+-----------------+




> show variables like '%database';
+------------------------+-----------------+
| Variable_name          | Value           |
+------------------------+-----------------+
| character_set_database | utf8            |
| collation_database     | utf8_unicode_ci |
| skip_show_database     | OFF             |
+------------------------+-----------------+








> create database testdb character set='utf8' collate='utf8_unicode_ci';

> show variables like '%database';
+------------------------+-------------------+
| Variable_name          | Value             |
+------------------------+-------------------+
| character_set_database | latin1            |
| collation_database     | latin1_swedish_ci |
| skip_show_database     | OFF               |
+------------------------+-------------------+

> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| testdb             |
+--------------------+

> use testdb;

> create table tblmen (mid int primary key auto_increment, na varchar(20), accnt varchar(20), pwd varchar(20));

> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| tblmen           |
+------------------+

> describe tblmen;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| mid   | int(11)     | NO   | PRI | NULL    | auto_increment |
| na    | varchar(20) | YES  |     | NULL    |                |
| accnt | varchar(20) | YES  |     | NULL    |                |
| pwd   | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

> show create table tblmen \G;
*************************** 1. row ***************************
       Table: tblmen
Create Table: CREATE TABLE `tblmen` (
  `mid` int(11) NOT NULL AUTO_INCREMENT,
  `na` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `accnt` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `pwd` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`mid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci




> insert into tblmen values(1,'蔡英九','act1','pwd1');    //AUTO_INCREMENT
> select * from tblmen;
+-----+-----------+-------+------+
| mid | na        | accnt | pwd  |
+-----+-----------+-------+------+
|   1 | 蔡英九    | act1  | pwd1 |
+-----+-----------+-------+------+


//Table 匯出 文字檔
> select * into outfile 'tblmen.txt' from tblmen;

//離開 MariaDB
# ls /var/lib/mysql/testdb
db.opt  tblmen.frm  tblmen.ibd  tblmen.txt

# cat /var/lib/mysql/testdb/tblmen.txt
1       蔡英九  act1    pwd1








注意!PHP7已經不支援MySQL系列函數,而是改用MySQLi,或者PDO物件。


display_errors = On



# ls /var/log
anaconda  dnf.librepo.log  firewalld   lastlog  private  wtmp
audit     dnf.log          hawkey.log  mariadb  sssd
btmp      dnf.rpm.log      httpd       php-fpm  tuned


# ls /var/log/php-fpm
error.log  www-error.log

# tail -1 /var/log/php-fpm/error.log
[20-Dec-2020 09:07:12] NOTICE: systemd monitor interval set to 10000ms

# tail -1 /var/log/php-fpm/www-error.log
thrown in /var/www/html/0.php on line 2


# ls /var/log/httpd
access_log  error_log

# tail -1 /var/log/httpd/access_log
192.168.1.104 - - [20/Dec/2020:10:41:57 +0800] "-" 408 - "-" "-"

# tail -1 /var/log/httpd/error_log
[Sun Dec 20 08:59:24.949687 2020] [core:notice] [pid 11417:tid 140192777812288] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'




# ls /var/log/mariadb
mariadb.log

# tail -1 /var/log/mariadb/mariadb.log
Version: '10.3.17-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server





<?php
ini_set("display_errors","On");
error_reporting(E_ALL);

$con= mysql('localhost','root','db123456','testdb');
if (mysqli_cinnect_error()){
        echo "錯誤:".mysqli_connect_error()."<br>";
}
?>


++++++++++++++++++++++++++++++++++++++++++++++++ php

# dnf list | grep php
php.x86_64                                             7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-bcmath.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-cli.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-common.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-dba.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-dbg.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-devel.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-embedded.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-enchant.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-fpm.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-gd.x86_64                                          7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-gmp.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-intl.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-json.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-ldap.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-mbstring.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-mysqlnd.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-odbc.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-opcache.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-pdo.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-pear.noarch                                        1:1.10.5-9.module_el8.2.0+313+b04d0a66           AppStream
php-pecl-apcu.x86_64                                   5.1.12-2.module_el8.2.0+313+b04d0a66             AppStream
php-pecl-apcu-devel.x86_64                             5.1.12-2.module_el8.2.0+313+b04d0a66             AppStream
php-pecl-zip.x86_64                                    1.15.3-1.module_el8.2.0+313+b04d0a66             AppStream
php-pgsql.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-process.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-recode.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-snmp.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-soap.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-xml.x86_64                                         7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream
php-xmlrpc.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream




# dnf -y install php php-fpm php-gd php-mbstring php-mysqlnd
# dnf list installed | grep php
php.x86_64                           7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-cli.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-common.x86_64                    7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-fpm.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-gd.x86_64                        7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-mbstring.x86_64                  7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-mysqlnd.x86_64                   7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-pdo.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream


# dnf list installed | grep php

# rpm -qa | grep php

# ls /usr/sbin | grep php
php-fpm

# ls /usr/lib/systemd/system | grep php
php-fpm.service


# systemctl | grep php
php-fpm.service   

# ls /etc/php.ini
/etc/php.ini




# vi /var/www/html/0.php
<?php
phpinfo();
?>


# dnf -y install mariadb mariadb-server
# dnf list installed | grep mariadb
mariadb.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-backup.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-common.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-connector-c.x86_64           3.0.7-1.el8                             @AppStream
mariadb-connector-c-config.noarch    3.0.7-1.el8                             @AppStream
mariadb-errmsg.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-gssapi-server.x86_64         3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server-utils.x86_64          3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
# systemctl start mariadb
# systemctl enable mariadb



# vi /etc/php.ini
...
extension=mysqli
...

# systemctl restart httpd
or
# systemctl restart php-fpm





# vi /var/www/html/1.php
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);

$con= mysqli_connect('localhost','root','db123456','testdb');

echo $kk;


?>











-----------------------------------------------------------------------


# systemctl status httpd
# systemctl status php-fpm
# systemctl status mariadb


<?php

$host = 'localhost';
$db = 'testdb';
$user = 'root';
$pwd = 'db123456';
$link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);

?>




-----------------------------------------------------------
# vi /var/www/html/list.php

<?php

$host = 'localhost';
$db = 'testdb';
$user = 'root';
$pwd = 'db123456';
$db_link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);
$db_link->exec("set character set utf8");

$rt=$db_link->query("select * from tblmen");
$rows=$rt->fetch();
?>

<html>
<head></head>
<body>
<h1 align="center">學生系統</h1>
<p align="center"><a href="add.php">新增學生資料</a>   <a href="query.php">查詢學生資料</a></p>
<table border=1 align="center">
<tr><td>編號</td><td>名字</td><td>帳號</td><td>密碼</td></tr>

<?php
while (!empty($rows)){
        echo "<tr>";
        echo "<td>".$rows["mid"]."</td>";
        echo "<td>".$rows["na"]."</td>";
        echo "<td>".$rows["accnt"]."</td>";
        echo "<td>".$rows["pwd"]."</td>";
        echo "<td><a href='update.php?mid=".$rows["mid"]."'>修改</a></td>";
        echo "<td><a href='delete.php?mid=".$rows["mid"]."'>刪除</a></td>";
        echo "</tr>";

        $rows=$rt->fetch();
}
$db_link=null;


?>

</table>
</body>
</html>








-----------------------------------------------------------

# vi /var/www/html/add.php

<?php
if ($_POST["act"]=="add"){
    $host = 'localhost';
    $db = 'testdb';
    $user = 'root';
    $pwd = 'db123456';
    $db_link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);
    $db_link->exec("set character set utf8");

    $rt=$db_link->query("INSERT INTO `tblmen`(`mid`, `na`, `accnt`, `pwd`) VALUES ('".$_POST["mid"]."','".$_POST["na"]."','".$_POST["accnt"]."','".$_POST["pwd"]."')");

    header("Location:list.php");
}
?>

<html>
<head></head>
<body>
<h1 align="center">新增資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid"></td></tr>
<tr><td>名字</td><td><input type="text" name="na"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="add" name="act">
<input type="submit" value="新增" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>








-----------------------------------------------------------

# vi /var/www/html/update.php



<?php

$host = 'localhost';
$db = 'testdb';
$user = 'root';
$pwd = 'db123456';
$db_link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);
$db_link->exec("set character set utf8");



if ($_POST["act"]=="update"){
        $str="update tblmen set na='".$_POST["na"]."',accnt='".$_POST["accnt"]."',pwd='".$_POST["pwd"]."' where mid =".$_POST["mid"];
        header("Location:list.php");
}
else{
    $str="select * from tblmen where mid=".$_GET["mid"];
}



$rt=$db_link->query($str);
$rows=$rt->fetch();

?>

<html>
<head></head>
<body>
<h1 align="center">修改資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formUpdate">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid" value="<?php echo $rows["mid"]; ?>" disabled></td></tr>
<tr><td>名字</td><td><input type="text" name="na" value="<?php echo $rows["na"]; ?>"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt" value="<?php echo $rows["accnt"]; ?>"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd" value="<?php echo $rows["pwd"]; ?>"></td></tr>

<tr><td></td><td>
<input type="hidden" value="<?php echo $rows["mid"]; ?>" name="mid">
<input type="hidden" value="update" name="act">
<input type="submit" value="更新" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>









-----------------------------------------------------------


# vi /var/www/html/query.php
<html>
<head></head>
<body>
<h1 align="center">會員查詢</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formQuery">
<table align="center">
<tr><td>姓名</td><td><input type="text" name="na"></td><td></td><td></td></tr>
<tr><td></td><td>
<input type="hidden" value="query" name="act">
<input type="submit" value="查詢" name="ok">
</td><td></td><td></td></tr>

<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>

<tr><td>編號</td><td>姓名</td><td>帳號</td><td>密碼</td></tr>

<?php
if ($_POST["act"]=="query"){
        $db_link=mysql_connect("localhost","root","db123456");


        mysql_query("SET NAMES 'utf8'");


        $db_sel=mysql_select_db("kkdb");
        $str_sel="SELECT * FROM `tblmen` WHERE `na` LIKE '%".$_POST["na"]."%'";
//echo $str_sel;
        $result=mysql_query($str_sel);
        $data_cnt=mysql_num_rows($result);

       if ($data_cnt!=0){
                while ($tbl_rows=mysql_fetch_assoc($result)){
                        echo "<tr>";
                        echo "<td>".$tbl_rows["mid"]."</td>";
                        echo "<td>".$tbl_rows["na"]."</td>";
                        echo "<td>".$tbl_rows["accnt"]."</td>";
                        echo "<td>".$tbl_rows["pwd"]."</td>";
                        echo "</tr>";
                }
        }
}
?>



</table>
</form>
</body>
</html>






=========================

vi /var/www/html/query.php

<?php

ini_set("display_errors","On");
error_reporting(E_ALL);


if ($_POST["act"]=="query"){
        $host = 'localhost';
        $db = 'testdb';
        $user = 'root';
        $pwd = 'db123456';
        $db_link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);
        $db_link->exec("set character set utf8");

        $rt=$db_link->query("SELECT * FROM `tblmen` WHERE `na` LIKE '%".$_POST["na"]."%'");
        $data_cnt=mysqli_num_rows($rt);

       if ($data_cnt!=0){
                while ($rows=mysqli_fetch_assoc($rt)){
                        echo "<tr>";
                        echo "<td>".$rows["mid"]."</td>";
                        echo "<td>".$rows["na"]."</td>";
                        echo "<td>".$rows["accnt"]."</td>";
                        echo "<td>".$rows["pwd"]."</td>";
                        echo "</tr>";
                }
        }
}
?>


<html>
<head></head>
<body>
<h1 align="center">會員查詢</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formQuery">
<table align="center">
<tr><td>姓名</td><td><input type="text" name="na"></td><td></td><td></td></tr>
<tr><td></td><td>
<input type="hidden" value="query" name="act">
<input type="submit" value="查詢" name="ok">
</td><td></td><td></td></tr>

<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>

<tr><td>編號</td><td>姓名</td><td>帳號</td><td>密碼</td></tr>




+++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++12/23
+++++++++++++++++++++++++++++++++++++++++++


# dnf -y install httpd
# systemctl start httpd
# systemctl enable httpd
# systemctl status httpd
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

http://172.31.145.99/






# dnf list | grep php

# dnf -y install php php-fpm php-gd php-mbstring php-mysqlnd

# dnf list installed | grep  php
php.x86_64                           7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-cli.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-common.x86_64                    7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-fpm.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-gd.x86_64                        7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-mbstring.x86_64                  7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-mysqlnd.x86_64                   7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream
php-pdo.x86_64                       7.2.24-1.module_el8.2.0+313+b04d0a66   @AppStream


# dnf list installed | grep php

# rpm -qa | grep php

# ls /usr/sbin | grep php
php-fpm

# ls /usr/lib/systemd/system | grep php
php-fpm.service


# systemctl | grep php
php-fpm.service   

# ls /etc/php.ini
/etc/php.ini



# systemctl restart httpd

# vi /var/www/html/0.php

<?php

ini_set("display_errors","On");   

//  
# vi /etc/php.ini 
...
display_errors = On
...

# systemctl restart httpd

無效!!!!!!
//

echo "kk<br>";
echo "瀏覽器中文編碼是否正常?<br>";

$sid="s01";
$str1="select * from tblmen where sid='".$sid."'";
$str2="select * from tblmen where sid='$sid'";        //php 字串以雙引號包起來,單引號會解析出其內容

echo $str1."<br>";
echo $str2."<br>";
echo $str3;

phpinfo();

?>


http://172.31.145.99/0.php
kk
編碼是否正常?
select * from tblmen where sid='s01'
select * from tblmen where sid='s01'

Notice: Undefined variable: str3 in /var/www/html/1.php on line 15
...



//刪除編輯錯誤時所產生的暫存檔
# rm -rf /var/www/html/.1.php.swp





# dnf list | grep mariadb
mariadb.x86_64                                         3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-backup.x86_64                            3:10.3.17-1.module_el8.1.0+257+48736ea6     AppStream
mariadb-common.x86_64                          3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-connector-c.i686                          3.0.7-1.el8                                      AppStream
mariadb-connector-c.x86_64                             3.0.7-1.el8                                      AppStream
mariadb-connector-c-config.noarch                      3.0.7-1.el8                                      AppStream
mariadb-connector-c-devel.i686                         3.0.7-1.el8                                      AppStream
mariadb-connector-c-devel.x86_64                       3.0.7-1.el8                                      AppStream
mariadb-connector-odbc.x86_64                          3.0.7-1.el8                                      AppStream
mariadb-devel.x86_64                               3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-embedded.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-embedded-devel.x86_64             3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-errmsg.x86_64                             3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-gssapi-server.x86_64                   3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-java-client.noarch                                                 2.2.5-3.el8                                      AppStream
mariadb-oqgraph-engine.x86_64               3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-server.x86_64                               3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-server-galera.x86_64                    3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-server-utils.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream
mariadb-test.x86_64                                    3:10.3.17-1.module_el8.1.0+257+48736ea6          AppStream



# dnf -y install mariadb-server

# dnf list installed | grep mariadb
mariadb.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-backup.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-common.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-connector-c.x86_64           3.0.7-1.el8                             @AppStream
mariadb-connector-c-config.noarch    3.0.7-1.el8                             @AppStream
mariadb-errmsg.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-gssapi-server.x86_64         3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server-utils.x86_64          3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream



# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb


# mysqladmin -u root password db123456
# mysql -u root -p
Enter password:



MariaDB [(none)]> select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+





--------------- 資料庫字元集 character set 和連線校對 collaction   -------------

MariaDB [(none)]> set character_set_database='utf8';
MariaDB [(none)]> set collation_database='utf8_unicode_ci';
MariaDB [(none)]> show variables like '%database';
+------------------------+-----------------+
| Variable_name          | Value           |
+------------------------+-----------------+
| character_set_database | utf8            |
| collation_database     | utf8_unicode_ci |
| skip_show_database     | OFF             |
+------------------------+-----------------+




MariaDB [(none)]> create database kkdb;

MariaDB [(none)]> show variables like '%database';
+------------------------+-----------------+
| Variable_name          | Value           |
+------------------------+-----------------+
| character_set_database | utf8            |
| collation_database     | utf8_unicode_ci |
| skip_show_database     | OFF             |
+------------------------+-----------------+

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkdb               |
| mysql              |
| performance_schema |
+--------------------+



MariaDB [(none)]> show create database kkdb \G;
*************************** 1. row ***************************
       Database: kkdb
Create Database: CREATE DATABASE `kkdb` /*!40100 DEFAULT CHARACTER SET latin1 */
1 row in set (0.000 sec)

ERROR: No query specified




MariaDB [(none)]> use kkdb;
Database changed


MariaDB [kkdb]> create table tblmen (mid int primary key auto_increment, na varchar(20), accnt varchar(20), pwd varchar(20));

MariaDB [kkdb]> show tables;
+----------------+
| Tables_in_kkdb |
+----------------+
| tblmen         |
+----------------+


MariaDB [kkdb]> describe tblmen;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| mid   | int(11)     | NO   | PRI | NULL    | auto_increment |
| na    | varchar(20) | YES  |     | NULL    |                |
| accnt | varchar(20) | YES  |     | NULL    |                |
| pwd   | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+


MariaDB [kkdb]> show create table tblmen \G;
*************************** 1. row ***************************
       Table: tblmen
Create Table: CREATE TABLE `tblmen` (
  `mid` int(11) NOT NULL AUTO_INCREMENT,
  `na` varchar(20) DEFAULT NULL,
  `accnt` varchar(20) DEFAULT NULL,
  `pwd` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`mid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

?????? 如此作法有問題........

--------------- 以上  資料庫字元集 character set 和連線校對 collaction   -------------










//移除重裝
# dnf list installed | grep mariadb
//沒效,原產生資料庫還在



!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!





# dnf -y install mariadb-server

# dnf list installed | grep mariadb
mariadb.x86_64                       3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-backup.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-common.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-connector-c.x86_64           3.0.7-1.el8                             @AppStream
mariadb-connector-c-config.noarch    3.0.7-1.el8                             @AppStream
mariadb-errmsg.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-gssapi-server.x86_64         3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server.x86_64                3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream
mariadb-server-utils.x86_64          3:10.3.17-1.module_el8.1.0+257+48736ea6 @AppStream



# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb


# mysqladmin -u root password db123456
# mysql -u root -p
Enter password:

MariaDB [(none)]> select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+

MariaDB [(none)]> create database kkdb character set='utf8' collate='utf8_unicode_ci';

MariaDB [(none)]> show variables like '%database';
+------------------------+-------------------+
| Variable_name          | Value             |
+------------------------+-------------------+
| character_set_database | latin1            |
| collation_database     | latin1_swedish_ci |
| skip_show_database     | OFF               |
+------------------------+-------------------+

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkdb               |
| mysql              |
| performance_schema |
+--------------------+


MariaDB [(none)]> use kkdb;
Database changed

MariaDB [kkdb]> create table tblmen (mid int primary key auto_increment, na varchar(20), accnt varchar(20), pwd varchar(20));

MariaDB [kkdb]> show tables;
+----------------+
| Tables_in_kkdb |
+----------------+
| tblmen         |
+----------------+


MariaDB [kkdb]> describe tblmen;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| mid   | int(11)     | NO   | PRI | NULL    | auto_increment |
| na    | varchar(20) | YES  |     | NULL    |                |
| accnt | varchar(20) | YES  |     | NULL    |                |
| pwd   | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

MariaDB [kkdb]> show create table tblmen \G;
*************************** 1. row ***************************
       Table: tblmen
Create Table: CREATE TABLE `tblmen` (
  `mid` int(11) NOT NULL AUTO_INCREMENT,
  `na` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `accnt` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `pwd` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`mid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci






MariaDB [kkdb]> insert into tblmen values(1,'蔡英九','act1','pwd1');    //AUTO_INCREMENT 無效

MariaDB [kkdb]> insert into tblmen (na,accnt,pwd) values('關羽','act5','pwd5');    //ok!

MariaDB [kkdb]> select * from tblmen;
+-----+-----------+-------+------+
| mid | na        | accnt | pwd  |
+-----+-----------+-------+------+
|   1 | 蔡英九    | act1  | pwd1 |
+-----+-----------+-------+------+


MariaDB [kkdb]> select * into outfile 'tblmen.txt' from tblmen;

MariaDB [kkdb]> Ctrl-C -- exit!
Aborted


# cat /var/lib/mysql/kkdb/tblmen.txt
1       蔡英九  act1    pwd1



===========================

# vi /var/www/html/LinkServer.php

<?php
$host = 'localhost';
$db = 'kkdb';
$user = 'root';
$pwd = 'db123456';
$db_link=new pdo("mysql:host=$host;dbname=$db", $user, $pwd);
$db_link->exec("set character set utf8");
?>





===========================

# vi /var/www/html/list.php

<?php
include("LinkServer.php");

$rt=$db_link->query("select * from tblmen");
$rows=$rt->fetch();
?>

<html>
<head></head>
<body>
<h1 align="center">學生系統</h1>
<p align="center"><a href="add.php">新增學生資料</a>   <a href="query.php">查詢學生資料</a></p>
<table border=1 align="center">
<tr><td>編號</td><td>名字</td><td>帳號</td><td>密碼</td></tr>

<?php
while (!empty($rows)){
        echo "<tr>";
        echo "<td>".$rows["mid"]."</td>";
        echo "<td>".$rows["na"]."</td>";
        echo "<td>".$rows["accnt"]."</td>";
        echo "<td>".$rows["pwd"]."</td>";
        echo "<td><a href='update.php?mid=".$rows["mid"]."'>修改</a></td>";
        echo "<td><a href='delete.php?mid=".$rows["mid"]."'>刪除</a></td>";
        echo "</tr>";

        $rows=$rt->fetch();
}
$db_link=null;


?>

</table>
</body>
</html>






===========================

# vi /var/www/html/add.php

<?php
if ($_POST["act"]=="add"){
    include("LinkServer.php");

    $rt=$db_link->query("INSERT INTO `tblmen`(`mid`, `na`, `accnt`, `pwd`) VALUES ('".$_POST["mid"]."','".$_POST["na"]."','".$_POST["accnt"]."','".$_POST["pwd"]."')");

    header("Location:list.php");
}
?>

<html>
<head></head>
<body>
<h1 align="center">新增資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid"></td></tr>
<tr><td>名字</td><td><input type="text" name="na"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="add" name="act">
<input type="submit" value="新增" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>







===========================

# vi /var/www/html/update.php

<?php

include("LinkServer.php");


if ($_POST["act"]=="update"){
        $str="update tblmen set na='".$_POST["na"]."',accnt='".$_POST["accnt"]."',pwd='".$_POST["pwd"]."' where mid =".$_POST["mid"];
        header("Location:list.php");
}
else{
    $str="select * from tblmen where mid=".$_GET["mid"];
}



$rt=$db_link->query($str);
$rows=$rt->fetch();

?>

<html>
<head></head>
<body>
<h1 align="center">修改資料</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formUpdate">
<table align="center">
<tr><td>編號</td><td><input type="text" name="mid" value="<?php echo $rows["mid"]; ?>" disabled></td></tr>
<tr><td>名字</td><td><input type="text" name="na" value="<?php echo $rows["na"]; ?>"></td></tr>
<tr><td>帳號</td><td><input type="text" name="accnt" value="<?php echo $rows["accnt"]; ?>"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd" value="<?php echo $rows["pwd"]; ?>"></td></tr>

<tr><td></td><td>
<input type="hidden" value="<?php echo $rows["mid"]; ?>" name="mid">
<input type="hidden" value="update" name="act">
<input type="submit" value="更新" name="ok">
<input type="reset" value="清除" name="erase">
</td></tr>
</table>
</form>
</body>
</html>





===========================



#vi /var/www/html/query.php


<html>
<head></head>
<body>
<h1 align="center">會員查詢</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
<form action="" method="post" name="formQuery">
<table align="center">
<tr><td>姓名</td><td><input type="text" name="na"></td><td></td><td></td></tr>
<tr><td></td><td>
<input type="hidden" value="query" name="act">
<input type="submit" value="查詢" name="ok">
</td><td></td><td></td></tr>
</table>

<?php
if($_POST["act"]=="query"){
        include("LinkServer.php");
        $rt=$db_link->query("select * from tblmen where na LIKE '%".$_POST["na"]."%'");
        $rows=$rt->fetch();

        echo "<table align='center' >";
        echo "<tr><td>編號</td><td>名字</td><td>帳號</td><td>密碼</td></tr>";
        echo "<tr><td>".$rows["mid"]."</td><td>".$rows["na"]."</td><td>".$rows["accnt"]."</td><td>".$rows["pwd"]."</td></tr>";
        echo "</table>";

}

?>

</form>
</body>
</html>








===========================

# vi /var/www/html/delete.php

<?php
include("LinkServer.php");
$rt=$db_link->query("delete from tblmen where mid ='".$_GET["mid"]."'");
?>

<html>
<head></head>
<body>
<h1 align="center">資料刪除完畢!</h1>
<p align="center"><a href="list.php">返回主畫面</a></p>
</body>
</html>





===========================

# vi /var/www/html/index.php

<?php
if ($_POST["act"]=="login"){
    include("LinkServer.php");
    $rt=$db_link->query("select * from tblmen where accnt ='".$_POST["accnt"]."' and pwd ='".$_POST["pwd"]."'");

    $data_cnt=$rt->rowCount();

        if ($data_cnt==1){
                header("Location:list.php");
        }else{
                header("Location:index.php");
        }

}
?>

<html>
<head></head>
<body>
<h1 align="center">會員登入</h1>
<form action="" method="post" name="formAdd">
<table align="center">
<tr><td>帳號</td><td><input type="text" name="accnt"></td></tr>
<tr><td>密碼</td><td><input type="text" name="pwd"></td></tr>
<tr><td></td><td>
<input type="hidden" value="login" name="act">
<input type="submit" value="登入" name="ok">
</td></tr>
</table>
</form>
</body>
</html>



===========================

//欄位分隔符號,預設"\t"
//每行結束符號,預設"\n" 
MariaDB [kkdb]> select * from tblmen into outfile 'tblmen.txt';

# cat /var/lib/mysql/kkdb/tblmen.txt
1       蔡英九  act1    pwd1
2       蘇太多  act2    pwd2
3       陳偉    act3    pwd3
4       趙少主  act44   pwd44


# vi /var/lib/mysql/kkdb/tblmen.txt
1       蔡英九  act1    pwd1
2       蘇太多  act2    pwd2
3       陳偉    act3    pwd3
4       趙少主  act44   pwd44
5       王政正  act5    pwd5
6       韓國仁  act6    pwd6



MariaDB [kkdb]> delet from tblmen;

MariaDB [kkdb]> load data infile 'tblmen.txt' into table tblmen;

MariaDB [kkdb]> select * from tblmen;
+-----+-----------+-------+-------+
| mid | na        | accnt | pwd   |
+-----+-----------+-------+-------+
|   1 | 蔡英九    | act1  | pwd1  |
|   2 | 蘇太多    | act2  | pwd2  |
|   3 | 陳偉      | act3  | pwd3  |
|   4 | 趙少主    | act44 | pwd44 |
|   5 | 王政正    | act5  | pwd5  |
|   6 | 韓國仁    | act6  | pwd6  |
+-----+-----------+-------+-------+




//備份資料庫,沒寫 table 代表全部 database

# mysqldump -u root -p kkdb > kkdb.bk.sql
Enter password:

# ls
anaconda-ks.cfg  kkdb.bk.sql



//刪除database
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkdb               |
| mysql              |
| performance_schema |
+--------------------+


MariaDB [(none)]> drop database kkdb;
ERROR 1010 (HY000): Error dropping database (can't rmdir './kkdb', errno: 39 "Directory not empty")


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkdb               |
| mysql              |
| performance_schema |
+--------------------+

MariaDB [(none)]> use kkdb;

MariaDB [kkdb]> show tables;
Empty set (0.000 sec)

?????database 還在 但 table 已刪除 
?????因為 在var/lib/mysql/kkdb/ 有曾經匯出的 table 資料

# ls /var/lib/mysql/kkdb/tblmen.txt
/var/lib/mysql/kkdb/tblmen.txt

# rm  /var/lib/mysql/kkdb/tblmen.txt
rm:是否移除普通檔案'/var/lib/mysql/kkdb/tblmen.txt'? y

?????刪除在var/lib/mysql/kkdb/ 曾經匯出的 table 資料 即可完整刪除database
MariaDB [(none)]> drop database kkdb;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+


# ls /var/lib/mysql/kkdb
ls: 無法存取 '/var/lib/mysql/kkdb': No such file or directory



//資料庫還原
//先建立空資料庫

MariaDB [(none)]> create database kkdb character set='utf8' collate='utf8_unicode_ci';
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkdb               |
| mysql              |
| performance_schema |
+--------------------+


//還原
# mysql -u root -p kkdb < kkdb.bk.sql
Enter password:

# ls /var/lib/mysql/kkdb
db.opt  tblmen.frm  tblmen.ibd



MariaDB [(none)]> use kkdb;

MariaDB [kkdb]> show tables;
+----------------+
| Tables_in_kkdb |
+----------------+
| tblmen         |
+----------------+


MariaDB [kkdb]> select * from tblmen;
+-----+-----------+-------+-------+
| mid | na        | accnt | pwd   |
+-----+-----------+-------+-------+
|   1 | 蔡英九    | act1  | pwd1  |
|   2 | 蘇太多    | act2  | pwd2  |
|   3 | 陳偉      | act3  | pwd3  |
|   4 | 趙少主    | act44 | pwd44 |
|   5 | 王政正    | act5  | pwd5  |
|   6 | 韓國仁    | act6  | pwd6  |
+-----+-----------+-------+-------+


-----------------------------------------------------------










2020年11月7日 星期六

CentOS8


此篇已經重新謄錄完成!!

可以作廢。


------------------------------

            以下20201106研習

------------------------------



# uname -a

Linux centos8.kk 4.18.0-193.el8.x86_64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# rpm -q centos-release
centos-release-8.2-2.2004.0.1.el8.x86_64


------------------------------升級與補強

# dnf -y install wget

# wget http://ftp.kh.edu.tw/APPL/dnf/CentOS8/fix-yum_repo-CentOS8.sh

# ls -l
-rw-r--r--. 1 root root 1838 10月 19 10:58 fix-yum_repo-CentOS8.sh

# chmod 755 fix-yum_repo-CentOS8.sh

# ls -l
-rwxr-xr-x. 1 root root 1838 10月 19 10:58 fix-yum_repo-CentOS8.sh


------------------------------修正套件庫來源及增加 epel 套件庫來源

# ./fix-yum_repo-CentOS8.sh

# dnf -y update


------------------------------讓設備自動定期更新套件

# dnf -y install dnf-automatic

# cp /etc/dnf/automatic.conf /etc/dnf/automatic.conf.bk

# dnf install vim 

# vim /etc/dnf/automatic.conf
...
apply_updates = yes

# systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; disabled>
   Active: inactive (dead)

# systemctl enable dnf-automatic.timer

# systemctl start dnf-automatic.timer

# systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; enabled;>
   Active: active (waiting) since Sun 2020-11-08 22:48:24 CST; 3s ago


------------------------------看更新紀錄,知道那些套件更新
# cat /var/log/dnf.rpm.log

# tail /var/log/dnf.rpm.log
# tail -2 /var/log/dnf.rpm.log

# more /var/log/dnf.rpm.log
# cat /var/log/dnf.rpm.log | more
# cat /var/log/dnf.rpm.log | grep Installed
# grep Installed /var/log/dnf.rpm.log




------------------------------簡易指令說明
# ip --help
# ip -help
# ip -h
# man ip    //詳細使用手冊


# ip address show    //路由表複雜時比 ifconifg 效能較佳
# ip route show



------------------------------檔案目錄簡介
# dnf -y install tree
# tree -L 1 /                // 1: 第1層      /: 根目錄
/
├── bin -> usr/bin
├── boot
├── dev
├── etc
├── home
├── lib -> usr/lib
├── lib64 -> usr/lib64
├── media
├── mnt
├── opt
├── proc                             
├── root
├── run                               
├── sbin -> usr/sbin
├── srv
├── sys
├── tmp
├── usr
└── var

/proc 是一種虛擬文件系統。儲存的是當前核心運行狀態的一系列特殊文件,用戶可以通過這些文件查看有關系統硬體及當前正在運行進程的信息。

# cat /proc/cpuinfo

# ls /proc/1

# ps -aux




/run 程式或服務啟動後會將其 PID 放置於此,正在執行

# ls /run

# cat /run/sshd.pid



/opt 第3方程式放在此



# ls /srv

# ls -al /sys




Linux       根目錄 /
Windows 根目錄 \






















FileTable 指到 inode 起始點。inode 是 block 的 index

inode 類似 windows 動態磁區。本即樹狀架構,永遠不用重整磁區。
愈亂效果才會出來。搜尋平均使用效率高。

windows 之前的 FAT32 需要重整。
MBR --> FileTable --> 磁區
主機愈忙,檔案系統碎片愈高,沒時間重整。

是主機的用途來設定 block 大小,如:郵件 2K~8K、資料庫 1K~2K。
block 愈小, inode 愈多,愈占空間。與空間的運作效能有關。

磁區格式化完成,inode 完成對應到 block

FileTable 此架構在記憶體內
不用停機,有彈性,利於線上作業

新增檔案,找可用的空 inode 連結至此
刪除檔案,切斷檔案與原 inode 連結,並重新標示為可用。若建立新檔案使用到這個 inode,原 block 資料會被新檔覆蓋。


1. inode

2. link:
soft link   檔名指到原檔的 inode。                似捷徑。
hard link 再找一個空 inode 連到原 block。 有副本。

# cp anaconda-ks.cfg anaconda-ks.cfg_bk
# ln -s anaconda-ks.cfg_bk SoftLink.cfg
# ls -l
-rw-------. 1 root root 1263 11月 13 14:13 anaconda-ks.cfg_bk
lrwxrwxrwx. 1 root root   18 11月 13 14:14 SoftLink.cfg -> anaconda-ks.cfg_bk
# rm -f anaconda-ks.cfg_bk
# ls -l
lrwxrwxrwx. 1 root root   18 11月 13 14:14 SoftLink.cfg -> anaconda-ks.cfg_bk
出現錯誤


# link anaconda-ks.cfg_bk  HardLink.cfg
# ls -l
# rm -f anaconda-ks.cfg_bk
# ls -l
-rw-------. 1 root root 1263 11月 13 13:59 HardLink.cfg
沒出現錯誤
建立 hard link 的 inode 仍連結到原 anaconda-ks.cfg_bk 所在的 block


3. mount 將一磁區 inode、block 給一個目錄使用

 

//分割區使用狀況及掛載狀態
# df -h

檔案系統                    容量        已用     可用      已用%    掛載點

devtmpfs                     1.9G        0           1.9G      0%           /dev

tmpfs                           1.9G        0           1.9G      0%           /dev/shm

tmpfs                           1.9G        9.0M     1.9G      1%           /run

tmpfs                           1.9G        0            1.9G      0%          /sys/fs/cgroup

/dev/mapper/cl-root     17G        1.7G       16G      10%        /

/dev/sda1                     976M      184M     726M    21%        /boot

tmpfs                           376M      0             376M    0%          /run/user/0


目錄獨立分開,即使爆了不會影響其他目錄。 /var/log



//磁區。LVM 可動態調整的 partition
# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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: 0xc2c9c20c

所用裝置   可開機   Start          結束           磁區           Size   Id    類型
/dev/sda1    *             2048         2099199      2097152    1G     83    Linux
/dev/sda2                   2099200   41943039    39843840  19G   8e    Linux LVM



# du -h /var/log
0           /var/log/private
8.0K     /var/log/sssd
8.0K     /var/log/tuned
152K    /var/log/audit
3.1M    /var/log/anaconda
3.4M    /var/log






------------------------------檔案系統權限
Owner
Group
Other  

r    100    4
w   010    2
x    001    1


每一個檔案均有一個 Owner,僅有 root 與 owner 可以更改檔案存取保護模式 --> chmod
只有 root 可以更改檔案的 Owner 與 Group   -->chown

# ls -l /etc/shadow
----------. 1 root root 654 11月 11 10:24 /etc/shadow
//全關,只有 root 可以改

# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 33600  4月  7  2020 /usr/bin/passwd

密碼在系統檔中,本應只有 root 可以改
為了方便使用者可以自行設定密碼,所以改由使用者執行
即暫時將使用者身分提升至 root,完成工作後再自動降回使用者身分
但若故意將密碼設的太長造成溢位,無法完成設定密碼工作,就會一直在 root 身分







------------------------------打包、壓縮、解壓縮
# dnf install tar

//c:打包   v:顯示運作過程   f:指定檔案名稱  z:壓縮
# tar cvfz test.tar.gz anaconda-ks.cfg1 anaconda-ks.cfg2 anaconda-ks.cfg3
# ls
anaconda-ks.cfg2   test.tar.gz
anaconda-ks.cfg1   anaconda-ks.cfg3

# mkdir test
# mv test.tar.gz test
# cd ./test

//x:解開 tar
# tar xvfz test.tar.gz
# ls





------------------------------
            參照舊資料,綜合應用
------------------------------

HostOS:
windows10    192.168.2.100     MAC Address 24-4B-FE-E8-E6-06


GuestOS:
CentOS8.2    192.168.2.103



------------------------------------------------------------ Windows10 企業版,無法 ping

Windows 系統 --> 控制台 --> Windows Defender 防火牆 --> 進階設定 --> 輸入規則 -->
檔案及印表機共用 (回應要求 - ICMPv4-In) - 私人  -->  右鍵 -->啟用規則

# ping 172.31.145.100
PING 172.31.145.100 (172.31.145.100) 56(84) bytes of data.
64 bytes from 172.31.145.100: icmp_seq=1 ttl=128 time=0.513 ms




------------------------------------------------------------ 網卡
# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="1eb5087f-ef0a-4aa0-8aef-bd99188bcca5"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="172.31.145.99"
PREFIX="24"
GATEWAY="172.31.145.254"
DNS1="163.28.136.14"
IPV6_PRIVACY="no"


# man ip

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
...
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:77:e4:bc brd ff:ff:ff:ff:ff:ff    //下圖3裝置
    inet 172.31.145.99/24 brd 172.31.145.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::121b:84d9:9429:5d4c/64 scope link noprefixroute
       valid_lft forever preferred_lft forever


# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:77:e4:bc brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    10126889   10294    0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    266250     2270     0       0       0       0

# ip link set ens33 up        //啟用網路介面卡   up:開    down:關




# man nmcli
# nmcli device status
DEVICE  TYPE      STATE     CONNECTION
ens33   ethernet  已連線    ens33

# nmcli device connect ens33        //啟用網卡   停用網卡:disconnect




# man nmtui
# nmtui

//先進行 PieTTY 設定:選項 --> 亞洲語系修正 --> Unicode 亞洲寬符號字元 (取消)











------------------------------------------------------------ 路由

2020年10月13日 星期二

JavaScript

 <!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title></title>

        <script>

            document.write("可以寫 JavaScript 的地方1:head 標籤內");

        </script>

        

    </head>

    <body>

        <header></header>

        <section>

            <script>

                document.write("可以寫 JavaScript 的地方2:body 標籤內");

            </script> 


            <script src="hello.js"> 

                document.write("Test!")               

            </script> 

            

            <script>

                var ret=alert("警告!");

                document.write("alert!結束...")                   

            </script>


            <script>

                var ret=confirm("確認?")

                document.write("<p>confirm結果傳回:"+ret+"</p>");                

            </script> 

            

            <script>

                var ret=prompt("請輸入帳號:");

                document.write(""+ret);

            </script>

                      

        </section>

        <footer></footer>


    </body>

</html>

-----------------------------------------------------------------2020-10-16

https://www.youtube.com/watch?v=35sPvHtT8iY&list=PLGBY4JjI_1Pgeq1vqOAZVlM7FzCrKkK-c&index=11

---------------------------------------------------------------------


var todos=["do1","do2","do3"]        //Array       


console.log(todos)                           //顯示
["do1", "do2", "do3"]

todos
["do1", "do2", "do3", "newdo"]

todos.push("newdo")                          //新增
console.log(todos)
["do1", "do2", "do3", "newdo"]


todos[2]="updated"                            //修改
console.log(todos)
["do1", "do2", "updated", "newdo"]

todos.splice(3,1)                                     //刪除
console.log(todos)
["do1", "do2", "updated"]



------------------------------------------------------------------函式

var todos=["k1","k2","k3"]

function displayTodos(){

    console.log(todos)

}


displayTodos()
["k1", "k2", "k3"]



function addTodos(todo){

    todos.push(todo)

    displayTodos()    

}

addTodos("Addtest")

["k1", "k2", "k3", "Addtest"]



function changeTodo(position,newTodo){

    todos[position]=newTodo

    displayTodos()

}

changeTodo(0,"updatedTodo")
["updatedTodo", "k2", "k3", "Addtest"]



function deleteTodo(position){

    todos.splice(position,1)

    displayTodos()

}


deleteTodo(2)
["updatedTodo", "k2", "Addtest"]



----------------------------------------------------------------物件


var person={

    name:"John",                   //屬性

    sayName:function(){      //方法

        console.log("Hi my name is",this.name)

    }


person.name
"John"


person.sayName()
Hi my name is John



----------------------------------------------------------------

var todos={

    todos:["k1","k2","k3"],

    displayTodo:function(){

        console.log(this.todos);

    },

       addTodo:function(todo){

        this.todos.push(todo);

        this.displayTodo()

    },

        changTodo:function(position,newvalue){

        this.todos[position]=newvalue;

        this.displayTodo()

    },

        deleteTodo:function(position){

        this.todos.splice(position,1);

        this.displayTodo()

    }


todos.displayTodo()
["k1", "k2", "k3"]


todos.addTodo("newk")
["k1", "k2", "k3", "newk"]


todos.changTodo(0,"updated")
["updated", "k2", "k3"]


todos.deleteTodo(0)
["k2", "k3"]





2020年10月3日 星期六

HTML5+CSS3+JavaScript

 

---------------------HTML5

HTML a 元素   

anchor 建立了通往其他頁面、檔案、Email 地址、或其他 URL 的超連結。


src --> img標籤,script標籤,iframe標籤;

是英語單詞source的縮寫

href   --> link標籤,a標籤

是Hypertext Reference的缩寫。 意思是指定超鏈結目標的URL。


rel

relation 關聯


HTML img alt -->圖片替代文字。 alternative 兩者(或若干)中擇一的;替代的;

HTML img title -->滑鼠移經顯示文字標示


------範例


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" href="09kkStyle.css">
        <style>
            body{
                width: 90%;
                margin: 0 auto;
                background-color: #EEFFBB;
                font-size: 1em;
                font-family: 新細明體,serif;
                color: #333333;
                line-height: 1.5em;
                letter-spacing: 0.05em;
            }
            header, section, footer{
                background-color: #F0F8FF;                              
                border-radius: 5px;                
                border: 1px solid #CCCCCC;
                box-shadow: 5px 0px 10px -3px #AAAAAA;
            }
            header p{
                font-size: 3.5em;
                font-family: 微軟正黑;
                color: #F0F8FF;
                text-align: center;
                letter-spacing: 1em;
                text-shadow: -2px -2px 0px #FFFFFF, 2px 2px 0px #444444, 2px 2px 6px #888888 ;
                margin-top: 40px;
            }
            #topnav{
                background-color: #FFF0E6;
                border-top: 1px dashed #FF9F60;
                border-bottom: 1px dashed #FF9F60;
                height: 40px;
            }           
            #topnav ul {
                float: left;
                left: 16%;
                position: relative;
                margin: 5px;               
            }
            
            #topnav li{
                float: left;
                padding: 4px;
                background-color: #FF6600;
                list-style-type: none;
                width: 85px;
                text-align: center;
                margin: 0 5px 0 0;
            }

            #topnav a{
                font-family: 新細明體;
                font-size: 1.1em;
                font-weight: bold;
                color: #FFFFFF;
                text-decoration: none;
            }
            
            #topnav a:hover{
                font-size: 1.2em;
                color: #000000;
                text-decoration: underline;
            }
            
            section{
                clear: left;
            }
            .Title01{
                font-size: 2em;
                font-family: 標楷體;
                text-shadow: 0 0 0.2em #87F, 0 0 0.2em #87F, 0 0 0.2em #87F;
            }
            figure {
                display:inline ;
                border: 1px solid #BFBFBF; 
                box-shadow: 2px 2px 3px rgba(135, 139, 133,0.4);
                float:left;
                margin: 0 15px;
            }

            figure img{
                display: table-row;
                margin: 5px 5px 10px 5px;
            }

            figcaption {
                display:block ;
                background-color: #145A32;
                color: #FFFFFF;
                font: italic smaller sans-serif;
            }
            #p1{
                margin: 15px ;
                text-align:justify;
            }
            #p2{
                margin: 15px;
                text-indent: 2em;
                text-align: justify;
            }
            #float_off{
                clear: both;
            }
            footer{               
                text-align: center;                
            }
            footer p{
               
                font-size: 1.5em;
                font-weight: bold;
                text-shadow:  1.4px 1.4px 1.3px #333333;
            }

        </style>
    </head>
    <header>
        <p>網站名稱</p>
        <nav id="topnav">
            <ul>
                <li><a href="#">首頁</a></li>
                <li><a href="#">網路學堂</a></li>
                <li><a href="#">蒐羅天下</a></li>
                <li><a href="#">部落格</a></li>
                <li><a href="#">專欄</a></li>
                <li><a href="#">免費廣告</a></li>
                <li><a href="#">下載專區</a></li>
                <li><a href="#">論壇</a></li>
            </ul>


        </nav>
    </header>
    <section>
        <p class="Title01">章節名稱</p>
        <figure>            
            <img src="pic/02.png" > 
            <figcaption>夜宿高山</figcaption>
        </figure>
        <p id="p1">
真的是太厲害了,用手抄寫經文,當成家裡壁紙!台南安南區一位75歲的阿伯,他七八年前退休後,就開始抄寫佛經,當成家裡的壁紙,走進他家,牆壁上、貼滿手寫經文,讓人大開眼界,他受訪時笑著說,對他來講,這也是一種修身養性的方式。經過台南安南區這裡的透天厝,常常有人會被,這醒目的黃色壁紙,給吸引住停下來看,走近一看,上面密密麻麻的,都是用手寫的佛家經文,整整齊齊大小一致,讓人忍不住讚嘆,而作者就是這位已經75歲的徐阿伯。這是他家不管是鐵捲門,或是壁磚上頭有護貝過的紙張,是他製作的佛經壁紙,七八年前他退休後,開始用手抄寫經文,當成修身養性的方式,慢慢地,這些妝點家裡的壁紙,讓看過的人印象深刻,阿伯的家,也成為這個區域,最有特色的房子。真的是太厲害了,用手抄寫經文,當成家裡壁紙!台南安南區一位75歲的阿伯,他七八年前退休後,就開始抄寫佛經,當成家裡的壁紙,走進他家,牆壁上、貼滿手寫經文,讓人大開眼界,他受訪時笑著說,對他來講,這也是一種修身養性的方式。經過台南安南區這裡的透天厝,常常有人會被,這醒目的黃色壁紙,給吸引住停下來看,走近一看,上面密密麻麻的,都是用手寫的佛家經文,整整齊齊大小一致,讓人忍不住讚嘆,而作者就是這位已經75歲的徐阿伯。這是他家不管是鐵捲門,或是壁磚上頭有護貝過的紙張,是他製作的佛經壁紙,七八年前他退休後,開始用手抄寫經文,當成修身養性的方式,慢慢地,這些妝點家裡的壁紙,讓看過的人印象深刻,阿伯的家,也成為這個區域,最有特色的房子。
        </p>
        <p id="p2">
            真的是太厲害了,用手抄寫經文,當成家裡壁紙!台南安南區一位75歲的阿伯,他七八年前退休後,就開始抄寫佛經,當成家裡的壁紙,走進他家,牆壁上、貼滿手寫經文,讓人大開眼界,他受訪時笑著說,對他來講,這也是一種修身養性的方式。
            經過台南安南區這裡的透天厝,常常有人會被,這醒目的黃色壁紙,給吸引住停下來看,走近一看,上面密密麻麻的,都是用手寫的佛家經文,整整齊齊大小一致,讓人忍不住讚嘆,而作者就是這位已經75歲的徐阿伯。
            這是他家不管是鐵捲門,或是壁磚上頭有護貝過的紙張,是他製作的佛經壁紙,七八年前他退休後,開始用手抄寫經文,當成修身養性的方式,慢慢地,這些妝點家裡的壁紙,讓看過的人印象深刻,阿伯的家,也成為這個區域,最有特色的房子。
                    </p>
        <p id="float_off"></p>
    </section>
    <footer><p>CopyRight (c) 2020 GuoChin All Righs Reserved.</p></footer>
</html>




 

2020年9月19日 星期六

CentOS8 參照 2015年7月3日 CentOS7練習


此篇已經重新謄錄完成!!

可以作廢。




HostOS:
windows10
192.168.2.100

若無法 ping :
控制台\系統及安全性\Windows Defender 防火牆-->進階設定-->輸入規則
啟用  檔案及印表機共用(回應要求-ICMPv4-IN)  設定檔:私人   -->啟用規則


GuestOS:
CentOS8
192.168.2.103

# ping 192.168.2.100
PING 192.168.2.100 (192.168.2.100) 56(84) bytes of data.
64 bytes from 192.168.2.100: icmp_seq=1 ttl=128 time=0.367 ms
.
.


----------------------------------------------- 啟用網卡

# ip addr
# ip -s link
# ip link set ens33 up        //啟用網路介面卡   up:開    down:關

# nmcli device status
DEVICE  TYPE      STATE     CONNECTION
ens33   ethernet  已連線    ens33
lo      loopback  不受管理  --

# nmcli device connect ens33        //啟用網卡   停用網卡:disconnect
裝置「ens33」已成功以「9cb77588-c78e-40b0-acbe-3be164c3e385」啟用。


# nmtui        //啟用連線






----------------------------------------------- 路由

# ip route | column -t
default         via  192.168.2.1  dev    ens33   proto  static  metric  100             
192.168.2.0/24  dev  ens33        proto  kernel  scope  link    src     192.168.2.103  metric  100

# ip route | column -t > kkRouteTable.txt
# ls
kkRouteTable.txt
# cat kkRouteTable.txt



# ip -6 route | column -t        //IPv6 Route Table
::1        dev  lo     proto  kernel  metric  256  pref  medium
fe80::/64  dev  ens33  proto  kernel  metric  100  pref  medium



# tracepath 168.95.1.1        //traceroute


# ss -antp |column -t        //對應 netstat -antp



# ss -t


                   




----------------------------------------------- 

# systemctl list-unit-files                     //查詢服務啟動或是關閉狀態,以檔名顯示

# systemctl list-units                           //查詢目前所有已啟動的服務
UNIT                                               LOAD   ACTIVE SUB       DESCRIPTION
...
crond.service                                      loaded active running   Command Scheduler
...
firewalld.service                                  loaded active running   firewalld - dynamic firew>
...
NetworkManager.service                             loaded active running   Network Manager
...
sshd.service                                       loaded active running   OpenSSH server daemon
...



# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-03-03 07:47:29 CST; 1h 40min ago


# systemctl stop firewalld.service                   //立即停止xxx.service
# systemctl start firewalld.service                  //立即啟動xxx.service
# systemctl is-active firewalld.service
active


# systemctl disable firewalld.service            //設定開機不啟動xxx.service
# systemctl enable firewalld.service            //設定開機啟動xxx.service

# chkconfig firewalld off                             //設定 firewalld 開機時不要啟動
# chkconfig firewalld on                             //設定 firewalld 開機時啟動,且不加.service


# systemctl is-enabled firewalld.service
enabled




----------------------------------------------- 

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
...


# vi /etc/sysconfig/selinux        //關閉SELINUX
...
SELINUX=disabled
...




----------------------------------------------- 

# journalctl               //日誌檢視說明
# journalctl -n10      //列出最後10行資料
# journalctl -xn        //列出最後事件,並提供相關解決問題資訊

# journalctl --follow            //持續列出最後10行事件記錄
-- Logs begin at Tue 2020-03-03 07:47:06 CST. --
 3月 03 09:31:32 Ku.CentOS8 systemd[1]: Stopped firewalld - dynamic firewall daemon.
...


# tail -n 10 -f /var/log/messages
Mar  3 09:31:43 kk systemd[1]: Stopping firewalld - dynamic firewall daemon...
Mar  3 09:31:44 kk systemd[1]: Stopped firewalld - dynamic firewall daemon.





-----------------------------------------------


(一)使用者的設定

# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

# crontab -e
53 07 * * * /usr/bin/ls

# crontab -l
53 07 * * * /usr/bin/ls

# cat /var/spool/cron/root
53 07 * * * /usr/bin/ls


# journalctl -n 10
...

 3月 04 07:51:52 Ku.CentOS8 crontab[1733]: (root) BEGIN EDIT (root)
 3月 04 07:52:43 Ku.CentOS8 crontab[1733]: (root) REPLACE (root)
 3月 04 07:52:43 Ku.CentOS8 crontab[1733]: (root) END EDIT (root)
 3月 04 07:53:01 Ku.CentOS8 crond[967]: (root) RELOAD (/var/spool/cron/root)
 3月 04 07:53:01 Ku.CentOS8 systemd[1]: Started Session 3 of user root.
 3月 04 07:53:01 Ku.CentOS8 CROND[1737]: (root) CMD (/usr/bin/ls  )
...


# cat /var/log/cron
...
Mar  4 07:51:52 Ku crontab[1733]: (root) BEGIN EDIT (root)
Mar  4 07:52:43 Ku crontab[1733]: (root) REPLACE (root)
Mar  4 07:52:43 Ku crontab[1733]: (root) END EDIT (root)
Mar  4 07:53:01 Ku crond[967]: (root) RELOAD (/var/spool/cron/root)
Mar  4 07:53:01 Ku CROND[1737]: (root) CMD (/usr/bin/ls  )
...


# tail /var/log/cron
...






(二)系統的設定檔

# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

00 08 * * * root /usr/bin/ls



# systemctl list-units
UNIT                          LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting   Arbitrary Executable >
...
crond.service                 loaded active running   Command Scheduler
...
firewalld.service             loaded active running   firewalld - dynamic firewall daemon
...
NetworkManager.service        loaded active running   Network Manager
...
sshd.service                  loaded active running   OpenSSH server daemon


# systemctl restart crond

# tail /var/log/cron
...
Mar  5 08:00:01 Ku crond[974]: (*system*) RELOAD (/etc/crontab)
Mar  5 08:00:01 Ku CROND[1765]: (root) CMD (/usr/bin/ls)
Mar  5 08:00:01 Ku CROND[1764]: (root) CMDOUT (anaconda-ks.cfg)
Mar  5 08:00:01 Ku CROND[1764]: (root) CMDOUT (kkRouteTable.txt)
...


# journalctl -n 10
-- Logs begin at Thu 2020-03-05 07:42:10 CST, end at Thu 2020-03-05 08:01:01 CS>
 3月 05 08:00:01 Ku.CentOS8 crond[974]: (*system*) RELOAD (/etc/crontab)
 3月 05 08:00:01 Ku.CentOS8 CROND[1765]: (root) CMD (/usr/bin/ls)
 3月 05 08:00:01 Ku.CentOS8 CROND[1764]: (root) CMDOUT (anaconda-ks.cfg)
 3月 05 08:00:01 Ku.CentOS8 CROND[1764]: (root) CMDOUT (kkRouteTable.txt)
...





-----------------------------------------------

# date
四  3月  5 11:06:39 CST 2020


// 更改日期間:  MMDDhhmmYYYY  月日時分年
# date 040608302020
一  4月  6 08:30:00 CST 2020




//查看 BIOS 時間
# hwclock -r
2020-03-05 11:13:12.171152+08:00


//將電腦日期時間寫入到 BIOS 時間
# hwclock -w



-----------------------------------------------







-----------------------------------------------







-----------------------------------------------







-----------------------------------------------







-----------------------------------------------







-----------------------------------------------







----------------------------------------------- 

Python 程式設計

Ch1 認識 Python
1-1

CentOS8 Apache



-------------------------------------------------

// DNF  is  the  next upcoming major version of YUM, a package manager for
   RPM-based Linux distributions.
# dnf -y install httpd

# rpm -qa | grep httpd
httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64
centos-logos-httpd-80.5-2.el8.noarch
httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64
httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch

//執行檔
# ls /usr/sbin | grep httpd
httpd

//設定檔
# ls /etc/httpd/conf
httpd.conf 

//站台預設 跟目錄
# ls /var/www/
html

# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service


//displays information about a selection of the active processes.
//To see every process on the system using BSD syntax:
# ps -axu | grep httpd
root       958  0.0  0.5 280208 10988 ?        Ss   14:30   0:00 /usr/sbin/httpd -DFOREGROUND
apache     991  0.0  0.4 292424  8252 ?        S    14:30   0:00 /usr/sbin/httpd -DFOREGROUND
...



# ls /usr/lib/systemd/system | grep httpd
httpd.service
httpd@.service
httpd.service.d
httpd.socket
httpd.socket.d



# firewall-cmd --state
running

# firewall-cmd --get-service | grep http

# ls /usr/lib/firewalld/services/ | grep http
https.xml
http.xml
wbem-https.xml
wbem-http.xml

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens32
  sources:
  services: cockpit dhcpv6-client http ssh
...


HostOS
http://192.168.1.4/




-------------------------------------------------設定虛擬目錄 Alias-------在其他的系統目錄 /opt


# ls -l /
...
drwxr-xr-x.   2 root root    6  5月 11  2019 opt
...

# mkdir /opt/web

# echo Hello Alias > /opt/web/index.html

# ls -l /opt
drwxr-xr-x. 2 root root 24  3月 26 14:59 web

# ls -l /opt/web/
-rw-r--r--. 1 root root 12  3月 26 14:59 index.html


# vi /etc/httpd/conf/httpd.conf
...
Alias /kk1web /opt/web
<Directory /opt/web>
   Require all granted
</Directory>


# systemctl restart httpd.service




HostOS
http://192.168.1.4/kk1web/
Hello Alias






-------------------------------------------------設定虛擬目錄 Alias-------在 /home

# vi /var/www/html/1.html
This is /var/www/html/1.html


HostOS
http://192.168.1.4/1.html
This is /var/www/html/1.html




# mkdir /home/web

# vi /home/web/1.html
This is One Web on /home/web


# vi /etc/httpd/conf/httpd.conf
...
Alias /web01 /home/web
<Directory "/home/web">
    Require all granted
</Directory>

# systemctl restart httpd.service


HostOS
http://192.168.1.4/web01/1.html
Forbidden
You don't have permission to access /web01/1.html on this server.


# tail -1 /var/log/httpd/error_log
[Thu Mar 26 15:15:25.107073 2020] [core:error] [pid 2426:tid 139987941058304] (13)Permission denied: [client 192.168.1.2:52012] AH00132: file permissions deny server access: /home/web/1.html



# ls -Z /var/www
system_u:object_r:httpd_sys_content_t:s0 html

# ls -Z /var/www/html
unconfined_u:object_r:httpd_sys_content_t:s0 1.html


# ls -Z /
...
system_u:object_r:usr_t:s0 opt

# ls -Z /home
unconfined_u:object_r:user_home_dir_t:s0 web

# ls -Z /home/web/
unconfined_u:object_r:user_home_t:s0 1.html

# chcon -t httpd_sys_content_t /home/web

# ls -Z /home
unconfined_u:object_r:httpd_sys_content_t:s0 web