Linux的LAMP環境搭建,SQL語句,文件共享

一、搭建php-fpm工做方式的LAMP環境,實現wordpress正常訪問
1)安裝程序包php

[root@silassu  ~]# yum install mariadb-server php-fpm httpd php-mysql

2)Mysql服務的搭建html

[root@silassu ~]# cat /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]

# this is only for embedded server
[embedded]

# This group is only read by MariaDB-5.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mysqld-5.5]

# These two groups are only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

[mariadb-5.5]

[root@silassu ~]# systemctl start mariadb.service
[root@silassu ~]# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      50            *:3306                      *:*     
[root@silassu ~]# mysql_secure_installation
[root@silassu ~]# mysql -uroot -p123qwe
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> GRANT ALL ON *.* to 'wordpress'@'120.79.170.206' IDENTIFIED BY '123qwe';
MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wpuser'@'120.79.170.206' IDENTIFIED BY '123qwe';
MariaDB [(none)]> FLUSH PRIVILEGES;

3)Php-fpm服務器的搭建mysql

[root@silassu ~]# vi /etc/php-fpm.d/www.conf    #修改相關參數
[root@silassu ~]# mkdir -pv /var/lib/php/session
[root@silassu ~]# chown apache:apache /var/lib/php/session/
[root@silassu ~]# systemctl start php-fpm.service
[root@silassu ~]# ss -tnl
State       Recv-Q Send-Q                                                Local Address:Port                                                               Peer Address:Port              
LISTEN      0      128                                                               *:22                                                                            *:*                  
LISTEN      0      128                                                       127.0.0.1:9000                                                                          *:*                  
LISTEN      0      50                                                                *:3306                                                                          *:*                  
[root@silassu ~]# systemctl status php-fpm.service
● php-fpm.service - php-fpm
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: activating (start) since Mon 2018-12-17 15:14:01 CST; 1min 14s ago
 Main PID: 10980 (code=exited, status=78);         : 11027 (php-fpm)
   CGroup: /system.slice/php-fpm.service
           ├─11027 php-fpm: master process (/etc/php-fpm.conf)
           ├─11029 php-fpm: pool www
           ├─11030 php-fpm: pool www
           ├─11031 php-fpm: pool www
           ├─11032 php-fpm: pool www
           └─11033 php-fpm: pool www

Dec 17 15:14:01 silassu systemd[1]: Starting php-fpm...

4)搭建httpd服務linux

[root@silassu ~]# httpd -M | grep fcgi
proxy_fcgi_module (shared)
[root@silassu ~]# cat /etc/httpd/conf.d/fcgi.conf 
Listen 8080
<VirtualHost *:8080>
        DirectoryIndex index.php
        ServerName www.silassu.com
        DocumentRoot /var/www/html
        ProxyRequests off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
        ProxyPassMatch ^/(ping|pmstatus)$ fcgi://127.0.0.1:9000/$1
        <Directory "/var/www/html">
               options none
               Allowoverride None
               Require all granted
        </Directory>
</VirtualHost>

5)建立測試文件sql

[root@silassu ~]# cat /var/www/html/index.php
<?php
          phpinfo();
?>
[root@silassu ~]# cat /var/www/html/mysql.php 
<?php
         $conn = mysql_connect('120.79.170.206','wordpress','123qwe');
         if ($conn)
                 echo "Connected to mysql.";
         else
                 echo "Fail";
?>

6)搭建wordpressshell

[root@silassu ~]#unzip wordpress-5.0.1-zh_CN.zip -d /var/www/html/

Linux的LAMP環境搭建,SQL語句,文件共享
Linux的LAMP環境搭建,SQL語句,文件共享
Linux的LAMP環境搭建,SQL語句,文件共享


二、什麼是DML?經常使用SQL舉例,每一個命令至少1個例子,最多不超過3個例子數據庫

