Manage run levels
RHEL6: operation level 300
0: shutdown 0 services
1: Single user mode (implementation of basic functions, cracking Linux passwords) 50 services
2: Multi user character interface (network not supported) 80 services
3: The multi-user character interface (supporting network) server has 100 service levels by default
4: 0 services are not defined
5: Graphical interface} 300 services
6: Restart 0 services
Switch operation level: init # number
RHEL7: operation mode (operation level)
Character mode: multi user target
Graphics mode: graphical target
Currently switch directly to character mode
]# systemctl isolate multi-user.target #Equivalent to the original init 3
Currently switch directly to graphics mode
]# systemctl isolate graphical.target #Equivalent to the original init 5
View the default entry mode for each boot
[root@svr7 /]# systemctl get-default Set permanent policy, and enter automatically every time you start multi-user.target [root@svr7 /]# systemctl set-default multi-user.target [root@svr7 /]# reboot
2, Introduction to Web server
- Web services based on B/S (Browser/Server) architecture
- The server provides Web pages
- The browser downloads and displays the web page
- Hyper Text Markup Language
- Hyper Text Transfer Protocol
Three step strategy: packaging, configuration and service startup
Software for realizing Web functions: httpd, Nginx, Tomcat
httpd by the software foundation Apache
Virtual machine A: building basic Web services
]# yum -y install httpd ]# rpm -q httpd ]# echo NSD Web Server > /var/www/html/index.html ]# > /etc/resolv.conf ]# systemctl restart httpd #Restart the service ]# curl http://192.168.4.7 # test access NSD Web Server
- Reason for displaying the test page (welcome page)
1. No web documents have been written
2. The written page file is not named index html
3. Store the web page file directory. The access rule is to deny all clients access
- Default configuration provided
- Listen: listening address: port (80)
- ServerName: DNS name registered in this site (empty)
- DocumentRoot: Web page root (/ var/www/html)
- DirectoryIndex: start page / first page file name (index.html)
Main configuration file: / etc / httpd / conf / httpd conf
Common errors:
[root@svr7 ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@svr7 ~]# journalctl -xe
DocumentRoot: Web page file root (/ var/www/html)
virtual machine A ]# mkdir /var/www/myweb ]# echo wo shi myweb > /var/www/myweb/index.html ]# vim /etc/httpd/conf/httpd.conf .......Ten thousand words are omitted here DocumentRoot "/var/www/myweb" #Modify configuration .......Ten thousand words are omitted here ]# systemctl restart httpd #Restart service ]# curl http://192.168.4.7 wo shi myweb
Web services are directed to the directory where web pages are stored
Default inheritance
/# deny all clients access
/var/www # allows all clients to access
Conclusion: the client can only access the web page file under / var/www
/webroot
/ var/www/myweb # allows all clients to access
/ var/www/myweb/cbd # allow all clients to access
/ var # deny all client access
- Access control based on web file directory
When the subdirectory has no rules, it inherits the rules of the upper level directory by default
If there is a separate configuration for this directory, the upper level directory rules will not be inherited
Conclusion: the client can only access the web page file under / var/www
Container format
Container format: <Directory /> Require all denide #Reject everyone <Directory> <Dirctory "/var/www"> Require all granted #Allow everyone </Directory> virtual machine A: ]# mkdir /webroot ]# echo wo shi webroot > /webroot/index.html ]# vim /etc/httpd/conf/httpd.conf .......Ten thousand words are omitted here DocumentRoot "/webroot" <Directory "/webroot"> #For / webroot path Require all granted #Allow everyone access </Directory> .......Ten thousand words are omitted here ]# systemctl restart httpd #Restart service ]# curl http://192.168.4.7 wo shi webroot
Client: curl http://192.168.4.7---- >Server ---- > HTTP protocol ---- > httpd process ---- "/ etc / httpd / conf / httpd conf---->DocumentRoot ---->/webroot----->index. html
Client: curl http://192.168.4.7 # network path
Server: / Webroot / index HTML # actual path
http://192.168.4.7 = DocumentRoot /webroot
Client: curl http://192.168.4.7/abc
Server: / Webroot / ABC / index HTML # actual path
- Network path and actual path
DocumentRoot --->/webroot
Network path: curl http://192.168.4.7
Actual service: / webroot
Access procedure: client curl http://192.168.4.7--- >Server 192.168.4.7 --- "80 ---" httpd --- "/ etc / httpd / conf / httpd conf--->DocumentRoot --->/webroot--->index.html
Network path: curl http://192.168.4.7/abc
Actual service: / Webroot / ABC / index html
virtual machine A ]# mkdir /webroot/abc ]# echo wo shi abc > /webroot/abc/index.html ]# curl http://192.168.4.7/abc/
- Listen: listening IP address: listening port (80)
Port: the digital number plays the role of identification and identifies the protocol
http protocol default port: 80
It is recommended to customize the port, which is greater than 1024 and the port limit is 65535
[root@svr7 ~]#vim /etc/httpd/conf/httpd.conf .......Ten thousand words are omitted here Listen 80 Listen 8100 .......Ten thousand words are omitted here [root@svr7 ~]# systemctl restart httpd [root@svr7 ~]#curl 192.168.4.7:8100 [root@svr7 ~]#curl 192.168.4.7 #The default is port 80
<VirtualHost *:80> ServerName www.qq.com DocunentRoot /var/www/qq <VirtualHost *:80> <VirtualHost *:80> SeverName www.lol.com DocunmentRoot /var/www/lol <VirtualHost *:80>
3, Virtual Web host
- Virtual Web host
- Multiple different Web sites are provided by the same server
- Distinguishing mode
- Domain name based virtual host
- Port based virtual host
- IP address based virtual host
- Profile path
- /etc/httpd/conf/httpd.conf # main configuration file
- /etc/httpd/conf.d/*.conf # call configuration file
- Add configuration for each virtual site
< virtualhost IP address: Port >
ServerName = the DNS name of this site
DocumentRoot is the page root of this site
</VirtualHost>
virtual machine A: [root@svr7 ~]# vim /etc/httpd/conf.d/haha.conf <VirtualHost *:80> #Listen on all IP addresses 80 ServerName www.qq.com #Domain name of the website DocumentRoot /var/www/qq #Web page file path </VirtualHost> <VirtualHost *:80> ServerName www.lol.com DocumentRoot /var/www/lol </VirtualHost> ]# mkdir /var/www/qq /var/www/lol ]# echo wo shi QQ > /var/www/qq/index.html ]# echo wo shi lol > /var/www/lol/index.html ]# systemctl restart httpd
Use the / etc/hosts file to directly resolve the domain name, which is only resolved locally
]# vim /etc/hosts .......Ten thousand words are omitted here 192.168.4.7 www.qq.com www.lol.com ]# curl http://www.qq.com ]# curl http://www.lol.com ]# mkdir /var/www/qq /var/www/lol ]# echo wo shi QQ > /var/www/qq/index.html ]# echo wo shi lol > /var/www/lol/index.html ]# systemctl restart httpd use/etc/hosts The file directly resolves the domain name, which is only resolved locally ]# vim /etc/hosts .......Ten thousand words are omitted here 192.168.4.7 www.qq.com www.lol.com ]# curl http://www.qq.com ]# curl http://www.lol.com
Transfer the pre written page (web.zip) to the virtual machine:
Pass the pre written page (web.zip) to virtual machine A
On Linux real machine:
[ root@localhost ~]#SCP / root / download / Web zip root@192.168.4.7:/root
On windows real machine:
]# ls /root/web.zip /root/web.zip ]# mkdir /nb ]# unzip /root/web.zip -d /nb ]# ls /nb/ ]# ls /nb/web/ ]# ls /nb/web/html/ ]#cp -r /nb/web/html/* /var/www/ ]# ls /var/www/ ]# vim /etc/httpd/conf.d/xixi.conf <VirtualHost *:80> ServerName www.nb1.com DocumentRoot /var/www/nsd01 </VirtualHost> <VirtualHost *:80> ServerName www.nb2.com DocumentRoot /var/www/nsd02 </VirtualHost> <VirtualHost *:80> ServerName www.nb3.com DocumentRoot /var/www/nsd03 </VirtualHost> <VirtualHost *:80> ServerName www.nb4.com DocumentRoot /var/www/nsd04 </VirtualHost> [root@svr7 ~]# systemctl restart httpd [root@svr7 ~]# vim /etc/hosts .......Ten thousand words are omitted here 192.168.4.7 www.nb1.com 192.168.4.7 www.nb2.com 192.168.4.7 www.nb3.com 192.168.4.7 www.nb4.com
Once the virtual Web hosting function is used, all websites must be rendered using the virtual Web
virtual machine A [root@svr7 ~]# vim /etc/httpd/conf.d/haha.conf .......Ten thousand words are omitted here <VirtualHost *:80> ServerName www.xixi.com DocumentRoot /webroot </VirtualHost> [root@svr7 ~]# systemctl restart httpd [root@svr7 ~]# vim /etc/hosts .......Ten thousand words are omitted here 192.168.4.7 www.qq.com www.lol.com www.xixi.com [root@svr7 ~]# curl http://www.xixi.com
- Port based virtual Web host
]# vim /etc/httpd/conf.d/haha.conf <VirtualHost *:80> ServerName www.qq.com DocumentRoot /var/www/qq </VirtualHost> Listen 8080 #httpd program listens to port 8080 <VirtualHost *:8080> #The website uses port 8080 ServerName www.qq.com DocumentRoot /var/www/lol </VirtualHost> [root@svr7 ~]# systemctl restart httpd [root@svr7 ~]# curl www.qq.com:8080 [root@svr7 ~]# curl www.qq.com