centos7操作

一、安装系统

  1、下载(Minimal ISO)http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso

  2、使用vmware进行安装(略)

  3、查看系统版本:cat /etc/redhat-release

二、基本配置

  1、网络配置

    a、网卡配置文件目录:/etc/sysconfig/network-scripts

    b、安装ifconfig:yum install net-tools

    c、查看网卡信息:ifconfig , ip address,ip -s link ,ip link

  2、安装wget

    yum install wget

  3、配置yum源:http://mirrors.163.com/.help/centos.html

    a、首先备份/etc/yum.repos.d/CentOS-Base.repo:mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

    b、进入目录:cd /etc/yum.repos.d/

    c、下载文件:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

    d、运行命令生成缓存:yum clean all,yum makecache

  4、安装vim:yum install -y vim

  5、安装ssh服务(默认已经安装,如果系统为桌面版,需要手动安装)

    yum install openssh-server

    systemctl start sshd.service

    systemctl enable sshd.service

    yum install openssh-clients(客户端)

  6、ssh客户端连接服务端:ssh user@host_ip

    a、通过host连接服务端

      cd ~/.ssh

      vim config

        host "205"
           HostName 192.168.8.205
           User root
           Port 22
        host "205_1"
           HostName 192.168.8.205
           User root
           Port 22

      连接:ssh 205  或 ssh 205_1都可以连接到192.168.8.205

    b、密钥连接

      客户端生成密钥文件

      cd ~/.ssh

      ssh-keygen(生成私钥和公钥)

      将生成的密钥中公钥字符串写入被管理服务器 ~/.ssh/authorized_keys文件中(ssh-copy-id user@host_ip)

      登录:ssh user@host_ip

    c、xshell密钥连接

      工具--》用户密钥管理者--》生成

      将生成的密钥中公钥字符串写入被管理服务器 ~/.ssh/authorized_keys文件中,然后xshell连接时选择Public key

  7、修改ssh默认端口:vim /etc/ssh/sshd_config    取消注释  #Port 22,改成想设置成的端口号,可以同时监听多个端口

 

三、常用命令    

  软件包管理器

清除未安装完任务

yum -y install yum-utils

 yum clean all

yum-complete-transaction

yum-complete-transaction --cleanup-only

    安装软件:yum install XXX

    卸载软件:yum remove XXX

    搜索软件:yum serach XXX

    清理缓存:yum clean packages

    列出已安装:yum list

    软件包信息:yum info XXX

  硬件资源

    内存:free -m

    硬盘:df -h

    负载:w/top

    cpu:cat /proc/cpuinfo

    磁盘格式化:fdisk

  linux文件目录结构

    根目录/     家目录/home     临时目录 /tmp     配置目录/etc     用户程序目录/usr

  vim

    gg行首

    G行尾

    dd删除行

    u撤销

    yy复制行

    p粘贴

  从文件尾部开始读tail  从文件头部读head  读取整个文件cat  分页读取more  可控分页less  搜索关键字grep  查找文件find  统计个数wc

  find

    find path -name 文件名,find path -type 文件类型(d 目录,f 文件),find path -size   ,find . -ctime -20 (20天内有修改的),find . -type f -name "imooc" -exec rm {} \

  tar 

    (-c: 建立压缩档案,-x:解压,-t:查看内容,-r:向压缩归档文件末尾追加文件,-u:更新原压缩包中的文件)

    (-z:有gzip属性的,-j:有bz2属性的,-Z:有compress属性的)

    (-v:显示所有过程)

    (-f:使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名)

  用户操作

    useradd username 添加用户

    passwd username 设置密码

    userdel -r(删除/home目录下的家目录) username

  firewall

    yum install firewall 安装

    systemctl status firewalld 查看状态

    systemctl start/stop firewalld  启动或关闭

    systemctl enable/disable firewalld 开机启动设置

    systemctl list-unit-files |grep firewalld 查看是否开机启动

    firewall-cmd --state

    firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

  visodu

    # %wheel        ALL=(ALL)       NOPASSWD: ALL

    %username  ALL=(ALL)       NOPASSWD: ALL

  文件上传

    scp filename username@host_ip:dir  (filename是本地文件,username是目标服务器用户,host_ip是目标服务器ip,dir是目标服务器目录)

  文件下载

    scp username@host_ip:dir/filename dir(本地目录)

  xshell文件传输:服务器上安装 yum install lrzsz,rz客户端到服务器,sz filename服务器到客户机

  

