美文网首页
奥特虾的复习笔记之《Linux高级运维》

奥特虾的复习笔记之《Linux高级运维》

作者: 奥特虾 | 来源:发表于2018-03-12 15:55 被阅读0次
    Linux

    2018-03-12

    1.安装最小化Linux系统
    2.配置yum源
    #!/bin/bash
    echo '正在配置yum源'
    mkdir /usr/mnt
    mount /dev/cdrom /usr/mnt
    echo "[base]
    name=CentOS-$releasever - Base
    baseurl=file:///usr/mnt
    gpgcheck=0
    enable=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6" > /etc/yum.repos.d/CentOS-Base.repo
    yum clean all
    yum list
    echo '正在配置开机自动挂载'
    echo '/dev/cdrom              /mnt/cdrom              iso9660   default     0 0' >> /etc/fstab
    
    3.配置网卡
    教室网络环境
    IPADDR=192.168.146.176
    NETMASK=255.255.252.0
    GATEWAY=192.168.147.254
    

    一个故障记录,很多同学配置完本机静态IP地址后能够ping通公网IP,但无法ping通域名,故障原因是在配置网络时未启用DHCP服务,虚拟机无法从DHCP服务器获取到DNS
    解决方案:

    • ifcfg-eth0BOOTPROTO=static设置为BOOTPROTO=dhcp,重启服务后再修改为静态
    • 进入/etc/resolv.conf,添加DNS解析地址
    4.给最小化Linux安装图形化界面并设置为开机后自动进入GUI
    #!/bin/bash
    yum groupinstall -y "X Window System"
    yum groupinstall -y "Desktop"
    yum groupinstall -y "input methods"              #输入法,可以不安装
    yum groupinstall -y "Chinese Support"           #安装中文支持
    cp /etc/inittab /etc/inittab.bak               #备份相关配置文件
    echo 'id:5:initdefault:' > /etc/inittab     #将Linux开机默认运行级别修改为5
    
    设置语言为中文的方法
    vi /etc/sysconfig/i18n
    
    #LANG="en_US.UTF-8"             #注释掉相关代码,方便后期修改为英文语言
    LANG="zh_CN.UTF-8"
    SYSFONT="latarcyrheb-sun16"
    

    2018-03-13

    1.卸载GUI并将Linux开机默认运行级别修改回3

    卸载软件组命令yum -y groupremove

    2.配置ntp服务器
    yum -y install ntp
    vi /etc/ntpd.conf
    添加一行
    restrict 192.168.144.241 mask 255.255.252.0 nomodify notrap    #IP、子网掩码
    
    • 思考:如何在不关闭防火墙的情况下使用ntp
      解决方案:配置防火墙规则iptables -I INPUT -p udp --dport 123 -j ACCEPT
    3.配置samba服务
    yum -y install samba
    cp /etc/samba/smb.conf /etc/samba/smb.conf.bak       #备份配置文件
    
    修改配置文件:

    security = user修改为security = share
    在文件末尾追加以下内容

    [share]
          comment = share for users
          path = /tmp/samba
          browseable = yes
          public = yes
          writable = yes
    
    mkdir /tmp/samba
    chmod 777 -R /tmp/samba
    chown -R nobody:nobody /tmp/samba
    
    启动samba服务
    service smb restart
    service iptables stop
    setenforce 0
    
    4.指定用户访问samba共享目录
    useradd lenovo
    smbpasswd -a lenovo
    #新建用户并设置密码
    
    mkdir /usr/code
    chown -R lenovo:lenovo /use/code
    #创建共享文件夹并设置属组
    

    配置文件末尾添加以下内容

      [lenovo]
      comment =lenovo
      path = /use/code
      browseable = yes
      public = yes
      writable = yes
      writelist = lenovo    #也可设置用户组,如用户组lenovo有写入权限,则writelist = @lenovo
        
    
    5.MySQL安装与配置
    MySQL的安装
    yum -y install mysql
    yum -y install mysql-server
    yum -y install mysql-devel
    
    配置MySQL密码
    mysqladmin -u root password "123456"
    
    配置MySQL远程连接
    GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%'IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
    

    2018-03-14

    1.在LAMP环境下部署网站
    搭建LAMP环境

    整了一天这个已经心力憔悴了
    每个人的生产环境不太一样,大致总结一下需要安装的组件

    yum -y install httpd
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
    rpm -ivh ftp://192.168.144.254/pub/t1lib-5.1.2-6.1.x86_64.rpm
    rpm -ivh libX11-1.5.0-4.el6.x86_64.rpm
    rpm -ivh libxcb-1.8.1-1.el6.x86_64.rpm
    yum -y install t1lib
    yum -y install php56w
    yum -y install php56w-gd
    yum -y install php56w-mysql
    rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
    rpm -ivh perl-DBI-1.609-4.el6.x86_64.rpm 
    rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm 
    rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm
    yum install mysql-server
    yum install mysql-libs
    yum install mysql
    
    将FTP内网页源码下载到自己虚拟机内,并部署至/var/www/下
    wget ftp://192.168.144.254/pub/TPshop_20171106_v2.0.8.zip
    unzip TPshop_20171106_v2.0.8.zip
    mv TPshop_20171106_v2.0.8 html
    cp -R html/ /var/www/ 
    chown -R apache.apache /var/www/html
    

    关闭防火墙后,输入自己虚拟机的IP地址,按照安装提示一步一步向下即可

    一个总结

    以前部署WordPress的时候,非常容易,一会儿就部署好了,但是这次却花了将近一天的时间,主要原因是这次的电商网站对环境有特殊要求,而我们的CentOS 6.5自带的yum源无法get到对应版本的相关组件,所以需要通过其他方式或渠道安装(如第三方rpm或本地光盘镜像)。而在这个安装过程中,也出现了或多或少的依赖环境缺失(版本问题导致无法使用yum直接安装),所以需要用rpm将部分依赖软件装好后,再使用yum。看似一波三折,到最后发现,只是稍微绕了点。也不是很难

    2018-03-15

    CentOS 7 target管理
    • 切换到自启动到图形化界面模式

      rm /etc/systemd/system/default.target    #删除已存在的软连接
      ln -sf /lib/systemd/system/graphical.target  /etc/systemd/system/default.target   #默认级别转换到5
      reboot                          #重启
      

      其实还有更简单粗暴的操作

      systemctl set-default graphical.target
      
    • 修改当前运行模式

      systemctl isolate graphical.target
      
    • 查看当前默认运行级别

      systemctl get-default
      
    • 查看当前可用的target

      systemctl list-units --type target
      
    CentOS 7的服务管理
    • 启动服务

      systemctl start firewalld
      
    • 停止服务

      systemctl stop firewalld
      
    • 重启服务

      systemctl restart firewalld
      
    • 查看服务状态

      systemctl status firewalld                    #查看指定服务详细状态
      systemctl is-active firewalld                 #只显示是否active
      systemctl list-units --type-service           #查看所有服务的状态
      
    • 设置/禁止开机自启

      systemctl enable firewalld          #设置开机自启
      systemctl disable firewalld         #禁止开机自启
      

    一些练习题

    1. 使用ip addr查看和修改IP地址
    ip addr   #查看IP地址
    ip addr add 192.168.146.109/24 dev eth0     #修改IP地址
    ip addr del 192.168.146.109/24 dev eth0     #删除IP地址
    
    1. 查看日期与时间
    [root@localhost ~]# date
    2018年 03月 15日 星期四 14:20:46 CST
    
    1. 查看主机名
    [root@localhost ~]# hostname
    localhost.localdomain
    
    1. 查看硬盘当前可用空间
    [root@localhost ~]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   47G  4.0G   43G    9% /
    devtmpfs                 913M     0  913M    0% /dev
    tmpfs                    928M  148K  928M    1% /dev/shm
    tmpfs                    928M  9.3M  919M    2% /run
    
    1. 查看内存使用情况
    [root@localhost ~]# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           1.8G        330M        164M         10M        1.3G        1.4G
    Swap:          2.0G         68K        2.0G
    
    1. 查看USB接入情况
    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    fd0               2:0    1    4K  0 disk 
    sda               8:0    0   50G  0 disk 
    ├─sda1            8:1    0    1G  0 part /boot
    └─sda2            8:2    0   49G  0 part 
      ├─centos-root 253:0    0   47G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sr0              11:0    1 1024M  0 rom  
    

    相关文章

      网友评论

          本文标题:奥特虾的复习笔记之《Linux高级运维》

          本文链接:https://www.haomeiwen.com/subject/nqggfftx.html