欢迎光临
我们一直在努力

运维常用命令分享

运维常用命令

jar 开机自启

编辑开机自启脚本: vi /etc/systemd/system/drug-prod.service
——————————————————文件开始

[Unit]
Description=veterinarydrug
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/java/jdk1.8.0_191/bin/java -jar /deploy/drug-prod/veterinarydrug.jar –spring.profiles.active=prod –server.port=8089
#前面是java命令的绝对路径 后面是jar包的绝对路径
ExecStop=/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target

——————————————————–文件结束

服务重载,开机自启,启动关闭状态查看:

systemctl daemon-reload
systemctl stop drug-prod
systemctl -l status drug-prod
systemctl start drug-prod
开机自启:systemctl enable drug-prod
关闭开机自启:systemctl disable drug-prod

redis 安装与自启

下载(需要可以连接外网):wget http://download.redis.io/releases/redis-5.0.1.tar.gz
解压: tar -zxvf redis-5.0.1.tar.gz

cd redis-5.0.1
make MALLOC=libc 
cd src && make install
#验证安装: ./redis-server
#使用kill命令杀死进程: ps -aux | grep redis
#修改daemonize为yes,即默认以后台程序方式运行

修改配置文件:vi /deploy/redis/redis-5.0.1/redis.conf

——————————————————修改开始
daemonize yes requirepass foobared 注释掉bind 127.0.0.1 protected-mode no logfile "/var/log/redis/log.log"
——————————————————修改结束

./redis-cli -h 192.168.0.181 -p 6379 -a foobared
./redis-cli -p 6379 shutdown
#软链接redis-cli: ln -s /deploy/redis/redis-5.0.1/src/redis-cli /usr/bin/redis
#做完软链接后,直接使用redis命令调用客户端: redis -h 192.168.0.39 -p 6379 -a foobared

#编辑自启服务(不采用): vi /etc/systemd/system/redis-server.service
#存在问题:signal-handler (1543572685) Received SIGTERM scheduling shutdown.
#在Redis启动的时候会立马收到一个SIGTERM信号结束进程,使redis关闭。因此不采用此方法。

——————————————————–文件开始