DML( Data Manipulation Language):數據庫操做語言:SQL中處理數據庫中的數據;其主要命令有SELECT,INSERT,UPDATE,DELETE等。
    SELECT
        1)查詢指定表的全部數據
                SELECT * FROM  table_name
        2)查詢指定字段的數據,字段名能夠顯示別名
                SELECT field1,field2,…FROM table_name;
        3)根據指定條件查詢數據,分組,排序
                SELECT field,…FROM table_name WHERE condition GROUP BY field HAVING COUNT(*) >= '' ORDER BY field [ASC|DESC]; 
                condition:用於指明挑選條件
                GROUP BY:分組
                ORDER BY:排序
                        ASC:升序
                        DESC:降序

Linux的LAMP環境搭建,SQL語句,文件共享

INSERT
        1)默認根據表結構插入數據
                INSERT INTO table_name VALUES (value1,value2,value3,value4);
        2)往指定字段插入數據,剩餘字段不能爲非空
                INSERT INTO table_name (field1,field2,field3,field4) VALUES (value1,value2,value3,value4);

Linux的LAMP環境搭建,SQL語句,文件共享

UPDATE :表數據更新
            UPDATE table_name SET field=new_value WHERE condition;
            condition:用於指明挑選條件

Linux的LAMP環境搭建,SQL語句,文件共享

DELETE:刪除行數據
            DELETE FROM table_name WHERE condition
            condition:用於指明挑選條件

Linux的LAMP環境搭建,SQL語句,文件共享

DDL( Data Definition Language):數據庫服務器端命令的一種語言類型,表示數據定義語言,主要用於管理數據庫組件,例如數據庫,表,索引,視圖,用戶,存儲過程等;經常使用命令有CREATE,ALTER,DROP等;
    CREATE(建立)
            CREATE DATABASE 建立數據庫
            CREATE TABLE 建立表
            CREATE USER 建立用戶

Linux的LAMP環境搭建,SQL語句,文件共享

SHOW(查看)
            SHOW CREATE DATABASE 查看建立的數據庫
            SHOW CREATE TABLE 查看建立的表

Linux的LAMP環境搭建,SQL語句,文件共享

ALTER(修改)
            ALTER DATABASE 修改數據庫
            ALTER TABLE 修改表

Linux的LAMP環境搭建,SQL語句,文件共享

DROP(刪除)
            DROP DATABASE 刪除數據庫
            DROP TABLE 刪除表
            DROP USER 刪除用戶

Linux的LAMP環境搭建,SQL語句,文件共享


三、簡述ftp的主動和被動模式,並實現基於pam認證的vsftpdapache

FTP(File transfer Protocl):文件傳輸協議,是用於在網絡中控制文件的雙向傳輸的協議。FTP協議運行在TCP/21和20端口,一般來講21端口是命令端口、20端口是數據端口,但根據FTP的工做模式的不一樣,數據端口也有可能跟着改變。
     鏈接方式:
             命令鏈接:傳輸命令
             數據鏈接:傳輸數據
    工做模式:
            主動模式(PORT):服務器向客戶端發起數據傳輸請求;服務器端口是固定的;
            缺點:服務器帶客戶端的FTP鏈接很容易被傳輸過程當中的路由器、防火牆所影響或攔截。

Linux的LAMP環境搭建,SQL語句,文件共享

被動模式(PASV):客戶端向服務器端發起數據傳輸請求;服務器端口:半隨機,是隨機的;
            爲了解決主動模式所面臨的服務器到客戶端的鏈接會被攔截阻塞的問題,FTP發展出了被動模式。在被動模式中,命令鏈接和數據鏈接都由客戶端來發起,這樣就能夠解決從服務器到客戶端的數據端口的入方向鏈接被防火牆攔截的問題。

Linux的LAMP環境搭建,SQL語句,文件共享

vfs 配置
             主程序:/usr/sbin/vsftpd
             主配置文件:/etc/vsftpd/vsftpd.conf
             數據根目錄:/var/ftp
             Systemd Unit File :/usr/lib/systemd/systemd/vsftpd.service
             禁止登錄用戶列表:/etc/vsftpd/ftpusers
             用戶列表/etc/vsftpd/user_list

