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:
ServerName www.hg.com
DocumentRoot /data/www
<Directory "/data/www">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</VirtualHost>
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>
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=
enabled= Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “” or “”, for .x or .x versions, respectively.
yum install nginx
配置/etc/nginx/conf.d/xxx.conf
server {
listen ;
listen ;
server_name www.hg.com;
location / {
root /data/www;
index index.html index.htm;
}
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
伪静态
server {
listen ;
listen ;
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 ;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
负载均衡
upstream server_host{
server 192.168.8.205: weight=;
server 192.168.8.205:;
server 192.168.8.205:;
}
server {
listen ;
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 ;
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 ;
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./src/redis-server /usr/local/redis-5.0./redis.conf --daemonize no
ExecSop=/usr/local/redis-5.0./src/redis-cli -h 127.0.0.1 -p 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
centos7操作的更多相关文章
- CentOS7操作系统参数优化
生产环境配置需要标准化,将常用操作写成脚本用于操作系统的初始化. #!/bin/bash #Date:2017 #This Script is for centos7.3 init #01.配置yum ...
- centos7 操作记录
centos7 firewall 命令查看已经开放的端口firewall-cmd --list-ports查看开放的服务firewall-cmd --list-services开启端口firewall ...
- CentOS7操作Redis4.0
单机安装 1. 从官网下载 redis-4.0.10.tar.gz 到本地,然后上传到VMware虚拟机上,存放地址随意. 2. 解压: tar -zxvf redis-4.0.10.tar.gz 3 ...
- centos7 操作防火墙
原文:https://blog.csdn.net/u012498149/article/details/78772058 1.firewalld的基本使用 启动: systemctl start fi ...
- centos7操作防火墙
1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...
- centos7操作记录
/root/wang/shell 存放练习的shell文件,快捷命令wsh(alias wsh='cd /root/wang/shell') /root/wang/OS_bak 存放系统备份文件 ...
- centos7操作SSH/SSHD服务(查看/启动/重启/自启)
查看状态: systemctl status sshd.service 启动服务: systemctl start sshd.service 重启服务: systemctl restart sshd. ...
- CentOS7 离线安装gcc/pcre-devel/openssl-devel/zlib-devel
1. 解压CentOS7操作系统安装镜像,进入到CentOS-7.0-1406-x86_64-DVD\Packages目录,这下面存储了很多rpm包. 2. 找到下面列出的rpm包,上传到CentOS ...
- CentOS7安装详解
本文基于vmware workstations进行CentOS7安装过程展示,关于vmware workstations安装配置本人这里不再介绍,基本过程相当于windows下安装个软件而已. 1.打 ...
随机推荐
- 洛谷 P3119 [USACO15JAN]草鉴定Grass Cownoisseur (SCC缩点,SPFA最长路,枚举反边)
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of hi ...
- 关于Java的Object.clone()方法与对象的深浅拷贝
文章同步更新在个人博客:关于Java的Object.clone()方法与对象的深浅拷贝 引言 在某些场景中,我们需要获取到一个对象的拷贝用于某些处理.这时候就可以用到Java中的Object.clon ...
- 学习elasticsearch(一)linux环境搭建(1)
首先安装了Oracle Virtual Box 然后安装了最小版的CentOS.由于vbox自带的操作面板不太好用,于是用了xshell,XShell连接最小版的centOS时遇到的问题记录下. 1. ...
- MyBatis-09-Lombok
9.Lombok Project Lombok is a java library that automatically plugs into your editor and build tools, ...
- RHEL8 创建本地YUM存储库
yum 的好处及本地yum的好处不在本文讨论范畴,本文针对rhel8中的新功能yum做简要介绍和配置,在 RHEL 8中分为两个存储库: BaseOS 应用程序流(AppStream) BaseOS中 ...
- (三)wait()、notify()、notifyAll()
有新理解持续更新 轮询 线程本身是操作系统中独立的个体,但是线程与线程之间不是独立的个体,因为它们彼此之间要相互通信和协作. 想像一个场景,A线程做int型变量i的累加操作,B线程等待i到了10000 ...
- python大数据初探--pandas,numpy代码示例
import pandas as pd import numpy as np dates = pd.date_range(',periods=6) dates import pandas as pd ...
- 桥接模式(Bridge)---结构型
1 基础知识 定义:将抽象部分与它的具体实现部分分离,使得它们都可以独立变化.特征:通过组合的方式建立两个之间的联系而不是继承. 使用场景:抽象和具体实现之间增加更多的灵活性:一个类存在两个(多个)独 ...
- http message
- 配置魔药(DP)
配置魔药 [问题描述] 在<Harry Potter and the Chamber of Secrets>中,Ron的魔杖因为坐他老爸的Flying Car撞到了打人柳,不幸被打断了,从 ...