系统优化
修改 /etc/grub.conf
关闭 numa=off ,修改磁盘IO调度方式 elevator=deadline
修改方法:
grubby --update-kernel=ALL --args="transparent_hugepage=never" --args="elevator=deadline"
验证:
grubby --info=ALL
返回
args="ro crashkernel=auto rhgb quiet numa=off elevator=deadline"
grubby --update-kernel=ALL --args="transparent_hugepage=never" --args="elevator=deadline"
验证:
grubby --info=ALL
返回
args="ro crashkernel=auto rhgb quiet numa=off elevator=deadline"
关闭内存大页 hugepage
验证是否开启方法1:
如果以下文件不存在,则是THP已经从内核中移除。
/sys/kernel/mm/transparent_hugepage or /sys/kernel/mm/redhat_transparent_hugepage
验证是否开启方法2:
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[always] == 》表示开启
验证是否开启方法1:
如果以下文件不存在,则是THP已经从内核中移除。
/sys/kernel/mm/transparent_hugepage or /sys/kernel/mm/redhat_transparent_hugepage
验证是否开启方法2:
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[always] == 》表示开启
禁用内存大页
方法:
修改 /etc/rc.local
# vi /etc/rc.local #追加,禁用大页
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
# vi /etc/rc.local #追加,禁用大页
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
内核优化
vi /etc/sysctl.conf
vi /etc/sysctl.conf
添加内容如下:
vm.swappiness = 0
kernel.shmmax=135497418752
net.core.rmem_max = 4194304
net.core.wmem_max = 4194304
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.ipv4.ip_local_port_range = 9000 65535
kernel.sem = 50100 64128000 50100 1280
vm.dirty_background_bytes = 102400000
vm.dirty_ratio = 80
vm.nr_hugepages = 102352
/etc/security/limits.conf
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360
* soft stack unlimited
* hard stack unlimited
* soft memlock 250000000
* hard memlock 250000000
vm.swappiness = 0
kernel.shmmax=135497418752
net.core.rmem_max = 4194304
net.core.wmem_max = 4194304
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.ipv4.ip_local_port_range = 9000 65535
kernel.sem = 50100 64128000 50100 1280
vm.dirty_background_bytes = 102400000
vm.dirty_ratio = 80
vm.nr_hugepages = 102352
/etc/security/limits.conf
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360
* soft stack unlimited
* hard stack unlimited
* soft memlock 250000000
* hard memlock 250000000
块设备预读
blockdev --setra 16384 /dev/sda
设置开机启动生效:
echo "blockdev --setra 16384 /dev/sda" >> /etc/rc.local
blockdev --setra 16384 /dev/sda
设置开机启动生效:
echo "blockdev --setra 16384 /dev/sda" >> /etc/rc.local
应用层
show max_connections;
show shared_buffers;
show wal_buffers;
show checkpoint_completion_target;
show checkpoint_timeout;
show fsync;
show commit_delay;
show autovacuum_work_mem;
show commit_siblings;
show effective_cache_size;
show maintenance_work_mem;
show work_mem;
1.用超级用户运行
postgres=#
SELECT pg_reload_conf();
2.用UNIX的kill手动发起HUP信号
$kill -HUP PID
3.使用pg_ctl命令触发SIGHUP信号
$pg_ctl reload
show max_connections;
show shared_buffers;
show wal_buffers;
show checkpoint_completion_target;
show checkpoint_timeout;
show fsync;
show commit_delay;
show autovacuum_work_mem;
show commit_siblings;
show effective_cache_size;
show maintenance_work_mem;
show work_mem;
1.用超级用户运行
postgres=#
SELECT pg_reload_conf();
2.用UNIX的kill手动发起HUP信号
$kill -HUP PID
3.使用pg_ctl命令触发SIGHUP信号
$pg_ctl reload