四、服务部署

  1、apache

    yum install httpd

    配置虚拟主机/etc/httpd/conf/httpd.conf:   

      <VirtualHost *:8080>
              ServerName www.hg.com
              DocumentRoot /data/www
              <Directory "/data/www">
                      Options Indexes FollowSymLinks
                      AllowOverride None
                      Require all granted
              </Directory>
      </VirtualHost>
    伪静态/etc/httpd/conf/httpd.conf:
      <VirtualHost *:8080>
              ServerName www.hg.com
              DocumentRoot /data/www
              <Directory "/data/www">
                      Options Indexes FollowSymLinks
                      AllowOverride None
                      Require all granted
                      <IfModule mod_rewrite.c>
                              RewriteEngine On
                              RewriteRule ^(.*).htmp$ index.html
                      </IfModule>
              </Directory>
      </VirtualHost>
      
      LoadModule rewrite_module modules/mod_rewrite.so
 
  2、nginx
    http://nginx.org/en/linux_packages.html#stable
Pre-Built Packages for Stable version
To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

    yum install nginx

    配置/etc/nginx/conf.d/xxx.conf  

server {
    listen       80;
    listen 9999;
    server_name  www.hg.com;


    location / {
        root   /data/www;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

    伪静态

server {
    listen 80;
    listen 9999;
    server_name  www.hg.com www.hg1.com;
    root /data/www;
    index index.html index.htm;
    location / {
    rewrite ^(.*)\.htmp$ /index.html;
    }
}

     日志配置/etc/nginx/nginx.conf,https://www.cnblogs.com/kevingrace/p/5893499.html

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

    负载均衡

upstream server_host{
    server 192.168.8.205:80 weight=2;
    server 192.168.8.205:9999;
    server 192.168.8.205:8888;
}


server {
    listen 8888;
    server_name www.hg205.com;
    root /data/www;
    index index.html index.htm;
    location / {
    #rewrite ^(.*)\.htmp$ /index.html;
    #proxy_set_header Host www.baidu.com;
    #proxy_pass http://server_host;
    }
}

server {
    listen 9999;
    server_name  192.168.8.205;
    root /data/www1;
    index index.html index.htm;
    location / {
        #rewrite ^(.*)\.htmp$ /index.html;
        #proxy_set_header Host www.baidu.com;
        #proxy_pass http://server_host;
    }
}

server {
    listen 80;
    server_name  www.hg205.com;
    location / {
        proxy_pass http://server_host;
    }
}

   3、mysql 官方安装文档:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html

    centos7黙认安装了MariaDB,卸载:yum remove

    cd /tmp  wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

    sudo yum localinstall mysql80-community-release-el7-1.noarch.rpm(执行后,/etc/yum.repos.d目录下会有mysql-community.repo)

    查看版本状态:yum repolist all | grep mysql (黙认安装mysql8,无需进行下面的设置)

      shell> sudo yum-config-manager --disable mysql57-community
      shell> sudo yum-config-manager --enable mysql80-community

    安装:sudo yum install mysql-community-server

    查看root默认密码:sudo grep 'temporary password' /var/log/mysqld.log

    登录:shell> mysql -uroot -p

    修改密码:mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

    远程登录:mysql>use mysql,select * from user \G;,select host,user from user;,update user set host="%" where user="root";flush privileges;

    防火墙开放mysql:sudo firewall-cmd --add-service="mysql" --permanent,sudo firewall-cmd --reload

    开启日志记录:mysql>set global general_log_file="/tmp/mysql_general.log",  set global general_log=on;

    忘记root密码:修改/etc/my.conf,插入skip-grant-tables,update user set authentication_string = password("123456") where user="root"

  4、memcached

    yum install memcached

  5、redis

    wget http://download.redis.io/releases/redis-5.0.3.tar.gz(链接可以去官网复制)

    tar -xzvf redis-5.0.3.tar.gz

    mv redis-5.0.3 /usr/local/
    cd /usr/local/redis-5.0.3

    make

    配置成systemctl服务

      cd /usr/lib/systemd/system

      vim redis.service   

[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/usr/local/redis-5.0.3/src/redis-server /usr/local/redis-5.0.3/redis.conf  --daemonize no
ExecSop=/usr/local/redis-5.0.3/src/redis-cli -h 127.0.0.1 -p 6379 shutdown

[Install]
WantedBy=multi-user.target

      刷新配置  systemctl daemon-reload

      启动服务  systemctl start redis

      停止服务  systemctl stop redis

      开机启动  systemctl enable redis

    redis.conf配置(/usr/local/redis-5.0.3/redis.conf)

      daemonize yes

      protected-mode no

  6、git

  yum install git

  7、php

  8、java

  9、python

  10、服务管理

    crontab定时任务

    ntp

      yum install ntp

      natdate cn.pool.ntp.org

    logrotate

    supervisor

      pip install supervisor

      mkdir /etc/supervisor

      su root

      echo_supervisord_conf > /etc/supervisor/supervisor.conf

  11、zabbix

 

    

 

posted @ 2019-01-08 09:38  hougang  阅读(495)  评论(0编辑  收藏  举报