1)數據庫設置
[root@silassu ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 173
Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> CREATE DATABASE vsftpd;
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> USE vsftpd;
Database changed
MySQL [vsftpd]> CREATE TABLE users(id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,name CHAR(50) BINARY NOT NULL,password CHAR(48) BINARY NOT NULL);
Query OK, 0 rows affected (0.02 sec)

MySQL [vsftpd]> DESC users;
+----------+----------+------+-----+---------+----------------+
| Field    | Type     | Null | Key | Default | Extra          |
+----------+----------+------+-----+---------+----------------+
| id       | int(11)  | NO   | PRI | NULL    | auto_increment |
| name     | char(50) | NO   |     | NULL    |                |
| password | char(48) | NO   |     | NULL    |                |
+----------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

MySQL [vsftpd]> INSERT INTO users(name,password) VALUE('PaulCormier',password('RedHat'));
Query OK, 1 row affected (0.08 sec)

MySQL [vsftpd]> INSERT INTO users(name,password) VALUE('CamilleGutt',password('CentOS'));
Query OK, 1 row affected (0.00 sec)

MySQL [vsftpd]> SELECT * FROM users;
+----+-------------+-------------------------------------------+
| id | name        | password                                  |
+----+-------------+-------------------------------------------+
|  1 | PaulCormier | *023141D26FD2A879F5D82DE673D789E1508C9008 |
|  2 | CamilleGutt | *2273FEDA7433D659EE517A065F38BE5B8035F2C2 |
+----+-------------+-------------------------------------------+
2 rows in set (0.00 sec)

MySQL [vsftpd]> GRANT SELECT ON vsftpd.* TO 'vsftpd'@'127.0.0.1' IDENTIFIED BY 'RedHat';
Query OK, 0 rows affected (0.00 sec)

MySQL [vsftpd]> GRANT SELECT ON vsftpd.* TO 'vsftpd'@'localhost' IDENTIFIED BY 'RedHat';
Query OK, 0 rows affected (0.00 sec)

MySQL [vsftpd]>
2)安裝vsftpd服務
[root@silassu ~]# setenforce 0
[root@silassu ~]# iptables -F
[root@silassu ~]# yum install mariadb-devel pam-devel openssl-devel -y
[root@silassu ~]# tar -xf pam_mysql-0.7RC1.tar.gz
[root@silassu ~]# cd pam_mysql-0.7RC1/
[root@silassu pam_mysql-0.7RC1]# ./configure --with-mysql=/usr --with-openssl=/usr --with-pam=/usr --with-pam-mods-dir=/lib64/security
[root@silassu pam_mysql-0.7RC1]# make && make install
[root@silassu ~]# cd /usr/lib64/security/
[root@silassu security]# ls
pam_access.so    pam_deny.so       pam_filter      pam_lastlog.so    pam_mkhomedir.so   pam_pwhistory.so       pam_selinux.so     pam_tally2.so     pam_unix_auth.so     pam_wheel.so
pam_cap.so       pam_echo.so       pam_filter.so   pam_limits.so    pam_mysql.so        pam_pwquality.so       pam_sepermit.so    pam_time.so       pam_unix_passwd.so   pam_xauth.so
pam_chroot.so    pam_env.so        pam_ftp.so      pam_listfile.so   pam_namespace.so   pam_rhosts.so          pam_shells.so      pam_timestamp.so  pam_unix_session.so
pam_console.so   pam_exec.so       pam_group.so    pam_localuser.so  pam_nologin.so     pam_rootok.so          pam_stress.so      pam_tty_audit.so  pam_unix.so
pam_cracklib.so  pam_faildelay.so  pam_issue.so    pam_loginuid.so   pam_permit.so      pam_securetty.so       pam_succeed_if.so  pam_umask.so      pam_userdb.so
pam_debug.so     pam_faillock.so   pam_keyinit.so  pam_mail.so       pam_postgresok.so  pam_selinux_permit.so  pam_systemd.so     pam_unix_acct.so  pam_warn.so
[root@silassu ~]# yum install vsftpd -y
[root@silassu ~]# mkdir /ftproot/vuser -pv
mkdir: created directory ‘/ftproot’
mkdir: created directory ‘/ftproot/vuser’
[root@silassu ~]# useradd -s /sbin/nologin -d /ftproot/vuser/ vuser
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@silassu ~]# chmod u-w /ftproot/vuser/
[root@silassu ~]# cd /etc/pam.d/
[root@silassu pam.d]# vim vsftpd.mysql
[root@silassu pam.d]# cat vsftpd.mysql 
auth required /usr/lib64/security/pam_mysql.so user=vsftpd passwd=redhat host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2

