Linux课堂总结

####http服务的基础启动######

 

 

1.yum install httpd -y ##安装服务
2.systemctl start httpd ##开启服务
3.systemctl enable httpd ##开机自启
4.firewall-cmd --permanent --add-service=http  ##关闭火墙限制
5.firewall-cmd --permanent --add-service=https  
6.firewall-cmd --reload 
7.vim /var/www/html/index.html ##修改默认页面




/etc/httpd/conf/httpd.conf ####httpd的主配置文件


->修改默认端口(默认为80)


1.vim /etc/httpd/conf/httpd.conf
> Listen 8080 ##修改访问端口


2.firewall-cmd --permanent --add-port=8080/tcp


3.firewall-cmd --reload ##允许火墙开放8080端口




访问的时候机的在网址后面加上:80




->修改默认文件(默认是index.html


1.vim /etc/httpd/conf/httpd.conf


>DirectoryIndex index.html linux.html 








->修改默认目录(修改为/www/html)


1.vim /etc/httpd/conf/httpd.conf ##编辑配置文件
 DocumentRoot "/www/html"   #修改


<Directory "/www">       #添加目录
 Require all granted #添加权限
</Directory>


2.semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?' ##配置selinux




#####虚拟服务器(一个IP对应多个域名)######


(客户机中将多个域名对应同一个IP)


####客户端操作###


vim /etc/hosts
172.25.254.113 www.linux.com www.luck.com   ###地址解析


#####服务器的修改####


1.vim /etc/httpd/conf.d/default.conf ##新建子配置文件(非特殊域名登陆)
<virtualhost _default_:80>
        documentroot /var/www/html
        customlog "logs/default.log" combined   ##日志储存位置及其类型
</virtualhost>


 <directory /var/www/html>
         require all granted ##目录授权
 </directory>




2.vim /etc/httpd/conf.d/luck.conf ##新建子配置文件(特殊域名登陆)
 <virtualhost *:80>
        servername www.luck.com   ##说明特殊服务器
         documentroot /var/www/bymask        ##建立目录以及里面的文件
         customlog "logs/luck.log" combined
 </virtualhost>
 
 <directory /var/www/bymask>
         require all granted
 </directory>




#####访问限制#####
1.vim /etc/httpd/conf.d/mengran.conf
 <directory /var/www/bymask/pop> ##这个目录限制IP
         Order deny,allow ##读取顺序
         allow from  172.25.254.13
         deny from all
 </directory>
 
 <directory /var/www/luck/BY> ##密码限制
         Authuserfile /etc/httpd/conf/fileuser   ##密码文件在下面建立
         Authname "WQWQWQ"
         Authtype basic
         require valid-user
 </directory>


2.htpasswd -cm fileuser admin ##新建用户
3.htpasswd -m fileuser tom ##添加用户




#####apache中的插件(PHP,CGI)####
->PHP服务
1.yum install php -y ##安装php
2.systemctl restart httpd.service ##重启服务即可
3.vim /var/www/html/index.php
 <?php
         phpinfo ();     #php文件
 ?>




->CGI脚本
1.vim /var/www/html/index.cgi ##新建一个cgi脚本
 #!/usr/bin/perl
 print "Content-type: text/html\n\n";
 print `date +%H:%M:%S`;


2.chmod +x index.cgi ##赋予执行权限
3.vim /etc/httpd/conf.d/default.conf ##编辑默认配置文件
 <Directory /home/*/public_html>
     Options +ExecCGI
     AddHandler cgi-script .cgi
 </Directory>


##注意SELinux的影响,也可以修改安全上下文




#####https的配置(建立一个https的域名)(加密传输)####
1.yum install mod_ssl.x86_64 -y ##安装https(httpd的插件)
2.yum install crypto-utils.x86_64 -y ##安装证书产生器
3.genkey $(hostname) ##生成证书
4.vim /etc/httpd/conf.d/login.conf ##编辑文件
<virtualhost *:443>
        servername login.linux.com
        documentroot /var/www/login
        customlog "logs/login.log" combined
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/dns-servser1.crt
        SSLCertificateKeyFile /etc/pki/tls/private/dns-servser1.key
 </virtualhost>


 <directory /var/www/login>
        require all granted
 </directory>


 <virtualhost *:80>
        servername login.linux.com
        rewriteengine on
        RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
 </virtualhost>


###模版不变####


5.systemctl restart httpd.service ##重启服务








######数据库管理#######
1.yum install mariadb-server -y        ##安装mysql
2.systemctl start mariadb ##开启服务
3.vim /etc/my.cnf ##关闭远程连接端口
+ kip-networking=1
4.mysql_secure_installation ##初始化
5.mysql -uroot -p ##登陆




->使用
1.create database westos; ##创建westos数据库
2.use westos; ##进入数据库
3.create table linux( ##创建表,username,password字段
4.username varchar(15) not null,
password varchar(15) not null
);


6.select * from mysql.user; ##查询mysql库下的user表中的所以
7.alter table linux add age varchar(4); ##添加age字段到linux表中
8.ALTER TABLE linux DROP age ##删除age字段
9.ALTER TABLE linux ADD age   VARCHAR(5)  AFTER name


##在name字段后添加字段age
10.show tables; ##查看所有的表
11.desc linux; ##查看表结构
12.insert into linux values ('user1','passwd1'); ##在linux表中插入值
14.update linux set password=password('passwd2') where username=user1;
##更新linux表中user1 的密码
16.delete from linux where username=user1; ##删除linux表中user1的所以内容




->备份和恢复
1.mysqldump -uroot -predhat --all-database >/mnt/db.sql
##备份所有数据库
2.mysqldump -uroot -predhat --no-data --all-database
##不备份数据,只备份结构
3.mysqldump -uroot -predhat student >/mnt/student.sql
##备份数据库student
4.mysql -uroot -predhat student < /mnt/student.sql  ##恢复数据库student
5.mysql -uroot -predhat -e "SHOW DATABASES;"  ##直接执行语句








->用户的创建授权和删除
1.CREATE USER user@localhost identified by 'westos';


##建立本地用户 
  CREATE USER lee@'%' identified by 'redhat';  ##建立远程用户
2.GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to wxh@localhost;


##授权本地用户
  GRANT SELECT on mariadb.* lee@'%'; ##授权远程用户
3.SHOW GRANTS FOR wxh@localhost; ##查看用户权限
4.REVOKE DELETE,UPDATE,INSERT on mariadb.* from wxh@localhost;


##移除用户权限
5.DROP USER wxh@localhost; ##删除用户


6.grant select on  *.* to user1@localhost identified by 'passwd1';


##授权user1 密码为passwd1  并且只能在本地 查询数据库的所以内容 


7.grant all on mysql.* to user2@'%' identified by 'passwd2';


##授权user2 密码为passwd2  可以从远程任意主机登录mysql 并且可以对mysql数据库任意操作




->忘记密码
1.mysqladmin -uroot -predhat password 'westos'  ##记得密码
2.mysqld_safe --skip-grant-tables & ##跳过密码验证

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值