[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/deploy/redis/redis-5.0.1/src/redis-server /deploy/redis/redis-5.0.1/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

——————————————————–文件结束
服务操作:

systemctl daemon-reload
systemctl stop redisd
systemctl start redisd
systemctl -l status redisd
systemctl enable redisd
systemctl disable redisd

配置redis自启(推荐):
mkdir /etc/redis
生产环境使用的配置文件: /deploy/redis/redis-5.0.1/redis.conf

赋值启动脚本: cp /deploy/redis/redis-5.0.1/utils/redis_init_script /etc/init.d/redisd
设置为开机自启动:
此处直接配置开启自启动 chkconfig redisd on 将报错误: service redisd does not support chkconfig
应该编辑文件: vi /etc/init.d/redisd

———————————————-编辑开始

#!/bin/sh
#chkconfig: 2345 90 10
#description: Redis is a persistent key-value database
#
CONF="/deploy/redis/redis-5.0.1/redis.conf"

———————————————-编辑结束

设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop
netstat -unltp|grep 6379

nginx 安装与自启

环境安装: yum -y install gcc gcc-c++ autoconf automake gd gd-devel zlib zlib-devel openssl openssl-devel pcre-devel
下载nginx:wget http://nginx.org/download/nginx-1.15.6.tar.gz
解压并进入解压路径: tar -zxvf nginx-1.15.6.tar.gz
cd nginx-1.15.6/
配置,添加模块: ./configure –with-http_stub_status_module
make
make install
默认安装位置为: /usr/local/nginx
默认日志位置为: /usr/local/nginx/logs
编辑开机自启文件: vi /lib/systemd/system/nginx.service
验证模块是否安装:/usr/local/nginx/sbin/nginx -V
配置完成后检查配置文件: /usr/local/nginx/sbin/nginx -t
——————————————————–编辑开始

[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

——————————————————–编辑结束

systemctl stop nginx
systemctl start nginx
systemctl -l status nginx
systemctl enable nginx
systemctl disable nginx
systemctl restart nginx

–with-http_stub_status_module 模块配置:

vi /usr/local/nginx/conf/nginx.conf //编辑配置文件,如下:
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

curl 127.0.0.1/nginx_status //访问下,如果结果是:
Active connections: 2 server accepts handled requests 7 7 249 Reading: 0 Writing: 1 Waiting: 1
就说明安装成功了。

入口nginx配置示例:vi /usr/local/nginx/conf/nginx.conf
——————————————————–配置文件开始

worker_processes 1;

events {
worker_connections 1024;
}

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

sendfile on;
keepalive_timeout 65;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\\.";

server{
listen 8087;
server_name 192.168.0.206;
location / {
proxy_pass http://124.126.15.169:88;
#proxy_http_version 1.1;
#proxy_set_header Connection "";
}
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream bootshiro {
server 192.168.0.181:8089;
server 192.168.0.180:8089;
}

server {
listen 8088;
server_name 125.124.17.75;
#charset koi8-r;

#access_log logs/host.access.log main;

location /zyl/ {
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_pass http://bootshiro/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

}
location /ws/ {
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_pass http://bootshiro/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location / {
rewrite ^/VDU/$ /VDU/login.html permanent;
proxy_pass http://192.168.0.181:8088/;

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
if ($request_filename ~ .*\\.(htm|html)$)
{
add_header Cache-Control no-cache;
}
}
}
}

——————————————————–配置文件结束

——————————————————– web服务配置文件开始

worker_processes 1;

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\\.";

server {
listen 8088;
server_name 192.168.0.181;

location /VDU/ {
rewrite ^/VDU$ /VDU/login.html permanent;
index login.html;
root /deploy;
access_log on;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
}

——————————————————–web服务配置文件结束

fastdfs 安装与自启

下载环境: wget https://github.com/happyfish100/libfastcommon/archive/V1.0.36.tar.gz
解压、编译、安装:

tar -zxvf V1.0.36.tar.gz
cd libfastcommon-1.0.36
./make.sh
./make.sh install

下载fastdfs: wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
解压、编译、安装:

tar -zxvf V5.11.tar.gz
cd fastdfs-5.11/
./make.sh
./make.sh install

配置FastDFS跟踪器(Tracker):
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
修改配置文件: vim tracker.conf
——————————————————–修改开始

base_path=/usr/local/fastdfs/tracker
http.server_port=8080

——————————————————–修改结束

systemctl start fdfs_trackerd
systemctl stop fdfs_trackerd
systemctl -l status fdfs_trackerd
systemctl enable fdfs_trackerd
netstat -unltp|grep fdfs

出现问题:fdfs_trackerd:linux Permission denied
没有执行权限的原因:chmod 777 /usr/bin/fdfs_trackerd

/deploy/fastdfs/fastdfs-5.11/init.d/fdfs_trackerd start

配置FastDFS存储(Storage):
cd /etc/fdfs
cp storage.conf.sample storage.conf
修改配置文件: vim storage.conf
——————————————————–修改开始

#Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
base_path=/usr/local/fastdfs/storage
#逐一配置 store_path_count 个路径,索引号基于 0。
#如果不配置 store_path0,那它就和 base_path 对应的路径一样。
store_path0=/opt/fastdfs/file
#tracker_server 的列表 ,会主动连接 tracker_server
#有多个 tracker server 时,每个 tracker server 写一行
tracker_server=192.168.0.181:22122
#访问端口
http.server_port=8888

——————————————————–修改结束

systemctl start fdfs_storaged
systemctl stop fdfs_storaged
systemctl -l status fdfs_storaged
netstat -unltp|grep fdfs
systemctl daemon-reload
#验证配置是否成功: /usr/bin/fdfs_monitor /etc/fdfs/storage.conf

mysql 安装与自启

CentOS7下安装MySQL5.7安装与配置(YUM):
https://www.cnblogs.com/lgqboke/p/6873734.html
下载mysql源安装包: wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源:yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功:yum repolist enabled | grep "mysql.*-community.*"
安装MySQL:yum install mysql-community-server
show variables like 'log_%';

systemctl enable mysqld
systemctl daemon-reload
systemctl start mysqld

修改root默认密码:
grep 'temporary password' /var/log/mysqld.log (mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码)
set password for 'root'@'localhost'=password('密码');

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/ /var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
mysql -h 192.168.0.160 -u root -P 3306 -p

修改数据库配置:vi /etc/my.cnf
———————————————开始

lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

———————————————结束

备份:
vi dbback.sh

#!/bin/sh
mysqldump –defaults-file=/deploy/my.cnf veterinarydrug | gzip > /deploy/backup_db/veterinarydrug_$(date +%Y%m%d_%H%M%S).sql.gz
find /deploy/backup_db -mtime +30 -name "*.sql.gz" -exec rm -rf {} \\;

vi /deploy/my.cnf解决 End-User Guidelines for Password Security 问题

[client]
port=3306
host=192.168.0.160
user=root
password=密码

chmod 600 my.cnf

crontab -e 添加执行项目
查看crontab服务状态:systemctl status crond
查看crontab 日志 vi /var/log/cron

crontab -l : 0 1 * * 1,4 /deploy/dbback.sh

systemctl restart crond

硬盘挂载

查看/dev/sda1这个设备的uuid和label name :
dumpe2fs -h /dev/sda1
或 blkid

查看磁盘,看到未分区:fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a18d3

Device Boot Start End Blocks Id System
/dev/vda1 2048 8194047 4096000 82 Linux swap / Solaris
/dev/vda2 * 8194048 83886079 37846016 83 Linux

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

分区:fdisk /dev/vdb
n
p
1
enter
enter
w

fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a18d3

Device Boot Start End Blocks Id System
/dev/vda1 2048 8194047 4096000 82 Linux swap / Solaris
/dev/vda2 * 8194048 83886079 37846016 83 Linux

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x764d7f8a

Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 83 Linux

格式化分区:mkfs.ext4 /dev/vdb1

mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428544 blocks
2621427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2199912448
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

赞(0)
未经允许不得转载:171主机测评 » 运维常用命令分享
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址