0.vi命令模式下查找字符串命令 :/字符串
1.Ctrl+c 换行 free -m 查看当前内存使用情况
2.Ctrl+z 停止正执行程序
3.yum install net-tools 安装网络管理工具
netstat -ntlp 查看端口 #netstat -tulpn
4.chkconfig --list 查看所有开机启动的服务
systemctl list-unit-files|less 分页查找可上下分页more只能下翻
systemctl list-unit-files|grep enabled
systemctl list-unit-files|grep disabled
systemctl enable redis 设置开机启动
systemctl list-units --type=service 查看当前所有已启动的服务
5.ps -ef | grep mysqld 查询进程
6.mkdir -p建立级联目录 touch 建立文件 cp -rf 源文件位置 目标文件位置 mv 移动或重命名
rm -rf 递归删除文件和文件夹
7.useradd agasha 添加用户 默认自动创建同名组 groupadd kistier 添加组
gpasswd -a agasha kistier 把用户添加到组
passwd agasha 设置密码
id agasha 显示详细信息
useradd -u 2000 -g 1000 -d /home/agasha -s /sbin/nologin agasha 创建用户时指定uid、gid、home目录和shell
useradd -r agasha 删除用户是同时删除家目录
groupdel kistier 删除组
8.sudo命令
root用户登录执行#viduso 命令修改/etc/sudoers文件
-------------------------------------------------------------
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
agasha ALL=(root) NOPASSWD:ALL
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
%agasha ALL=(root) NOPASSWD:ALL
oracle ALL=(root) NOPASSWD:/usr/sbin/useradd, PASSWD:/usr/sbin/userdel
-------------------------------------------------
授权指定组和用户特定权限
用户登录后执行#su命令切换用户或者在所有执行命令前加上sudo前缀命令即可
sudo l 查看授权信息
9.grep sudoers /etc/sudoers 从文件内容抓取关键词
find /etc -name sudoers 从/etc目录下查找名为sudoers的文件或文件名
ls -al|less 显示当前目录所有文件和文件夹信息
ls -l /etc/sudoers 查看指定文件或目录权限信息
10.chmod
#ls -al test
-rw-rw-r--.
#chmod 777 test
-rwxrwxrwx.
#chmod a-x test
-rw-rw-rw-.
#chmod o+x,g+x test
-rw-rwx-rwx
更改文件所属组 chgrp agasha /test
更改文件所有者 chown -R agasha /test 更改文件夹所属组 chgrp -R root /test
12.rpm -qa|grep java 抓包
rpm -qi java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 查询指定包详细信息
rpm -qf /etc 查询指定文件夹下所有rpm包
rpm -qR java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 查询软件包依赖
rpm -q java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_6 查询包是否安装
rpm -e 包名 删除包
13.yum search 关键字 搜索指定报名所有相关包
yum -y install mysql-server 安装软件包
yum -y update mysql-server 更新软件包
#########################MySQL############################
vi /etc/my.cnf 查看日志 0afacf6d-6352-11e9-aa82-00163c0c52f9.
validate_password=off
default_password_lifetime=0
重启后生效
systemctl restart mysqld
cat /var/log/mysqld.log 查看生成临时密码
grep 'temporary password' /var/log/mysqld.log 通过关键字搜索更快
A temporary password is generated for root@localhost: lc><ruiI=2Fj
登录后立即修改密码
mysql
mysql5.6修改密码 update mysql.user set password=password("123456") where user="root";
alert user 'root'@'localhost' identified by '123456'
查看用户表
select host,user,authentication_string,plugin from mysql.user;
授权其他机器使用root用户登录(推荐)
CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 添加用户
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
----------------------------------8.0修改密码设置允许远程访问------------------------------------------
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
############################YUM##########################
yum自动安装openJDK之后的JAVA_HOME和CLASSPATH配置
find / -name java
cd /usr/lib/jvm/
临时对当前用户生效设置
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64
vi ~/.bashrc
export export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
对所有用户生效设置
vi /etc/profile
#set java environment
export JAVA_HOME=/usr/lib/jvm/java
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
. /etc/profile
查看
echo $JAVA_HOME
echo $CLASSPATH
###########################SSH###############################
配置ssh允许远程密码登录
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes
AllowUsers agasha
AllowUsers guojun2019
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#######################CATALINA###################################
tomcat开机启动
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat/tomcat.pid
Environment=JAVA_HOME=/usr/local/jdk
Environment=CATALINA_HOME=/usr/local/tomcat
ExecStart=/usr/local/tomcat/bin/daemon.sh start
ExecStop=/usr/local/tomcat/bin/daemon.sh stop
User=tomcat
Group=tomcat
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable tomcat
#######################FireWall############################
外部浏览器访问tomcat需要FireWall放行
firewall-cmd --state 查看防火墙状态
firewall-cmd --permanent --zone=public --add-port=8080/tcp 永久添加该端口去掉permanent则为临时
firewall-cmd --reload 加载配置使修改生效
firewall-cmd --permanent --zone=public --list-ports 查看开启端口是否为8080
-------------------------------------Nginx----------------------------------
编译环境gcc g++ 开发库之类的需要提前装好
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
首先安装PCRE pcre功能是让nginx有rewrite功能
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压安装包
tar zxvf pcre-8.35.tar.gz
进入安装包目录
cd pcre-8.35
编译
./configure
安装
make && make install
查看安装版本:pcre-config –version 如果出现版本号,说明安装成功
下载nginx:wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压安装包: tar zxvf nginx-1.6.2.tar.gz
进入安装包目录:cd nginx-1.6.2
配置:./configure
编译安装:make && make install
配置
cd conf 【注意为安装目录非解压目录可用命令查看 find / -name nginx.conf】
vi nginx.conf
-------------
upstream name {
server 192.168.2.50:8080;
server 192.168.2.165:8080;
}
proxy_pass http:name;
-------------
测试重启
cd /usr/local/nginx/sbin
./nginx -t 测试
./nginx -s reload 重新加载
./nginx 启动
设置 nginx命令
vi /etc/profie
添加path
:/usr/local/nginx/sbin
设置开机启动
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx 服务的说明
After=network.target 描述服务
[Service]
Type=forking 描述服务类别
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 表示给服务分配独立的临时空间
[Install]
WantedBy=multi-user.target 运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
systemctl enable nginx.service
@@@@@@@@@@@@@@@@redis@@@@@@@@@@@@@@@@@@@@@@@@@@
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
tar -zxvf redis-4.0.6.tar.gz
yum install gcc
cd redis-4.0.6
make MALLOC=libc
cd src && make install
vi /usr/local/redis/redis.conf
修改daemonize no 为yes
./redis-server /usr/local/redis-4.0.6/redis.conf 启动
设置开机启动
cd /etc
mkdir redis
cp /usr/local/redis-4.0.6/redis.conf /etc/redis/6379.conf
cp /usr/local/redis-4.0.6/utils/redis_init_script /etc/init.d/redisd
vi redisd
第二行添加注释
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
chkconfig redisd on
service redisd start
service redisd stop
--------------------------主从配置----------------------------------
redis.conf文件配置多份
1.port 配置端口号
2.daemonize yes 配置后台启动
3.pidfile /var/run/redis_port.pid配置进程文件
4.bind 127.0.0.1注释掉【重要】
配置从服务器masterauth与主服务器一致
分别配置主从服务器各自登录密码登录时用
src下 ./redis-server ../redis.conf启动服务
./redis-cli -p 6380 -a 123456登录服务
info replication查看主从信息
------------------集群配置----------------------------------
mkdir /usr/local/cluster/bin
cd /usr/local/cluster
mkdir -p 9001/data 9002/data 9003/data 9004/data
cp -rf /usr/local/redis/redis.conf 9001
cp -rf /usr/local/redis/redis.conf 9002
cp -rf /usr/local/redis/redis.conf 9003
cp -rf /usr/local/redis/redis.conf 9004
cd /usr/local/redis/src
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /usr/local/cluster/bin
配置redis.conf
port 9001
bind 192.168.2.165 #绑定的时本机IP地址做客户端登陆用
daemonize yes
cluster-enabled yes
cluster-config-file nodes-9001.conf
cluster-node-timeout 15000
pidfile /var/run/redis_9001.pid
dir /usr/local/cluster/9001/data #存放数据目录
环境准备
yum install rubygems
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.gz
./configure #编译
make && make install #安装
gem install redis
配置启动和关闭ruby脚本
vi startallredis.sh
./redis-server /usr/local/redis-cluster/9001/redis.conf
./redis-server /usr/local/redis-cluster/9002/redis.conf
./redis-server /usr/local/redis-cluster/9003/redis.conf
./redis-server /usr/local/redis-cluster/9004/redis.conf
chmod u+x startallredis.sh #使可以执行
vi stopallredis.sh
./redis-cli -h 192.168.2.165 -p 9001 shutdown
./redis-cli -h 192.168.2.165 -p 9002 shutdown
./redis-cli -h 192.168.2.165 -p 9003 shutdown
./redis-cli -h 192.168.2.165 -p 9004 shutdown
chmod u+x stopallredis.sh
创建集群
cd /usr/local/cluster/bin
./redis-trib.rb create --replicas 192.168.2.165:9001 192.168.2.165:9002 192.168.2.165:9003 192.168.2.165:9004
登录集群
./redis-cli -h 192.168.2.165 -p 9001
-------------------------------------
设置端口映射工具rinetd自启动
echo rinetd >>/etc/rc.local
chmod +x /etc/rc.d/rc.local
-----------------------------
vi /etc/sysconfig/clock(如果没有此文件则无需添加)
ZONE=Asia/Shanghai
rm /etc/localtime(如果无此文件则无需删除)
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install ntp
systemctl enable ntpd
systemctl start ntpd
localectl set-locale LANG=en_US.UTF-8 设置语言环境
localectl status 查看当前语言状态
df -h 查看磁盘总体使用情况
df -i /* 查看磁盘inode占用信息
du -h -x --max-depth=1 查看当前目录下各文件夹占用空间大小
------------------------------
设置开机启动
cp ./mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
-----------------------------
(stop slave)
CHANGE MASTER TO MASTER_HOST='192.168.8.10',
MASTER_PORT=3306,
MASTER_USER='slave1',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='binlog.000001',
MASTER_LOG_POS=1304;
start slave;
show slave statusG;
(show master status;)
GRANT REPLICATION SLAVE ON *.* to 'slave2'@'%' identified by '123456';
----------------------------------------------
配置yum源
cd /etc/yum.repos.d/
mkdir repo_bak
mv *.repo repo_bak/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
重启
yum clean all
yum makecache
yum list|grep epel-release
yum install -y epel-release
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum repolist enabled
----------------------------------------------
安装docker(删除镜像只能以ID删除,删除名字会破环镜像完整性)
yum update
yum remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce
systemctl enable docker
ystemctl start docker
docker version
docker images 查看所有镜像
docker container ls = docker ps 所有正在运行的容器
docker container ls -a = docker ps -a 所有的容器 包括正在运行的和没有运行的容器
docker run -d <IMAGE STRING> 后台运行镜像
docker rm <CONTAINER ID> 删除容器
删除全部容器
docker rm $(docker ps -aq)
停用并删除容器
docker stop $(docker ps -q) & docker rm $(docker ps -aq)
docker rmi <IMAGE STRING> 删除镜像
-----------------MYSQL
docker run -di --name mysql01 -p 3310:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
docker run -di --name mysql02 -p 3311:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
docker exec -it mysql01 bash
docker exec -it mysql02 bash
--------------------------ES
docker run -di --name=tensquare_es -p 9200:9200 -p 9300:9300 elasticsearch:5.6.8
docker cp tensquare_es:/usr/share/elasticsearch/config/elasticsearch.yml /usr/share/elasticsearch.yml
docker run -di --name=tensquare_es -p 9200:9200 -p 9300:9300 -v /usr/share/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:5.6.8
vi /usr/share/elasricsearch.yml
放开 transport.host: 0.0.0.0 允许任何远程主机访问
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65536
vi /etc/sysctl.conf
* vm.max_map_count=655360
reboot
------------------分词器
docker cp ik tensquare_es:/usr/share/elasticsearch/plugins
docker restart tensquare_es
192.168.2.232:9200/_analyze?analyzer=ik_smart&pretty=true&text=我是程序员
------------------head插件
docker run -di --name=elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5
添加跨域
vi /usr/share/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
重启
docker restart tensquare_es
----------------------------RabblitMQ
windows下 sbin目录下 rabbitmq-plugins enable rabbitmq_management 需要重新启动服务 localhost:15672登录管理界面 用户名密码均为guest
docker run -di --name=tensquare_rabbitmq -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 15671:15671 -p 15672:15672 -p 25672:25672 rabbitmq:management
service firewalld status 查看防火墙状态
systemctl stop firewalld 关闭防火墙
-------------------------------------------------
spring-cloud-bus http://192.168.169.130:9999/actuator/bus-refresh
制作镜像dockerfile和安装包jdk-8u171-linux-x64.tar.gz
docker build -t="jdk1.8" .
运行jdk
docker run -di --name=jdk1.8 jdk1.8
制作仓库
docker run -di --name=registry -p 5000:5000 registry
访问 192.168.2.232:5000/v2/_catalog 测试
添加docker信任仓库
vi /etc/docker/daemon.json
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"],
"insecure-registries":["192.168.2.232:5000"]
}
标记
docker tag jdk1.8 192.168.2.232:5000/jdk1.8
推送
docker push 192.168.2.232:5000/jdk1.8
---------------------------------------------------
DockerMaven插件部署(制作镜像上传仓库)
vi /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
systemctl daemon-reload
systemctl restart docker
systemctl start registry(启动私有仓库)
mvn clean package docker:build -DpushImage
docker run -di --name=tensquare_config -p 9999:9999 192.168.169.130:5000/tensquare_config:1.0-SNAPSHOT
------------------------------------------------------
docker pull gogs/gogs
docker run -di --name=gogs -p 10022:22 -p 3000:3000 -v /var/gogsdata:/data/gogs/gogs gogs/gogs
http://192.168.169.130:3000/
将localhost改为192.168.169.130即可然后注册登陆 新建公有仓库即可
-----------------------------------------------------
jenkins宿主机安装
wget https://pkg.jenkins.io/redhat/jenkins-2.83-1.1.noarch.rpm
rpm -ivh jenkins-2.83-1.1.noarch.rpm
vi /etc/sysconfig/jenkins
JENKINS_USER="root"
JENKINS_PORT="8888"
本机安装maven配好仓库(上传仓库前先install父项目和jar模块)地址还有java
Global Tool Configuration
JAVA_HOME /usr/java/jdk1.8.0_171-amd64
MAVEN_HOME /usr/local/maven
New Item
git地址 http://192.168.169.130:3000/agasha/tensquare.git
Pre Steps tensquare_eureka/pom.xml clean package docker:build -DpushImage
------------------------------------------------------
cat /var/jenkins_home/secrets/initialAdminPassword 获取密码
docker run -d -v jenkins_home:/var/jenkins_home -p 8880:8080 -p 50000:50000 jenkins/jenkins
docker logs 容器ID 查看初始密码访问8888端口等待自动下载安装
docker cp maven jenkinsID:/usr/local/maven
docker cp repository jenkinsID:/usr/local/repository
----------------------------------Rancher----------------------
docker run -d --name=rancher --restart=always -p 9090:8080 rancher/server
192.268.2.232:9090
基础架构=》镜像库=》custom=》IP地址
基础架构=》主机=》IP地址
sudo docker run -e CATTLE_AGENT_IP="192.168.169.130" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://192.168.169.130:9090/v1/scripts/4C8062A1F1FCFD00D956:1546214400000:gwAcCSqcfAxkAkoYYXoppdFlwU
应用=》全部=》添加应用 tensquare
给应用添加服务
--------------------------InfluxDB监控微服务内存------------------------------
docker run -di -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 --name influxsrv tutum/influxdb
192.268.2.232:8083
-----------------------------cAdvisor采集内存信息---------------------------
docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --
volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --
publish=8080:8080 --detach=true --link influxsrv:influxsrv --name=cadvisor
google/cadvisor -storage_driver=influxdb -storage_driver_db=_tensquare -
storage_driver_host=influxsrv:8086
192.268.2.232:8080
-------------------------------Grafana图形化显示---------------------------------------------
docker run -d -p 3001:3000 -e INFLUXDB_HOST=influxsrv -e INFLUXDB_PORT=8086
-e INFLUXDB_NAME=cadvisor -e INFUXDB_USER=agasha -e INFLUXDB_PASS=agasha
--link influxsrv:influxsrv --name grafana grafana/grafana
192.268.2.232:3001
---------------------------------------------------------------
[mysqld_multi]
mysqld = /home/mysql/bin/mysqld_safe
mysqladmin = /home/mysql/bin/mysqladmin
#user = multi_admin
#password = my_password
[mysqld2]
socket = /tmp/mysql.sock2
port = 3306
pid-file = /home/mysql/data2/mysql2.pid
datadir = /home/mysql/data2
#language = /usr/local/mysql/share/mysql/english
user = mysql
[mysqld3]
socket = /tmp/mysql.sock3
port = 3307
pid-file = /home/mysql/data3/mysql3.pid
datadir = /home/mysql/data3
#language = /usr/local/mysql/share/mysql/swedish
user = mysql
-----------------------------------------------------
/usr/local/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3306/data/ --user=mysql
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf
为防止内存不够 可设置innodb_buffer_pool_size = 32M
mysql -uroot -p123456 -S /data/3306/mysql.sock
update mysql.user set password=password("123456") where user="root";
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
-------------------------------------------------
ip address show
cd /etc/sysconfig/network-scripts
mv ifcfg-enps33 ifcfg-eno16777736
vi ifcgf-eno16777736
修改NAME=eno16777736 DEVICE=eno16777736
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl start network
----------------------------------------------
root用户忽然无法远程登录
systemctl restart systemd-logind