1. linux 常用命令
1. vim 快捷键 粘贴 yy, 复制 p,删除 dd,撤销 u,查询关键词: /hello 下一个 n
回到首行:: gg,回到末行:: G,显示行号:: set nu
2. 用户:
useradd hjk (useradd -d /home/sss hjk 创建hjk用户指定家目录)
passwd hjk
userdel sss ( userdel -r sss 删除该用户以及其家目录)
用户组
groupadd qlkj
useradd hjk -g qlkj
usermod hjk -g jishu
3. 权限
chmod u= wrx,g= rx,o= x 文件目录名
u:所有者,g:所有组,o:其他人 a:( u,g,o的总和)
r= 4,w= 2,x= 1 chmod 755 文件名
4. 查看日志
cat nginx.conf -n | more
more /etc/profile ( ctrl + b 向上,ctrl + f 向下)
less /etc/profile( 适合看大型日志) ( pageup pagedown)
5. du -sh 查询当前目录大小
df -m 查询系统磁盘
6. window 根据端口杀掉进程
netstat -ano | findstr "8080"
taskkill /f /pid "15728"
7. linux 根据端口查询进程
netstat -anp | grep 3306
lsof -i:3306
2.linux 环境
1.修改服务器登录端口
1. vim /etc/ssh/sshd_config
2. Port 1122
3. systemctl restart sshd.service
2. linux常用操作
一: 赋予 用户 sudo 权限
1. vim /etc/sudoers
2. qlkj ALL= ( ALL) ALL
二: 配置服务器免密登录 A login B
1: ssh-keygen -- 在A机器上生成公钥
2: ssh-copy-id qlkj@45.40.234.216 -- 将A机器公钥复制到B机器
3: ssh qlkj@45.40.234.216 -- 登录
3.安装jdk
1. 上传 jdk tar 包
2. tar -zxvf jdk-8u251-linux-x64.tar.gz
3. 配置环境变量
vim /etc/profile
JAVA_HOME= /usr/local/java/jdk
CLASSPATH= $JAVA_HOME /lib/
PATH= $PATH : $JAVA_HOME /bin
export PATH JAVA_HOME CLASSPATH
4. source /etc/profile
4.安装 nginx
1. 安装 环境
yum -y install make gcc-c++ zlib zlib-devel pcre-devel libtool openssl openssl-devel
2. 安装 PCRE
cd /usr/local/src/
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 查看版本
3. 下载nginx
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix= /usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre= /usr/local/src/pcre-8.35
make
make install
/usr/local/webserver/nginx/sbin/nginx -v
4. nginx 命令
/usr/local/webserver/nginx/sbin/nginx -s reload
/usr/local/webserver/nginx/sbin/nginx -s reopen
/usr/local/webserver/nginx/sbin/nginx -s stop
5.安装Redis
1. wget http://download.redis.io/releases/redis-5.0.7.tar.gz
2. tar -zxvf redis-5.0.7.tar.gz
3. cd redis-5.0.7.tar.gz
4. make
5. cd src
6. ./redis-server .. /redis.conf
6.安装minio 图片服务器
1. 上传 minio
2. chmod +x minio
3. 创建目录
mkdir -p minio/data
mkdir -p minio/log
4. 设置账户,密码
export MINIO_ACCESS_KEY= qlkj
export MINIO_SECRET_KEY= 123456789
5. 后台启动
nohup /usr/local/minio server /home/minio/data > /home/minio/log/minio.log 2> & 1 &
7.安装node环境
1. mkdir -p /usr/local/node
2. cd /usr/local/node
wget https://nodejs.org/dist/v11.12.0/node-v11.12.0-linux-x64.tar.xz
8.安装RabbitMQ
1: 安装 erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum install erlang
erl
2: 安装 rabbitmq-server
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.5/rabbitmq-server-3.8.5-1.el7.noarch.rpm
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
rpm --import https://packagecloud.io/gpg.key
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum -y install epel-release
yum -y install socat
rpm -ivh rabbitmq-server-3.8.5-1.el7.noarch.rpm
rabbitmq-plugins enable rabbitmq_management
systemctl start rabbitmq-server
http:ip
rabbitmqctl add_user qlkj 123456
rabbitmqctl set_user_tags qlkj administrator
rabbitmqctl set_permissions -p / qlkj "." "." ".*"
systemctl restart rabbitmq-server
cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.5/
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
1: 安装 gcc等环境
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
yum -y install ncurses-devel
2: 安装 Erlang环境
wget http://erlang.org/download/otp_src_18.2.1.tar.gz
tar xvfz otp_src_18.2.1.tar.gz
cd otp_src_18.2.1
./configure
make install
3. 安装 rabbitMq
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-generic-unix-3.6.9.tar.xz 并解压
将ebin目录下rabbit.app中loopback_users里的<< "guest" >> 删除
4.配置环境
vim /etc/profile
export PATH= /usr/local/rabbitmq/sbin:$PATH
source /etc/profile
rabbitmq-plugins enable rabbitmq_management
rabbitmq-server -detached
安装plugin
1: 下载:wget https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip
2: 解压: unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip
3: 启用
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
3.docker 安装
1. 安装docker 环境
1:准备工作:(非必须)
sudo yum update
sudo yum remove docker docker-common docker-selinux docker-engine
2:安装:
//1.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
//2.设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
//3.可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
//4.安装docker
sudo yum install docker-ce //由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
sudo yum install docker-ce-17.12.0.ce
3.设置开机启动
sudo systemctl start docker
sudo systemctl enable docker
4.验证安装是否成功
docker version
//配置阿里云镜像加速器
1: vim /etc/docker/daemon.json
2:
{
"registry-mirrors" : [ "https://fzhmfyeu.mirror.aliyuncs.com" ]
}
-- 配置加速器二
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://2be16b3b.m.daocloud.io
3: systemctl daemon-reload
4: systemctl restart docker
-- 安装 docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-` uname -s` -` uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
2.docker 安装maven私服
1. 下载一个nexus3的镜像
docker pull sonatype/ nexus3
2. 将容器内部/ var/ nexus- data挂载到主机/ root/ nexus- data目录。
docker run - d - p 8081 : 8081 -- name nexus - v / root/ nexus- data: / var/ nexus- data -- restart= always sonatype/ nexus3
3. 关闭防火墙, 访问http: / / ip地址: 8081
4. 默认登陆账号 admin admin123
5. 测试连接:
docker inspect f421afba4103
curl 172.17 .0 .2 : 8081
6. 等待一分钟,登录管理页面,修改admin密码
3.docker搭建gitlab
1 : 下载镜像文件
docker pull beginor/ gitlab- ce: 11.0 .1 - ce. 0
2. 创建GitLab 的配置 ( etc) 、 日志 ( log) 、数据 ( data) 放到容器之外,便于日后升级因此请先准备这三个目录。
mkdir - p / mnt/ gitlab/ etc
mkdir - p / mnt/ gitlab/ log
mkdir - p / mnt/ gitlab/ data
3. 运行GitLab容器
docker run \
-- detach \
-- publish 8443 : 443 \
-- publish 9090 : 80 \
-- name gitlab \
-- restart unless- stopped \
- v / mnt/ gitlab/ etc: / etc/ gitlab \
- v / mnt/ gitlab/ log: / var/ log/ gitlab \
- v / mnt/ gitlab/ data: / var/ opt/ gitlab \
beginor/ gitlab- ce: 11.0 .1 - ce. 0
4.
1. 修改/ mnt/ gitlab/ etc/ gitlab. rb
vi / mnt/ gitlab/ etc/ gitlab. rb
修改:external_url 'http://192.168.212.227'
2. 修改/ mnt/ gitlab/ data/ gitlab- rails/ etc/ gitlab. yml
vi / mnt/ gitlab/ data/ gitlab- rails/ etc/ gitlab. yml
找到关键字 * ## Web server settings *
host: 本机地址
port: 8090
4.docker 安装Apollo
1. 下载aploll配置中心
https: / / github. com/ nobodyiam/ apollo- build- scripts
2. 上传apollo- build- scripts- master文件到服务器中
3. unzip apollo- build- scripts- master. zip 解压配置文件
如果没有unzip命令的话,安装zip插件 yum - y install zip unzip
4. 配置数据策略
修改demo. sh
vim demo. sh
5. 启动阿波罗 . /demo. sh start
6. 访问:http: / / 47.107 .39 .48 : 8070 账号:apollo 密码: admin
4.docker 运行mysql
1 : docker pull mysql: 5.7
2. 创建挂载文件
mkdir - p / home/ mysql/ conf. d / home/ mysql/ data
touch / home/ mysql/ my. cnf
vim / home/ mysql/ my. cnf
[ mysqld]
user= mysql
character- set- server= utf8
default_authentication_plugin= mysql_native_password
secure_file_priv= / var/ lib/ mysql
expire_logs_days= 7
sql_mode= STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION
max_connections= 1000
[ client]
default - character- set= utf8
[ mysql]
default - character- set= utf8
3 : docker run -- restart= always -- privileged= true - d mysql: 5.7
- v / home/ qlkj/ mysql/ data/ : / var/ lib/ mysql
- v / home/ qlkj/ mysql/ conf. d: / etc/ mysql/ conf. d
- v / home/ qlkj/ mysql/ my. cnf: / etc/ mysql/ my. cnf
- p 33060 : 3306 -- name mysql - e MYSQL_ROOT_PASSWORD= 123456
4 : docker exec - it mysql / bin/ bash
4 : 使用登录工具登录docker
修改root 可以通过任何客户端连接
ALTER USER 'root' @'%' IDENTIFIED WITH mysql_native_password BY '123456' ;
5.docker 运行redis
1 : docker pull redis: 3.2
2 : docker run - p 6379 : 6379 - d redis: 3.2 -- appendonly yes
3 : docker exec - it 容器编号 redis- cli
6.docker 运行Nginx
1 : 下载
docker pull nginx
2 : 运行
docker run - p 80 : 80 -- name nginx \
- v / mydata/ nginx/ html: / usr/ share/ nginx/ html \
- v / mydata/ nginx/ logs: / var/ log/ nginx \
- v / mydata/ nginx/ conf: / etc/ nginx \
- d nginx
3 : docker exec - it nginx redis- cli
7.docker ElasticSearch
一:安装ES
1. 下载镜像(版本对应)
docker pull elasticsearch: 7.4 .2
docker pull kibana: 7.4 .2
2. 创建挂载目录文件
mkdir - p / mydata/ elasticsearch/ config
mkdir - p / mydata/ elasticsearch/ data
echo "http.host:0.0.0.0" >> / mydata/ elasticsearch/ config/ elasticsearch. yml
3. 运行容器
docker run - it -- name es - p 9200 : 9200 - p 9300 : 9300 - e "discovery.type=single-node" - e ES_JAVA_OPTS= "-Xms64m -Xmx128m" \
- v / mydata/ elasticsearch/ config/ elasticsearch. yml: / usr/ share/ elasticsearch/ config/ elasticsearch. yml \
- v / mydata/ elasticsearch/ data: / usr/ share/ elasticsearch/ data \
- v / mydata/ elasticsearch/ plugins: / usr/ share/ elasticsearch/ plugins \
- d elasticsearch: 7.4 .2
3. http: / / 45.40 .234 .216 : 9200 /
二:安装Kibana
1.d ocker run -- name kibana - e ELASTICSEARCH_HOSTS= http: / / 45.40 .234 .216 : 9200 - p 5601 : 5601 - d kibana: 7.4 .2
2. http
三:安装logstash : 实现数据库与ES同步
1. 上传logstash- 6.4 .3 . tar. gz到服务中
2. tar –zxvf logstash- 6.4 .3 . tar. gz
3. cd logstash- 6.4 .3
4. bin/ logstash- plugin install logstash- input- jdbc
5. bin/ logstash- plugin install logstash- output- elasticsearch
8docker 运行kafka
1.d ocker pull wurstmeister/ kafka
2.d ocker pull wurstmeister/ zookeeper ( 安装docker需要安装Zookeeper)
3. 运行Zookeeper
docker run - d -- name zookeeper - p 2181 : 2181 - t wurstmeister/ zookeeper
4. 运行Kafka环境
docker run -- name kafka01 \
- p 9092 : 9092 \
- e KAFKA_BROKER_ID= 0 \
- e KAFKA_ZOOKEEPER_CONNECT= 192.168 .212 .252 : 2181 \
- e KAFKA_ADVERTISED_LISTENERS= PLAINTEXT: / / 192.168 .212 .252 : 9092 \
- e KAFKA_LISTENERS= PLAINTEXT: / / 0.0 .0 .0 : 9092 \
- d wurstmeister/ kafka
9.docker 安装 rabbit MQ
1: docker pull rabbitmq:management
2: docker run --name rabbitmq -d -p 15672:15672 -p 5672:5672 rabbitmq:management
3: ip:15672
docker cp rabbitmq_delayed_message_exchange-3.8.0.ez rabbitmq:/plugins
10 docker 安装禅道
1 : docker pull idoop/ zentao
2 : mkdir - p / data/ zbox && docker run - d - p 80 : 80 - p 3306 : 3306 \
- e USER= "root" - e PASSWD= "password" \
- e BIND_ADDRESS= "false" \
- e SMTP_HOST= "163.177.90.125 smtp.exmail.qq.com" \
- v / data/ zbox/ : / opt/ zbox/ \
-- name zentao- server \
idoop/ zentao: latest
3 : http: / / 139.159 .186 .234 /
11.docker 本地镜像推送到阿里云
1 : docker commit - a hjk - m "new container" 容器编号 myContainer: 1
$ sudo docker login -- username= hjunkai709 registry. cn- shenzhen. aliyuncs. com
$ sudo docker tag [ ImageId] registry. cn- shenzhen. aliyuncs. com/ huagnjunkai/ mycentos: [ 镜像版本号]
$ sudo docker push registry. cn- shenzhen. aliyuncs. com/ huagnjunkai/ mycentos: [ 镜像版本号]