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.打 ...
随机推荐
- IP段的正则表达式
IPv4 prefix格式:比如: 192.168.1.0/24 ^(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{ ...
- okhttp异步请求流程和源码分析
在上一次[http://www.cnblogs.com/webor2006/p/8023967.html]中对同步请求进行了详细分析,这次来分析一下异步请求,而关于异步请求和同步请求其使用方式基本上差 ...
- windows10下成功安装docker splash及遇到问题的解决方案
转载出处:http://www.cnblogs.com/321lxl/p/9536616.html
- mybatis分页未明确的列定义
问题出现原因是 集成mybaits时 会自动加上 select tmp_page.*, rownum row_id from ( abc )tmp_page 我的问题是 abc区域的列名有重名的,保持 ...
- metal feature and specification
https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf 宝贝 https://developer.apple.com/metal/ ...
- hbase实践之写流程
内容提要 一.写入流程 初始化ZooKeeper Session,建立长连接,获取META Region的地址. 获取rowkey对应的Region路由信息:来自.meta. 写入region 如何快 ...
- node.js----一个httpserver提交和解析get参数的例子
前端代码 <!doctype html> <html lang="en"> <head> <meta charset="utf- ...
- Codeforces Round #586 (Div. 1 + Div. 2) E. Tourism
链接: https://codeforces.com/contest/1220/problem/E 题意: Alex decided to go on a touristic trip over th ...
- 在npm install时node-gyp出现错误
在执行npm install的时候出现了下面的错误,安装Xcode并执行sudo xcode-select -s /Applications/Xcode.app/Contents/Developer, ...
- JS 定时器-setInterval、clearInterval、setTimeout
在微信小程序里写的: // pages/splash/splash.js const app = getApp() Page({ data: { remainSecond: }, // 页面渲染完成后 ...