account required /usr/lib64/security/pam_mysql.so user=vsftpd passwd=redhat host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
[root@silassu pam.d]# vim /etc/vsftpd/vsftpd.conf
[root@silassu pam.d]# cat /etc/vsftpd/vsftpd.conf
......
pam_service_name=vsftpd.mysal
guest_enable=NO
guest_username=vuser
userlist_enable=YES
tcp_wrappers=YES
[root@silassu ~]# cd
[root@silassu ~]# cd /etc/vsftpd/vusrs_conf/
[root@silassu vusrs_conf]# vim PaulCormier
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@silassu vusrs_conf]# vim CamilleGutt
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
[root@silassu ~]# systemctl start vsftpd
3)客戶端測試
[root@SilasSZL ~]# yum install ftp -y 
[root@SilasSZL ~]# ftp 192.168.2.100
Connected to 192.168.2.100 (192.168.2.100).
220 (vsFTPd 3.0.2)
Name (10.9.3.244:root): PaulCormier
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd /etc
Local directory now /etc
ftp> put issue
local: issue remote: issue
227 Entering Passive Mode (192.168.2.100,24,224).
150 Ok to send data.
226 Transfer complete.
47 bytes sent in 0.000194 secs (242.27 Kbytes/sec)
ftp> mkdir sharetest
257 "/upload/sharetest" created
ftp> rm sharetest
250 Remove directory operation successful.
[root@SilasSZL ~]# ftp 192.168.2.100
Connected to 192.168.2.100 (192.168.2.100).
220 (vsFTPd 3.0.2)
Name (192.168.2.100:root): CamilleGutt
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd /etc
Local directory now /etc
ftp> mkdir share
550 Permission denied.
ftp> put issue
local: issue remote: issue
227 Entering Passive Mode (192.168.2.100,24,175).
550 Permission denied.

四、簡述NFS服務原理及配置vim

NFS(Network File System):網絡文件系統,它容許網絡中的計算機之間經過TCP/IP網絡共享資源。在NFS中,客戶端能夠透明讀寫服務器端上的文件,就像訪問本地文件同樣,經過掛載的方式將服務器的文件掛載到本地,如同本地磁盤同樣。
    NFS服務的優缺點
        優勢:
            節省本地存儲空間,將經常使用的數據存放在一臺能夠經過網絡訪問的服務器上
            簡單容易上手
            方便部署很是快速,維護十分簡單
        缺點:
            容易發生單點故障,須要作備份處理
            在高併發環境中效率性能有限
            客戶端沒有認證機制,數據經過明文傳輸,缺少安全性
            對數據的完整性不作驗證
            多臺機器掛載NFS服務器時,鏈接管理維護比較麻煩

Linux的LAMP環境搭建,SQL語句,文件共享
1)nfs服務端配置安全

[root@silassu ~]# yum -y install nfs-utils.x86_64
[root@silassu ~]# yum -y install rpcbind
[root@silassu ~]# mkdir /tmp/test
[root@silassu ~]# vi /etc/exports
[root@silassu ~]# cat /etc/exports
/tmp/text 192.168.2.104(rw,sync,root_squash)
[root@silassu ~]# systemctl start rpcbind
[root@silassu ~]# systemctl status nfs-server.service

2)客戶端掛載共享目錄

[root@silassu ~]# showmount -e 192.168.2.103
Export list for 192.168.2.103:
/tmp/test 192.168.2.104
[root@silassu ~]# mkdir /tmp/test
[root@silassu ~]# mount -t nfs 192.168.2.103:/tmp/test /tmp/test
[root@silassu ~]# cd /tmp/test
[root@silassu test]# ls
[root@silassu test]# vi nfs-share.txt
this is a client nfs share file

