- [Email protected]
- 2015-1-14 22:00:23
Ubuntu operation and maintenance skills update too fast, every six months a release, it will be updated every six months. All this knowledge is forgotten before the ubuntu14.04lts.
1. Rough fix Ubuntu under dpkg error
sudo rm-rf/var/lib/apt/*sudo apt-get updatesudo apt-get-f Install
2. Fine-tune the parameters between the jitter and the delay of the contract
net.ipv4.tcp_max_syn_backlog=4096 #1024 增加TCP SYN队列长度,使系统可以处理更多的并发连接net.core.wmem_default = 2097152 #108544,系统套接字缓冲区net.core.rmem_default = 2097152 #108544,系统套接字缓冲区net.core.rmem_max=16777216 #131071,系统套接字缓冲区net.core.wmem_max=16777216 #131071,系统套接字缓冲区net.ipv4.tcp_rmem=4096 87380 16777216 #4096 87380 174760, TCP接收缓冲区net.ipv4.tcp_wmem=4096 65536 16777216 #4096 16384 131072, TCP发送缓冲区net.ipv4.tcp_mem = 786432 1048576 1572864 # Out of socket memorynet.ipv4.tcp_syncookies=1 #0,防SyncFlood攻击net.ipv4.ip_local_port_range = 32768 61000 #用于向外连接的端口范围,这是默认值net.ipv4.tcp_max_tw_buckets = 5000 #180000,同时保持TIME_WAIT套接字的最大数量
3. Ubuntu automatically find the fastest source
Add the following 4 lines to the top of the source.list:
deb mirror://mirrors.ubuntu.com/mirrors.txt precise main restricted universe multiversedeb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main restricted universe multiversedeb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiversedeb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse
4. Ubuntu installs the latest Redis
sudo apt-get -y install python-software-propertiessudo add-apt-repository -y ppa:rwky/redissudo apt-get -y updatesudo apt-get -y install redis-server
5. Ubuntu Install latest mongodb5.1 installation
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen‘ | sudo tee /etc/apt/sources.list.d/mongodb.listsudo apt-get updatesudo apt-get install mongodb-org
5.2 Phpdriver
http://php.net/manual/en/mongo.installation.phphttps://github.com/joevallender/slim-php-mongo-restsudo apt-get install php-pearsudo pecl install mongoextension=mongo.sosudo service apache2 restart
6. Ubuntu Install latest Nodejs
sudo apt-get install python-software-propertiessudo add-apt-repository ppa:chris-lea/node.jssudo apt-get updatesudo apt-get install python g++ make nodejs
7. Ubuntu Installs Samba
apt-get install sambasmbpasswd -a uvim /etc/samba/smb.conf;homes; writable = yesservice smbd restart
8. SSH/SCP Cancel every inquiry yes/no
/etc/ssh/ssh_config 中的#
9. Ubuntu Routing Table Configuration 9.1 Add route matching entries
sudo route add -net 目标IP netmask 255.255.255.0 gw 网关IP# 注意目标IP的掩码要和netmask保持一致
9.2 Viewing the routing table
sudo route -n
UDP Packet Loss Detection Tool
sudo apt-get install 2ping2ping --listen --stats=5 -q # udp server2ping -i 0.02 -s 80 -q # udp client
One. TC Call Netem DO network simulation
Http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
tc qdisc del dev eth1 root
11.1 principle
Netem is a network emulation function module provided by Linux 2.6 and above kernel versions. The function module can be used to simulate complex Internet transmission performance in a well-performing LAN, such as low bandwidth, transmission delay, packet loss, etc.
TC is a tool in the Linux system with the full name traffic control. TC can be used to control the operating mode of Netem
11.2 Send delay
tc qdisc add dev eth0 root netem delay 100ms # 延迟100毫秒tc qdisc add dev eth0 root netem delay 100ms 20ms # 延迟 100ms ± 10mstc qdisc add dev eth0 root netem delay 100ms loss 20% # 30% 的包在100ms±10ms 70%保持100ms
11.3 Send Packet drops
tc qdisc add dev eth0 root netem loss 20% # 随机丢包20%tc qdisc add dev eth0 root netem loss 20% 40% # 随机丢包20% 成功率为40%
11.4 Sending duplicates
tc qdisc add dev eth0 root netem duplicate 1%
11.5 Send Damage
tc qdisc add dev eth0 root netem corrupt 0.2%
11.6 Sending a disorderly order
11.7 Specifying the destination address
tc qdisc add dev eth1 root handle 1: priotc qdisc add dev eth1 parent 1:1 handle 2: netem delay 500mstc filter add dev eth1 parent 1:0 protocol ip pref 55 handle ::55 u32 match ip dst 192.168.1.140 flowid 2:1
MySQL common operation and maintenance 12.1 Add users
CREATE USER ‘test‘@‘localhost‘ IDENTIFIED BY ‘test_password‘;GRANT ALL PRIVILEGES ON *.* TO ‘test‘@‘localhost‘;
12.2 Changing user passwords
SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD("root_password");
12.3 Creating a new MySQL instance
#!/bin/bash# script created by @everwannaport =$2name= "mysql-$1" data= "/var/lib/$name" log= "/var/log/mysql/$name" Config= "/etc/mysql/$name. Cnf" Pidname= "Mysqld-$1.pid" pid= "/var/run/mysqld/mysqld-$1.pid" Sockname= "mysqld-$1. Sock "sock="/var/run/mysqld/mysqld-$1.sock "runpid="/run/mysqld/mysqld-$1.pid "runsock="/run/mysqld/mysqld-$1. Sock "# Datasudo mkdir $datasudo chown-r mysql $data # logsudo mkdir $logsudo chown-r mysql $log # configsudo Cp/etc/mysql /MY.CNF $configsudo sed-i "s/= 3306/= $port/g" $configsudo sed-i "s/mysqld.sock/$sockname/g" $configsudo sed-i "S/mysql D.pid/$pidname/g "$configsudo sed-i" s/\/var\/lib\/mysql/\/var\/lib\/$name/g "$configsudo sed-i" S/\/var\/log\/mysql /\/var\/log\/mysql\/$name/g "$config # Apparmorecho" | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldecho "$data/R," | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldecho "$data/** rwk," | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldecho "$pid rw," | sudo tee-a/etc/apparmor.d/local/usr.sbiN.mysqldecho "$sock W," | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldecho "$runpid rw," | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldecho "$runsock W," | sudo tee-a/etc/apparmor.d/local/usr.sbin.mysqldsudo service apparmor reloadsudo mysql_install_db--user=mysql-- BASEDIR=/USR--datadir= $data--defaults-file= $configsudo-B mysqld_safe--defaults-file= $config--user=mysqlecho " ADD the following line into/etc/rc.local "echo" Sudo-b mysqld_safe--defaults-file= $config--user=mysql "
12.4 Login non-default instance
mysql -h127.0.0.1 -uroot -P4316 -ppassword
12.5 phpMyAdmin supports multiple DB instances
Modify /var/lib/phpmyadmin/config.inc.php
:
$index = INDEX; // 下拉框的下标$cfg[‘Servers‘][$index][‘verbose‘] = ‘default‘;$cfg[‘Servers‘][$index][‘host‘] = ‘127.0.0.1‘;$cfg[‘Servers‘][$index][‘port‘] = 3306;$cfg[‘Servers‘][$index][‘socket‘] = ‘/var/run/mysqld/mysqld.sock‘;$cfg[‘Servers‘][$index][‘connect_type‘] = ‘socket‘;$cfg[‘Servers‘][$index][‘extension‘] = ‘mysqli‘;$cfg[‘Servers‘][$index][‘auth_type‘] = ‘cookie‘;$cfg[‘Servers‘][$index][‘user‘] = ‘root‘;$cfg[‘Servers‘][$index][‘password‘] = ‘‘;
12.6 Configuring Master-Slave synchronization
@master:
sudo suvim /etc/mysql/my.cnfserver-id = 1log-bin = mysql-binbinlog_format = mixedexpire_logs_days = 10 max_binlog_size = 100Mbinlog-do-db = [dbname-you-wanna-sync]service mysql restartmysql -uroot -pagorabestvoip -h127.0.0.1 -P3306GRANT REPLICATION SLAVE ON *.* TO ‘[remote username]‘@‘[master ip]‘ IDENTIFIED BY ‘[passwd]‘;show master status\G
@slave:
sudo suservice mysql stopvim /etc/mysql/my.cnfserver-id = [slave server id]binlog-do-db = [dbname-you-wanna-sync]service mysql restartmysql -uroot -pagorabestvoip -h127.0.0.1 -P3306slave stop;change master to master_host=‘[master ip]‘,master_port=[port],master_user=‘[remote username]‘, master_password=‘[passwd]‘,master_log_file=‘mysql-bin.000004‘,master_log_pos=107; start slave; show slave status\G;
PHP allows uploading large files
sudo vim /etc/php5/apache2/php.iniupload_max_filesize = 50Mpost_max_size = 50Msudo vim /etc/apache2/envvars
Bash Common commands
Get file Last modified timestamp
stat -c %Y vs.exe
Get local IP
ifconfig | awk -F: ‘/inet addr/&& !($2 ~ /127\.0\.0\.1/){gsub(/ .*/, "", $2); print $2}‘
List the 10 highest frequency commands
history | awk ‘{a[$2]++}END{for(i in a){print a[i] " " i}}‘ | sort -rn | head
Process Start accurate time
for pid in $(pgrep exe); do echo -n "${pid} " ; ps -p ${pid} -o lstart | grep -v "START" ; done
Ubuntu x64 Install 32-bit runtime
sudo apt-get install ia32-libs
Ubuntu Kernel Auto-update causes the/boot partition to become larger
Http://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot
uname -r # 查看正在使用的内核dpkg -l linux-image-\* | grep ^ii # 列出所有内核sudo apt-get -y purge # 删除内核:后边指定内核版本
One-click Delete without kernel:
dpkg -l linux-{image,headers}-"[0-9]*" | awk ‘/^ii/{ print $2}‘ | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e ‘[0-9]‘ | xargs sudo apt-get -y purge
. C + + shortcut 17.1 copy vector to StringStream
std::copy(sentence.begin(), sentence.end(), std::ostream_iterator<std::string>(ss,"\n"));
17.2 transform Map.key to Vector
std::vector<uint32_t> vec;std::transform(users.begin(), users.end(), std::back_inserter(vec), [&]( const std::map<uint32_t, user_info_ptr>::value_type& x) { return x.first;});
17.3 Ifstream to String
ifstream ifs("file.txt");stringstream ss;ss << ifs.rdbuf();
17.4 Automatic identification of lambda parameter types
#define _A(container) decltype(*std::begin(container))std::for_each(ints.begin(), ints.end(), [](_A(ints)& val){ val = 7; });
Ubuntu configuration Coredump is permanently active
vim /etc/security/limits.conf* hard core unlimited* soft core unlimited* soft nofile 65500* hard nofile 65500sudo sed "s/enabled=1/enabled=0/" -i /etc/default/apportgrep enabled /etc/default/apportsudo echo "kernel.core_pattern=/tmp/core-%e-%t-%p-%u" | sudo tee /etc/sysctl.d/core-pattern.confsudo service procps start
Ubuntu Automatic Clock synchronization
sudo apt-get install ntpd
Ubuntu Configuring DNS
echo ‘nameserver 8.8.8.8‘ | sudo tee /etc/resolvconf/resolv.conf.d/basesudo service resolvconf restartcat /etc/resolv.conf
Ubuntu Disable Password Login
sed "s/$password_enabled/PasswordAuthentication no/" /etc/ssh/sshd_config > sshd_configsudo mv -v sshd_config /etc/ssh/sshd_configsudo service ssh reload
Ubuntu using rsyslog22.1 Installation
sudo apt-get install -y rsyslog
22.2 minute file
$template FormatWithPRI,"%$NOW% %TIMESTAMP:8:15% %syslogseverity-text% %syslogtag%%msg:::drop-last-lf%\n"if $programname == ‘demo.exe‘ then /var/log/demo.log;FormatWithPRIif $programname == ‘demo.exe‘ then ~
22.3 Filtering by Level
if $syslogseverity == ‘7‘ then ~
22.4 Log Rotate
/var/log/demo.log{ rotate 100 copytruncate dateext minsize 1M daily missingok notifempty delaycompress compress postrotate reload rsyslog >/dev/null 2>&1 || true endscript}
ubuntu12.04 Operation and Maintenance memo