Category Archives: Linux

CentOS7.3.1611でポートを解放する

ポートを解放
firewall-cmd –zone=public –add-port=80/tcp –permanent
firewall-cmd –add-port=22/tcp –zone=public –permanent

ファイアウォールを再起動
systemctl restart firewalld

利用しているポートを確認
lsof -i tcp:80

ポートの一覧を表示
netstat -ntlp

CentOS7.4でIPコマンドをメモする

1.環境の確認
# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

2.IPコマンド

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 9c:a3:ba:01:e1:a5 brd ff:ff:ff:ff:ff:ff
inet xxx.xxx.xxx.55/23 brd xxx.xxx.xxx.255 scope global eth0
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 9c:a3:ba:03:68:45 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 9c:a3:ba:04:ee:e5 brd ff:ff:ff:ff:ff:ff

 

3.特定デバイスの状態確認
ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet xxx.xxx.xxx.55 netmask 255.255.254.0 broadcast xxx.xxx.xxx.255
ether 9c:a3:ba:01:e1:a5 txqueuelen 1000 (Ethernet)
RX packets 14156471 bytes 920928982 (878.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3618059 bytes 4088711994 (3.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.デバイスごとのパケット処理数
# netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 14159495 0 0 0 3618824 0 0 0 BMRU
eth1 1500 0 0 0 0 0 0 0 0 BMRU
eth2 1500 0 0 0 0 0 0 0 0 BMRU
lo 65536 1583651 0 0 0 1583651 0 0 0 LRU

CentOS7にlshwでディスクの型番を取得する

# yum install lshw
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* remi-safe: mirror.bebout.net
Resolving Dependencies
–> Running transaction check
—> Package lshw.x86_64 0:B.02.17-12.el7 will be installed
–> Processing Dependency: hwdata for package: lshw-B.02.17-12.el7.x86_64
–> Running transaction check
—> Package hwdata.x86_64 0:0.252-8.4.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
lshw x86_64 B.02.17-12.el7 base 286 k
Installing for dependencies:
hwdata x86_64 0.252-8.4.el7 base 2.1 M

Transaction Summary
================================================================================
Install 1 Package (+1 Dependent package)

Total download size: 2.4 M
Installed size: 13 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): lshw-B.02.17-12.el7.x86_64.rpm | 286 kB 00:00
(2/2): hwdata-0.252-8.4.el7.x86_64.rpm | 2.1 MB 00:00
——————————————————————————–
Total 5.3 MB/s | 2.4 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : hwdata-0.252-8.4.el7.x86_64 1/2
Installing : lshw-B.02.17-12.el7.x86_64 2/2
Verifying : lshw-B.02.17-12.el7.x86_64 1/2
Verifying : hwdata-0.252-8.4.el7.x86_64 2/2

Installed:
lshw.x86_64 0:B.02.17-12.el7

Dependency Installed:
hwdata.x86_64 0:0.252-8.4.el7

Complete!

# sudo lshw -c disk
*-cdrom
description: SCSI CD-ROM
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/cdrom
logical name: /dev/sr0
capabilities: audio
configuration: status=nodisc
*-virtio3
description: Virtual I/O device
physical id: 0
bus info: virtio@3
logical name: /dev/vda
size: 200GiB (214GB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: driver=virtio_blk guid=24e50a8f-eb81-4573-9f30-1084d97ebbc2 logicalsectorsize=512 sectorsize=512

「Linux」ワイルドカード(* ?)を利用するメモ

サンプルコード1(*)
$ ls
test.txt test1 test2 test3 index.php error.log
$ rm test*
$ ls
index.php error.log

 

サンプルコード2(?)
$ ls
test01 test02 test03 test04 test11 test12 test13 test14
$ rm test?4
$ ls
test01 test02 test03 test11 test12 test13

DebianにMySQLで外部ホストから接続できるメモ

1.3306ポートを開放
vim /etc/iptables.conf
追記
-A INPUT -p tcp –dport 3306 -j ACCEPT
再起動
iptables-restore < /etc/iptables.conf

 

2.mysqlのIPアドレスを修正
vim /etc/mysql/my.cnf
修正前
bind-address = 127.0.0.1
修正後
bind-address = 0.0.0.0

3.root権限を修正
use mysql;
update user set password=PASSWORD(‘new password’) where user=’root’;
FLUSH PRIVILEGES;

権限設定
GRANT ALL ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘newpassword’;
exit;

4.再起動
/etc/init.d/mysql restart

CentOS7にyumでgitをインストールするメモ

1.gitインストールかどうかをチェック
#git –version

2.yumでgitをインストール
#yum install git

 

3.バージョン確認
#yum –version

 

4.gitをアンインストール
#yum remove git

Linuxにhtopをインストールするメモ

# tar zxvf htop-1.0.2.tar.gz
# cd htop-1.0.2
# ./configure
# make && make install

エラーメッセージ
configure: error: You may want to use –disable-unicode or install libncursesw.
解決方法
# yum install ncurses-devel

CentOS7.2に自動アップデートを有効、無効に設定する方法

# vi /etc/yum
# yum install yum-cron -y

# ls
fssnap.d  pluginconf.d  protected.d  vars  version-groups.conf  yum-cron.conf  yum-cron-hourly.conf
# vi yum-cron.conf

 

自動アップデートを有効になる
# systemctl start crond

# yum -y install cronie

# yum -y install yum-cron

# systemctl start yum-cron

 

自動アップデートを無効になる

# gedit /etc/yum/yum-cron.conf

update_messages = no

download_updates = no

「shell」ディスクの使用状況を調べるコード

サンプルコード
#!/bin/bash
IP=`ifconfig eth0|sed -n ‘2p’|awk ‘{print $2}’|cut -c 6-`
SPACE=`df |sed -n ‘/\/$/p’|awk ‘{print $4}’|sed ‘s/%//’`
if [ $SPACE -ge 90 ];then
echo “The /  disk is full”
fi

redisサーバ自動起動スクリプトのサンプルコード

サンプルコード:
#!/bin/bash
#
# redis – this script starts and stops the redis-server daemon
#
# chkconfig:   – 80 12
# description:  Redis is a persistent key-value database
# processname: redis-server
# config:      /etc/6379.conf
# pidfile:     /redis/redis6379.pid
PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379
EX_EC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/redis/redis6379.pid
CONF=”/etc/6379.conf”

case “$1” in
start)
if [ -f $PIDFILE ]
then
echo “$PIDFILE exists, process is already running or crashed”
else
echo “Starting Redis server…”
$EX_EC $CONF
fi
if [ “$?”=”0” ]
then
echo “Redis is running…”
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo “$PIDFILE does not exist, process is not running”
else
PID=$(cat $PIDFILE)
echo “Stopping …”
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo “Waiting for Redis to shutdown …”
sleep 1
done
echo “Redis stopped”
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo “Usage: /etc/init.d/redis {start|stop|restart|force-reload}” >&2
exit 1
esac

 

#chmod 0777 /etc/init.d/redis
#chkconfig redis on

# vi /etc/rc.d/rc.local

追記
service redis start