3)服務端驗證

[root@silassu ~]# cd /tmp/test/
[root@silassu test]# ls
nfs-share.txt
[root@silassu test]# cat nfs-share.txt
this is a client nfs share file

五、簡述samba服務,並實現samba配置

Samba是在Linux和UNIX系統上實現SMB協議的一個免費軟件,由服務器及客戶端程序構成。SMB(Server Messages Block,信息服務塊)是一種在局域網上共享文件和打印機的一種通訊協議,它爲局域網內的不一樣計算機之間提供文件及打印機等資源的共享服務。SMB協議是客戶機/服務器型協議,客戶機經過該協議能夠訪問服務器上的共享文件系統、打印機及其餘資源。例如Windows和Linux,Windows和Unix等,能夠使用samba服務器來解決兩者傳輸問題。
    SAMBA主要提供的是SMB/CIFS或者NETBIOS協議的。

    samba用戶管理:smbpasswd命令;
    smbpasswd [options] USERNAME
        -a:添加
        -x:刪除
        -d:禁用
        -e:啓用
    pdbedit
        -L:列出samba服務中的全部用戶;
        -a, --create:添加用戶爲samba用戶;
        -u, --user=USER:要管理的用戶;
        -x, --delete:刪除用戶;
        -t, --password-from-stdin:從標準輸出接收字符串做爲用戶密碼;使用空提示符,然後將密碼輸入兩次;

samba服務的程序安裝和配置

[root@silassu ~]# yum install samba -y
[root@silassu ~]# rpm -ql samba
/etc/openldap/schema
/etc/openldap/schema/samba.schema
/etc/pam.d/samba
/usr/bin/eventlogadm
/usr/bin/smbstatus
/usr/lib/systemd/system/nmb.service
/usr/lib/systemd/system/smb.service
......
[root@silassu ~]# rpm -ql samba-common
/etc/logrotate.d
/etc/logrotate.d/samba
/etc/samba
/etc/samba/lmhosts
/etc/samba/smb.conf
/etc/samba/smb.conf.example
/etc/sysconfig/samba
/usr/lib/tmpfiles.d/samba.conf
/usr/share/man/man5/lmhosts.5.gz
/usr/share/man/man5/smb.conf.5.gz
/usr/share/man/man5/smbpasswd.5.gz
/usr/share/man/man7/samba.7.gz
/var/lib/samba
/var/lib/samba/lock
/var/lib/samba/private
/var/log/samba
/var/log/samba/old
/var/run/samba
/var/run/winbindd
[root@silassu ~]# iptables -F
[root@silassu ~]# setenforce 0
[root@silassu ~]# mkdir /share
[root@silassu ~]# vim /etc/samba/smb.conf
[root@silassu ~]# cat /etc/samba/smb.conf
......
[share]
        comment=share
        path=/share
        guest ok=yes
        read only=no
[root@silassu ~]# testparm
[root@silassu ~]# useradd samba
[root@silassu ~]# pdbedit -a samba
new password:
retype new password:
Unix username:        samba
NT username:          
Account Flags:        [U     
User SID:             S-1-5-21-3402031604-584554795-1042339899-1000
Primary Group SID:    S-1-5-21-3402031604-584554795-1042339899-513
Full Name:            
Home Directory:       \\silassu\samba
HomeDir Drive:        
Logon Script:         
Profile Path:         \\silassu\samba\profile
Domain:               SILASSU
Account desc:         
Workstations:         
Munged dial:          
Logon time:           0
Logoff time:          Wed, 06 Feb 2036 23:06:39 CST
Kickoff time:         Wed, 06 Feb 2036 23:06:39 CST
Password last set:    Wed, 19 Dec 2018 11:51:23 CST
Password can change:  Wed, 19 Dec 2018 11:51:23 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

[root@silassu ~]# systemctl start smb
相關文章
相關標籤/搜索